Jupyter notebook free fall with quadratic drag.ipynb
Numerical solution of the non-dimensional equation of motion for a mass falling with quadratic drag
The equation to solve is
Define the step size and the initial height. These parameters can be changed here, to see the effects on the solution. The initial velocity is zero.
Now we can calculate the position and velocity iteratively. We can also calculate the exact position and velocity at each time step for comparison later. These are and
Define the functions that return the exact values of the position and the velocity:
Now we aready to start calculating the position and velocity iteratively. First, from and we calculate and using a simple forward Euler approximation: We also calculate the exact values at .
Then we iterate until the object reaches the ground, that is while . Notice that the calculation actually ends when the position becomes negative, so the plots will only be drawn up to the previous step, which we will call . And we also calculate the exact values for comparison later.
Just for fun, we will print the duration of the fall, and the final velocity and position. If is high enough, the final velocity should be near the terminal velocity, which is .
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-16-1ceb9e7f437f> in <module>()
1 # Plot the position as a function of time
2
----> 3 plot(t[0:N], x[0:N], lw=2, color='red')
4 xlabel("$T$")
5 ylabel("$X$")
NameError: name 'plot' is not defined
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-17-513d3892b877> in <module>()
1 # Plot the velocity as a function of time
2
----> 3 plot(t[0:N], v[0:N], lw=2, color='red')
4 xlabel("$T$")
5 ylabel("$V$")
NameError: name 'plot' is not defined
Now for comparison purposes, we will plot the exact position (blue curve) with the numerical solution every 0.2 time units (red circles). You can change the step size to something larger, like , at the beginning see how the match degrades.
And the same for the velocity: