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/hopper.ipynb
Views: 531
Modeling and Simulation in Python
Case study: Hopper optimization
Copyright 2017 Allen Downey
Testing make_system
Testing slope_func
Now we can run the simulation.
Plotting r
We can also see the relationship between y
and r
, which I derive analytically in the book.
And here's the figure from the book.
We can use interpolation to find the time when y
is 47 meters.
At that point r
is 55 mm, which is Rmax
, as expected.
The total amount of rotation is 1253 rad.
Unrolling
For unrolling the paper, we need more units:
And a few more parameters in the Condition
object.
make_system
computes rho_h
, which we'll need to compute moment of inertia, and k
, which we'll use to compute r
.
Testing make_system
Here's how we compute I
as a function of r
:
When r
is Rmin
, I
is small.
As r
increases, so does I
.
Here's the slope function.
Testing slope_func
Now we can run the simulation.
And look at the results.
Extrating the time series
Plotting theta
Plotting omega
Plotting y
Here's the figure from the book.
Yo-yo
Exercise: Simulate the descent of a yo-yo. How long does it take to reach the end of the string.
I provide a Condition
object with the system parameters:
Rmin
is the radius of the axle.Rmax
is the radius of the axle plus rolled string.Rout
is the radius of the yo-yo body.mass
is the total mass of the yo-yo, ignoring the string.L
is the length of the string.g
is the acceleration of gravity.
Here's a make_system
function that computes I
and k
based on the system parameters.
I estimated I
by modeling the yo-yo as a solid cylinder with uniform density (see here). In reality, the distribution of weight in a yo-yo is often designed to achieve desired effects. But we'll keep it simple.
Testing make_system
Write a slope function for this system, using these results from the book:
where is the augmented moment of inertia, .
Hint: If y
is less than 0, it means you have reached the end of the string, so the equation for r
is no longer valid. In this case, the simplest thing to do it return the sequence of derivatives 0, 0, 0, 0
Test your slope function with the initial conditions.
Then run the simulation.
Check the final conditions. If things have gone according to plan, the final value of y
should be close to 0.
Plot the results.
theta
should increase and accelerate.
y
should decrease and accelerate down.