velocity = append(velocity,v) # Now that the calculations are done, plot the position: plot(time, height, 'ro') xlabel("Time (s)") ylabel("Height (m)") # just for comparison, I'll also plot the known solution! plot(time, xi + vi*time - 0.5*g*time**2, 'b-') show() You can see on the graph below that this a little bit off, but not bad; you can actually works pretty well. It’s make it better by making dt smaller and N correspondingly larger. ASSIGNMENT Change that sample code to of free-fall. The equations for SHM, ‘solve’ Simple Harmonic Motion instead in Euler format, are dx = v dt dv = a dt (6) a=−g, a=−ω2 xi=1, vi=0 x. ω=1 but instead of use Use , and . Plot the position for 10 seconds. Make the code put your name in the title, of course, and ‘A’ students will plot the known solution also!
velocity = append(velocity,v) # Now that the calculations are done, plot the position: plot(time, height, 'ro') xlabel("Time (s)") ylabel("Height (m)") # just for comparison, I'll also plot the known solution! plot(time, xi + vi*time - 0.5*g*time**2, 'b-') show() You can see on the graph below that this actually works pretty well. It’s a little bit off, but not bad; you can make it better by making dt smaller and N correspondingly larger. ASSIGNMENT Change that sample code to ‘solve’ Simple Harmonic Motion instead of free-fall. The equations for SHM, in Euler format, are dx = v dt dv = a dt (6) but instead of a=−g, use a=−ω2 x. Use xi=1, vi=0 , and ω=1 . Plot the position for 10 seconds. Make the code put your name in the title, of course, and ‘A’ students will plot the known solution also!
PICUP_EX5.docx