Intro to Chaos in Mechanics

This is really just for me so that I won’t forget.  I mean, I will forget—but then I can look back at this post and remember stuff.  Here’s to you Future Rhett.

What is a chaotic system?  Really, that’s the question—isn’t it?  There is the classic example of the double pendulumHere is some code for a double pendulum. And this is what it looks like.

Nov-11-2018 15-57-59.gif

But this isn’t the best system.  The problem is that there are two coordinates—the angle for the top bar and the angle for the bottom bar.  Sure, it’s cool—but what if you want to plot angle vs. time or something.  You have to plot both angles vs. time and that’s a bummer.

OK, how about a model of bounded population growth?  That’s just one dimensional, right?  Actually, it doesn’t even have to be population, it’s just an equation—something like this.

x_{n+1} = 4rx_n(1-x_n)

In this expression, r is some parameter—it really doesn’t matter what.  Let’s just model this expression for different values of r.  I’ll use a starting x value of 0.1 and r values of 0.7 and 0.9.   Here is the code.

GlowScript IDE 2018-11-11 17-55-15.png

Notice that when r = 0.7, the population reaches some stable value—but this is not true for r = 0.9.

Bifurcation Diagram

Now for another way to look at a chaotic systems—the bifurcation diagram.  Honestly, I didn’t really understand these things until I made one.  Here’s what we are going to do.

  • Start with some initial value of x (just pick something—I’m going to use 0.5).  Pick a value for r also.  Let’s just start at 0.1.
  • Run the model for 200 iterations and throw out that data.  This should allow us to look at the long term behavior for that particular value of r (throws out the transient behavior).
  • Now run the model for 100 additional iterations and save these.
  • Create a plot of these final x values vs. r.
  • Next increase the r value a little bit (I will increase it by 0.001)
  • Repeat until you get bored.

So if the model is stable after the initial stuff, then it will just keep plotting the same value of x after the first 200 iterations and you will just get a dot.  If it’s not stable after the first stuff, then you will get a bunch of dots with different x values.

OK, let’s do it.  Here is the code.  Oh, I made a function to iterate the model.  I probably should put more comments in there.

This is what it looks like.

GlowScript IDE 2018-11-12 09-08-29.png

Up to an r value of about 0.75, you only get one final x value.  After that, you get two different values . With r over 0.9, it gets crazy.

OK, that’s enough for now.  I just want to make sure future Rhett knows how to make a bifurcation diagram.

Angular Momentum and the Moment of Inertia

Let me be clear—something isn’t working with my program.  However, I think the idea is solid. Also, by writing this I might be able to figure out my problem.

Two Forms of Angular Momentum

I’ll just just to the main point. I’m trying to make a connection between the two forms of angular momentum.  The first is the point-particle definition.  This says that the angular momentum of a point is defined as:

\vec{L} = \vec{r} \times \vec{p}

In this expression, L is the angular momentum, r is the position vector, and p is the linear momentum.

The other form of angular momentum is defined as:

\vec{L} = I\vec{\omega}

Here ω is the angular velocity vector for a rigid object and I is the moment of inertia tensor.

Ok, let’s get started.  I’ll begin with a simple case and move to more complicated stuff.

A free particle.

A particle has a mass m and moves with a constant velocity (no external forces).  What happens to the angular momentum?  Here is a python program for a free particle in which I also calculate the angular momentum.  This is just a picture – you need to go here to run it.

Trinket 2018-11-05 10-46-12.png

Here is a plot of the z-component of the angular momentum in this case.

Trinket 2018-11-05 10-48-10.png

Notice that it’s constant.  Oh, I assume you know about cross products—they are in vpython, so you don’t have to do it manually.

So, yes—angular momentum is conserved.  No big surprise there.  But what if you change the origin?  Is angular momentum still conserved?  Try it.

There is very little point looking at the moment of inertia.  I’ll do that next.

Single object constrained to circular motion.

I want to get an object moving in a circle—but I don’t want to make some crazy constraint.  This sounds like a job for THE SPRING.  Yes, I will model an object moving in circular motion by using a spring attached to the object and some stationary thingy.

Here is the code.  Here is what it looks like.

Nov-05-2018 11-19-46.gif

If you calculate the angular momentum (from the linear momentum), here is what you get.

Trinket 2018-11-05 11-21-20.png

It doesn’t look constant—but I think that’s just a rounding error.  Reminder: this is the angular momentum from \vec{L} = \vec{r} \times \vec{p}.  What if I use the moment of inertia and the angular velocity?  Do I get the same thing?

I can calculate the angular velocity as:

\vec{omega} = \frac{\vec{r} \times \vec{v}}{r^2}

For objects moving about a fixed axis, the moment of inertia is a scalar value that is calculated as:

I = \sum_i m_i r_i^2

Notice that if you put these two definitions together, you get (essentially):

I\vec{\omega} = \vec{r}\times \vec{p}

So it should work.

Two masses.

Using a stationary pivot point can cause some problems.  Since the pivot point is stationary, there must be some external forces on the system.  This means that calculating momentum and angular momentum can be difficult.

Here is the program.  Here is what it looks like.

