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/chapters/chap24.ipynb
Views: 531
Printed and electronic copies of Modeling and Simulation in Python are available from No Starch Press and Bookshop.org and Amazon.
Rotation
Modeling and Simulation in Python
Copyright 2021 Allen Downey
License: Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
This chapter is available as a Jupyter notebook where you can read the text, run the code, and work on the exercises. Click here to access the notebooks: https://allendowney.github.io/ModSimPy/.
In this chapter and the next we'll model systems that involve rotating objects. In general, rotation is complicated. In three dimensions, objects can rotate around three axes and many objects are easier to spin around some axes than others. If the configuration of an object changes over time, it might become easier or harder to spin, which explains the surprising dynamics of gymnasts, divers, ice skaters, etc. And when you apply a twisting force to a rotating object, the effect is often contrary to intuition. For an example, see this video on gyroscopic precession: http://modsimpy.com/precess.
We will not take on the physics of rotation in all its glory; rather, we will focus on simple scenarios where all rotation and all twisting forces are around a single axis. In that case, we can treat some vector quantities as if they were scalars; that is, simple numbers.
The fundamental ideas in these examples are angular velocity, angular acceleration, torque, and moment of inertia. If you are not already familiar with these concepts, don't worry; I will define them as we go along, and I will point to additional reading.
The Physics of Toilet Paper
As an example of a system with rotation, we'll simulate the manufacture of a roll of toilet paper, as shown in this video: https://youtu.be/Z74OfpUbeac?t=231. Starting with a cardboard tube at the center, we will roll up 47 m of paper, a typical length for a roll of toilet paper in the U.S. (see http://modsimpy.com/paper).
The following figure shows a diagram of the system: represents the radius of the roll at a point in time. Initially, is the radius of the cardboard core, . When the roll is complete, is .
I'll use to represent the total rotation of the roll in radians. In the diagram, represents a small increase in , which corresponds to a distance along the circumference of .
I'll use to represent the total length of paper that's been rolled. Initially, and . For each small increase in , there is a corresponding increase in :
If we divide both sides by a small increase in time, , we get a differential equation for as a function of time.
As we roll up the paper, increases. Assuming it increases by a fixed amount per revolution, we can write
where is an unknown constant we'll have to figure out. Again, we can divide both sides by to get a differential equation in time:
Finally, let's assume that increases at a constant rate of rad/s (about 2900 revolutions per minute):
This rate of change is called an angular velocity. Now we have a system of differential equations we can use to simulate the system.
Setting Parameters
Here are the parameters of the system:
Rmin
and Rmax
are the initial and final values for the radius, r
. L
is the total length of the paper. omega
is the angular velocity in radians per second.
Figuring out k
is not easy, but we can estimate it by pretending that r
is constant and equal to the average of Rmin
and Rmax
:
In that case, the circumference of the roll is also constant:
And we can compute the number of revolutions to roll up length L
, like this.
Converting rotations to radians, we can estimate the final value of theta
.
Finally, k
is the total change in r
divided by the total change in theta
.
At the end of the chapter, we'll derive k
analytically, but this estimate is enough to get started.
Simulating the System
The state variables we'll use are theta
, y
, and r
. Here are the initial conditions:
And here's a System
object with init
and t_end
:
Now we can use the differential equations from the previous section to write a slope function:
As usual, the slope function takes a time stamp, a State
object, and a System
object.
The job of the slope function is to compute the time derivatives of the state variables. The derivative of theta
is angular velocity, omega
. The derivatives of y
and r
are given by the differential equations we derived.
And as usual, we'll test the slope function with the initial conditions.
We'd like to stop the simulation when the length of paper on the roll is L
. We can do that with an event function that passes through 0 when y
equals L
:
We can test it with the initial conditions:
Now let's run the simulation:
Here are the last few time steps.
The time it takes to complete one roll is about 4.2 seconds, which is consistent with what we see in the video.
The final value of y
is 47 meters, as expected.
The final value of r
is 0.55 m, which is Rmax
.
The total number of rotations is close to 200, which seems plausible.
As an exercise, we'll see how fast the paper is moving. But first, let's take a closer look at the results.
Plotting the Results
Here's what theta
looks like over time.
theta
grows linearly, as we should expect with constant angular velocity.
Here's what r
looks like over time.
r
also increases linearly.
Here's what y
looks like over time.
Since the derivative of y
depends on r
, and r
is increasing, y
grows with increasing slope.
In the next section, we'll see that we could have solved these differential equations analytically. However, it is often useful to start with simulation as a way of exploring and checking assumptions.
Analytic Solution
Since angular velocity is constant:
We can find as a function of time by integrating both sides:
Similarly, we can solve this equation
to find
Then we can plug the solution for into the equation for :
Integrating both sides yields:
So is a parabola, as you might have guessed.
We can also use these equations to find the relationship between and , independent of time, which we can use to compute . Dividing Equations 1 and 2 yields
Separating variables yields
Integrating both sides yields
Solving for , we have
ParseError: KaTeX parse error: Undefined control sequence: \label at position 44: … \̲l̲a̲b̲e̲l̲{eqn3}When , , so
When , , so
Solving for yields
ParseError: KaTeX parse error: Undefined control sequence: \label at position 53: …}^2) \̲l̲a̲b̲e̲l̲{eqn4}Plugging in the values of the parameters yields 2.8e-5
m/rad, the same as the "estimate" we computed in Section xxx.
In this case the estimate turns out to be exact.
Summary
This chapter introduces rotation, starting with an example where angular velocity is constant. We simulated the manufacture of a roll of toilet paper, then we solved the same problem analytically.
In the next chapter, we'll see a more interesting example where angular velocity is not constant. And we'll introduce three new concepts: torque, angular acceleration, and moment of inertia.
But first, you might want to work on the following exercise.
Exercises
This chapter is available as a Jupyter notebook where you can read the text, run the code, and work on the exercises. You can access the notebooks at https://allendowney.github.io/ModSimPy/.
Exercise 1
Since we keep omega
constant, the linear velocity of the paper increases with radius. We can use gradient
to estimate the derivative of results.y
.
Here's what the result looks like.
With constant angular velocity, linear velocity is increasing, reaching its maximum at the end.
Now suppose this peak velocity is the limiting factor; that is, we can't move the paper any faster than that. In that case, 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. Then, run the simulation and see how much faster we could finish rolling the paper.