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/chap24.ipynb
Views: 531
Modeling and Simulation in Python
Chapter 24
Copyright 2017 Allen Downey
Rolling paper
We'll start by loading the units we need.
And creating a Params
object with the system parameters
The following function estimates the parameter k
, which is the increase in the radius of the roll for each radian of rotation.
As usual, make_system
takes a Params
object and returns a System
object.
Testing make_system
Now we can write a slope function based on the differential equations
Testing slope_func
We'll use an event function to stop when y=L
.
Now we can run the simulation.
And look at the results.
The final value of y
is 47 meters, as expected.
The final value of radius is R_max
.
The total number of rotations is close to 200, which seems plausible.
The elapsed time is about 2 minutes, which is also plausible.
Plotting
Plotting theta
Plotting y
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.
Animation
Here's a draw function that animates the results using matplotlib
patches.
Exercise: Run the simulation again with a smaller step size to smooth out the animation.
Exercises
Exercise: Since we keep omega
constant, the linear velocity of the paper increases with radius. Use gradient
to estimate the derivative of results.y
. What is the peak linear velocity?
Now suppose the peak velocity is the limit; that is, we can't move the paper any faster than that.
Nevertheless, we might be able to speed up the process by keeping the linear velocity at the maximum all the time.
Write a slope function that keeps the linear velocity, dydt
, constant, and computes the angular velocity, omega
, accordingly.
Run the simulation and see how much faster we could finish rolling the paper.