Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/notebooks/jump.ipynb
Views: 531
Modeling and Simulation in Python
Bungee jump case study
Copyright 2018 Allen Downey
Bungee jumping
Suppose you want to set the world record for the highest "bungee dunk", as shown in this video. Since the record is 70 m, let's design a jump for 80 m.
We'll make the following modeling assumptions:
Initially the bungee cord hangs from a crane with the attachment point 80 m above a cup of tea.
Until the cord is fully extended, it applies no force to the jumper. It turns out this might not be a good assumption; we will revisit it.
After the cord is fully extended, it obeys Hooke's Law; that is, it applies a force to the jumper proportional to the extension of the cord beyond its resting length.
The jumper is subject to drag force proportional to the square of their velocity, in the opposite of their direction of motion.
Our objective is to choose the length of the cord, L
, and its spring constant, k
, so that the jumper falls all the way to the tea cup, but no farther!
First I'll create a Param
object to contain the quantities we'll need:
Let's assume that the jumper's mass is 75 kg.
With a terminal velocity of 60 m/s.
The length of the bungee cord is
L = 40 m
.The spring constant of the cord is
k = 20 N / m
when the cord is stretched, and 0 when it's compressed.
Now here's a version of make_system
that takes a Params
object as a parameter.
make_system
uses the given value of v_term
to compute the drag coefficient C_d
.
Let's make a System
spring_force
computes the force of the cord on the jumper.
If the spring is not extended, it returns zero_force
, which is either 0 Newtons or 0, depending on whether the System
object has units. I did that so the slope function works correctly with and without units.
The spring force is 0 until the cord is fully extended. When it is extended 1 m, the spring force is 40 N.
drag_force
computes drag as a function of velocity:
Here's the drag force at 60 meters per second.
Acceleration due to drag at 60 m/s is approximately g, which confirms that 60 m/s is terminal velocity.
Now here's the slope function:
As always, let's test the slope function with the initial params.
And then run the simulation.
Here's the plot of position as a function of time.
After reaching the lowest point, the jumper springs back almost to almost 70 m, and oscillates several times. That looks like more osciallation that we expect from an actual jump, which suggests that there some dissipation of energy in the real world that is not captured in our model. To improve the model, that might be a good thing to investigate.
But since we are primarily interested in the initial descent, the model might be good enough for now.
We can use min
to find the lowest point:
At the lowest point, the jumper is still too high, so we'll need to increase L
or decrease k
.
Here's velocity as a function of time:
Although we compute acceleration inside the slope function, we don't get acceleration as a result from run_ode_solver
.
We can approximate it by computing the numerical derivative of ys
:
And we can compute the maximum acceleration the jumper experiences:
Relative to the acceleration of gravity, the jumper "pulls" about "1.7 g's".
Under the hood
The gradient function in modsim.py
adapts the NumPy function of the same name so it works with Series
objects.
Solving for length
Assuming that k
is fixed, let's find the length L
that makes the minimum altitude of the jumper exactly 0.
The metric we are interested in is the lowest point of the first oscillation. For both efficiency and accuracy, it is better to stop the simulation when we reach this point, rather than run past it and the compute the minimum.
Here's an event function that stops the simulation when velocity is 0.
As usual, we should test it with the initial conditions.
Now we can test it and confirm that it stops at the bottom of the jump.
Exercise: Write an error function that takes L
and params
as arguments, simulates a bungee jump, and returns the lowest point.
Test the error function with a guess of 25 m and confirm that the return value is about 5 meters.
Use root_scalar
with your error function to find the value of L
that yields a perfect bungee dunk. Hint: before calling root_scalar
, make a version of params
with no dimensions.
Run a simulation with the result from root_scalar
and confirm that it works.