Nov-05-2018 12-54-39.gif

Yes, these are two unequal masses but the center of mass is stationary.  Also, I will skip the graph, but angular momentum (the z-component) is constant.

Here is a different (but similar) version of the program in which I also calculate the moment of inertia version of the angular momentum.  Everything seems to work—until it doesn’t.

What happens if the center of mass of the system is not zero?  In this case, I need to redo the angular momentum calculation.  First, for the point model, it would be still be r cross p, but I can write it two ways:

\vec{L} = \vec{r}_1 \times \vec{p}_1 = \vec{r}_{com} \times \vec{p}_{com} + \vec{r}_{1r} \times \vec{p}_{1r} +\vec{r}_{2r} \times \vec{p}_{2r}

In this case, the 1r subscript means the position relative to the center of mass and the momentum relative to the center of mass.  The com subscript means center of mass.

For the moment of inertia method, I have:

\vec{L} = \vec{r}_{com} \times \vec{p}_{com} + I\vec{\omega}

But this is where I will stop. For some reason, I can’t get a constant angular momentum using the moment of inertia.  Here is the plot of the component of momentum for the case when the center of mass is moving.

GlowScript IDE 2018-11-05 15-08-36.png

I feel like I am making some silly mistake.  So, here are some notes and comments.

  • Maybe I am calculating the relative velocity incorrectly.
  • Maybe it has something to do with my definition of the angular velocity.
  • Note that the two masses can have slightly different angular velocities since this isn’t actually a rigid object—it’s just mostly rigid (stiff spring).
  • I feel like I have so many different programs, that I’m losing track of what works (that’s why I wrote this blog post).
  • What’s the next step?  Well, after getting this calculation to work—I have big plans.  The ultimate goal is to have a 4 mass rotator (4 masses connected by springs) and calculate the moment of inertia and the angular momentum.  I would be very happy if I could show that the angular velocity vector doesn’t have to be in the same direction as the angular momentum vector. That would be cool.

 

Update on Python Physics Curriculum

So here is the deal.  I had this idea.  The plan was to include numerical calculations into the intro physics curriculum by writing a sort of online textbook.  Or maybe just redo my Just Enough Physics ebook to include more numerical calculations.  Anyway, this is what I came up with. It’s written with trinket.io – an online implementation of python that pretty much rocks.

Here is my curriculum (it’s incomplete – but totally free).

Introductory Physics with Python

Here are some of my own thoughts on this curriculum (including using trinket.io):

  • It’s free and online.  That’s mostly good – but I don’t know if online is the best format for physics.
  • There is one thing about trinket.io that makes this rock.  There is python RIGHT IN THE PAGE.  Readers can view and run code – no logging in, no saving, nothing.  Just edit and run.  No barriers.
  • It has the same idea as Just Enough Physics in that it goes over the basic stuff – but doesn’t overload the student with tons of different ideas (no fluid dynamics, waves, buoyancy, sound…).  It’s not that those are bad topics, it’s just too much.  Too much.
  • Homework.  Students want homework questions.  I sort of added those in – but students seem to want traditional homework questions.

Now for the part that needs work.  Well, all of it needs work – it’s not complete.  But I made an error – I figured I would finish this curriculum as I was using it to teach the summer session of physics, but the pressure was too much.  In the end, I think I made it too much like the traditional format of a textbook (with the traditional order of topics).  Really, I started along the best path – but went off the rails when I wanted to do a problem that involved new physics.  So, I just added that new stuff in there.

I need to rethink just what I want to cover – and here is my new plan.

  • Kinematics in 1-D and 2-D. I like starting with kinematics because students can model motion and this works great with numerical calculations.  The one problem is that you have to use acceleration instead of change in momentum – and this messes up with my momentum principle.  Actually, maybe I will just do 1-D motion so that I don’t need vectors.
  • Forces. I don’t really want to focus on forces and equilibrium, but the students need this to do more stuff.  In this, I need to do the following.
    • Vectors.  Boom – need vectors.
    • Special forces: gravity, real gravity, maybe Coulomb force.
    • What about friction, and forces of constraint (like the normal force)?  Here you can see how it gets out of hand.  Friction is super crazy if you think about it – so are normal forces.
    • What if I just did simple forces – like pushing with your hand or rockets?
  • Momentum Principle.  Here I need to make a connection between forces and motion.  Since I used acceleration before, I need to make a connection between the momentum principle and \vec{F}_\text{net} = m\vec{a}.  Honestly, I hate calling this Newton’s Second Law – it seems wrong.
    • But what about circular acceleration?  How do you deal with that?  I don’t know.  Maybe just avoid it for now.
  • Work Energy Principle. I think this is mostly ok – except I need to introduce the spring force and spring potential energy.
  • Angular Momentum Principle.  My initial idea was to cover “Three Big Ideas” – momentum principle, work-energy, angular momentum principle.  However, there is SO MUCH baggage associated with angular momentum principle.  Much of this stuff is just beyond intro-level students.

I think I have a new plan.

  • Start with kinematics in 1-D.
  • Forces – but simple stuff.  No friction.  No normal forces.  All the examples will be in space or something.
  • Momentum Principle and acceleration. Again, normal stuff.  No forces of constraint.  Mostly space stuff because that will be fun.  Projectile motion stuff too.
  • Work-Energy Principle.  Springs, gravity, dropping objects.  Orbits.
  • Special cases.  Instead of Angular Momentum, I’m going to go over forces of constraint, friction, normal forces, circular acceleration.

The end.  Oh, I need to make sure there are plenty of exercises for students.  Rewrites coming.

Numerical Calculation Collection

The following are some of my best posts about numerical calculations.

Working notes for my bouncing ball running model

I’ll be honest.  I had some problems getting my bouncing ball running model working.  Oh, here is the model.

https://www.wired.com/story/how-is-a-runner-like-a-bouncing-ball/

Basically, this models the speed of a running human by assuming they are bouncing ball.  When the human impacts the ground, there is some maximum impact force and an impact time.  The impact time decreases with horizontal velocity such that eventually, all the force is used in the vertical direction to keep the human off the ground long enough to switch feet in the air.  The end.

As I was making this model, I took some notes because I couldn’t get it to work.  Here are my notes.  Hopefully you can use this to see how to troubleshoot a program.

Running model notes

I think I mostly have it working:

http://www.glowscript.org/#/user/rhettallain/folder/blog_posts/program/runningbouncemodel/edit

Here is basically how it works.  Two big ideas:

  • Humans can push off the ground with some maximum force.  This force does two things – gets them off the ground and in the air so legs can move and pushes them forward
  • The contact time with the ground is small and gets smaller as horizontal speed increases
  • This means as the human speeds up, the ground force eventually gets to where it can only push up and not forward

Here is what it looks like so far

Here is a graph of speed vs. time

  • This model reaches a max speed of about 3.5 m/s in just a couple of strides – that doesn’t seem right
  • I think my Fv calc is wrong – it gives back the same speed not the needed vertical speed to get the stride time
  • Need to recalcualte Fv based on pfinal
  • If you want to be in the air for ts seconds, then your initial vertical velocity must be -g=dv/dt.  dv=g*dt dv = 2vstart. start=(½)gdt
  • Now to calculate the force. I know tc (contact time) so F = dp/dt = m*(vy2-vy1)/tc – this is the total force = Fv-mg so Fv = that stuff +mg

Something isn’t right.  Here is a plot of position vs. time

It’s getting higher and higher (and going lower – weird)

  • I’m getting stride (in air) times of 0.09 to 0.13 – that’s wrong

 

Ok – I think I know the problem.  I need to set the force push time loop and forget about while human.pos.y<R – I think that’s my problem

 

How about this

  1. Once human hits the ground – calculate Fv, Fx, and tc set tcount = 0
  2. While tcount < tc – set human.pos.y = ground. And set the forces
  3. When tcount = tc, turn off the forces and stop holding the person

 

It appears there is something wrong with my Fx.

  • Fx is some value for the first push – but after that it goes to zero and the Fv is maxed out.
  • Werid
  • There is a problem with both Fv and Fx

 

The problem is the time of impact – it gets too small such that the required force is HUGE

  • How about a min time – and it can’t go lower?

 

Fmax = m*2v/t

t=m*2*v/Fmax

 

I think the problem is that during the contact time, the horizontal force is too much so that the human ends up going faster than the theoretical speed.

 

I can use the time and force and velocity to estimate the average velocity and then recalculate the time

This is the paper

https://www.physiology.org/doi/pdf/10.1152/japplphysiol.00947.2009

It has this plot.

This shows a decrease in contact time with speed

Here is what I get for a fit

This gives a contact time function of

Although this “blows up” at v= 0.  Maybe I should say tc = 0.3612 for v < 2 and this expression for v>=2

End of notes – it finally worked.

Python Tip: User Scrolling

Just another quick tip.  Sometimes I create python to use as a demonstration. Here is an example:

https://trinket.io/glowscript/717bedba81

This is a double pendulum (sorry for the lack of embeds – I hope to fix that soon).  But there is a problem when you use the code as an embedded demo.  What happens if a user is reading over a blog post using the scroll wheel?  If they mouse over the trinket embed and scroll, they will zoom out and not see anything.

You can fix this by adding the following:

Yes, just add scene.userzoom=False

That’s it.

Python tip: Pausing

Ok, I’m going to start writing down things I learn about VPython.  First, a note.  If I say “VPython” or “Glowscript” – I’m really talking about the same thing.  In my usage, I will let VPython be a program in python with the visual module.  Hopefully, these things that I write will be the same for both platforms.

Now for today’s tip – how do you pause a program?  In the past, I have made these “start”-“pause” buttons.  It’s not super difficult to do, but there is some stuff in there that I just don’t understand. But there is a better way.

Let me start with a sample program.  This is just a ball tossed in the air – but with a pause button. Code here.

The magic happens in line 11.  When you put that scene.pause() in your program, you get a big “play” button in the lower right of your output window.  In this case, the program is paused before the calculations start so that the play button is there at the beginning.

Of course, you could have some calculations and then the pause button – it just depends on what you are trying to do.