Skip to content

Notebook 4 Exercise with f_v #8

Closed
mes15111 opened this issue Mar 24, 2020 · 2 comments
Closed

Notebook 4 Exercise with f_v #8

mes15111 opened this issue Mar 24, 2020 · 2 comments

Comments

@mes15111
Copy link

Exercise:
Enter your best guess for v0. What is the error between the measured yT and your predicted y(T)? Hint: use our function, f_v, and plot the results.

I used basically the same code for rk2_step, but am getting the error "setting an array element with a sequence". I was able to do guess and check until the error was close to 0, but when I try to do the plot something is going wrong in my for loop.

image

@jmr15122
Copy link

I am not sure if this has something to do with it, but I believe the num_sol_drag is a two-dimensional array and you are setting it with a one-dimensional statement in the for loop. I attempted to do a similar process of plotting the results and instead did it this way which seems to be a little simpler:

'''v0_examples = np.linspace(0,10,100)
error_in_v0 = np.zeros(100)
for i in range(0, len(error_in_v0)):
error_in_v0[i] = f_v(v0_examples[i])'''

Then, I plotted the sample v0 values versus their corresponding error and that helped me to make an educated guess.

@mes15111
Copy link
Author

Thank you! He ended up doing this one in the Google Hangout video and showed us this code which works:

v0_guess = np.linspace(0,1000)
e = np.zeros(len(v0_guess))
for i,v0 in enumerate(v0_guess):
e[i] = f_v(v0)

plt.plot(v0_guess,e)

Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants