appm 2360 lab #3: chaotic pendulum - applied...

9
APPM 2360 Lab #3: Chaotic Pendulum Figure 1: The chaotic trajectory of a double pendulum. This image is created by attaching an LED to the end of the pendulum and taking a long exposure. It is very easy to find chaotic behavior with a double pendulum. A single pendulum can also exhibit chaotic behavior, if it is driven by an outside force. Instructions Labs may be done in groups of 3 or less. You may use any program; but the TAs may not be able to help you unless you use MATLAB. One report must be turned in for each group and must be in PDF format. Labs must include each student’s: Name Student number Section number Recitation number 1

Upload: lydien

Post on 20-May-2018

214 views

Category:

Documents


1 download

TRANSCRIPT

APPM 2360

Lab #3: Chaotic Pendulum

Figure 1: The chaotic trajectory of a double pendulum. This image is created byattaching an LED to the end of the pendulum and taking a long exposure. It isvery easy to find chaotic behavior with a double pendulum. A single pendulumcan also exhibit chaotic behavior, if it is driven by an outside force.

Instructions

Labs may be done in groups of 3 or less. You may use any program; but theTAs may not be able to help you unless you use MATLAB. One report must beturned in for each group and must be in PDF format. Labs must include eachstudent’s:

• Name

• Student number

• Section number

• Recitation number

1

This lab is due on Friday, April 24, 2015 at 5pm. Each lab must be turnedin through D2L on the course page. When you submit the lab please includeeach group members information (name, student number, section number andrecitation number) in the comments. Once the labs are graded you need tospecifically check that your grade was entered. If you are missing a grade pleasebring the issue up with your TA within a week of grading.

The report must be typed (including equations). Be sure to label all imagesand graphs so that, independent of the text, it is clear what is in the graph.Simply answering the lab questions will not earn you a good grade. Take timeto write your report as up to 20% of your grade may be based on organization,structure, style, grammar, and spelling. Project office hours will be held inECCR 143 from Monday, April 20, 2015 to Friday, April 24, 2015. (Except thaton Tuesday April 21, office hours will be in the Stadium as usual.)

1 Objective

In this lab, you will explore the behavior of a forced, damped pendulum. Youwill see that the behavior is chaotic for certain parameter choices. We will walkyou through a similar example, the Lorenz system, first.

2 The Lorenz System

To complete this lab, we’ll need to understand how to solve systems of differen-tial equations in Matlab. We’ll practice with the Lorenz system. This systemwill also introduce us to mathematical chaos.

Edward Lorenz was an Americanclimatologist. In 1963 he developedthese equations to model atmosphericconvection:

x = a(y − x)

y = rx− y − xzz = xy − bz

where r, b, and a are parameters.This is called the Lorenz system.

It models a body of fluid (like wateror air) being heated from below. Thebehavior of the system changes a lot

for different values of these parameters. We’ll study the system for the param-eter values a = 16, r = 45, and b = 4 at first.

Notice the equations are nonlinear. Nonlinear DE systems can give rise toMUCH more complicated behavior than linear systems. Also, nonlinear systemsare usually difficult or impossible to solve by hand.

2

Since we can’t solve the Lorenz we have to solve numerically. To solvea system numerically, we pick a specific initial condition. Then, we run thesystem forward to find the trajectory from that initial condition. (Rememberyou studied this earlier in ODE.) This is only an approximation, of course.

We will use Matlab’s numerical ODE solver, ode45. (It’s a Runge-Kutta ap-proximation method that switches between order 4 and order 5.) Open Matlaband type doc ode45 in the Command Window to view the documentation forthis method. The documentation can be a bit confusing, so we’ll discuss theimportant points here.

• Syntax: [T,Y] = ode45(odefun, [t0 tf], y0)

• Inputs:

– odefun: Function handle. This is the most complicated input; we’llhave to create a separate m-file in Matlab for this. The functionshould take two inputs t and y, and output the derivative y′. Inother words, it describes the function y′ = f(t,y).

The vector y contains ALL our state variables. This is importantto understand! In other words, y = (x, y, z), and y′ = (x′, y′, z′).We have to put all our variables into a single vector, because that’sthe way ode45 works. Also important, in Matlab y and y′ must bothbe column vectors.

You turn a function into a function handle using an @ sign. Don’tworry, you’ll see how to do it in a second.

– [t0, tf]: Time interval on which to solve the DE.

– y0: Vector of initial conditions. In our case, y0 = (x0, y0, z0).

• Outputs:

– T: Column vector of the time points used. This is only interesting tous when plotting solutions of individual variables.

– Y: Solution array. In other words, this describes the approximatesolution to the DE system, starting from the initial condition wegave Matlab.

First let’s create the derivative function in an m-file. Once again, to useode45 we have to have two inputs t and y, and one output y′. (Because oursystem is autonomous, we don’t actually USE the variable t in the derivativefunction! But we have to include it anyway.) The function should look some-thing like

function Yprime = Lorenz(t,Y)% I use capital Y to represent the vector Y=(x,y,z)x = Y(1);y = Y(2);z = Y(3);

3

xprime = 16*(y-x);yprime = 45*x-y-x*z;zprime = x*y - 4*z;% Notice the semicolons on the line below (need to output a column vector)Yprime = [xprime;yprime;zprime];end

Now that we’ve made our derivative function, we just need an initial con-dition and a time interval to input to ode45. Let’s use the initial condition(15, 1, 0.1) and time interval t = 0 to t = 20. Open up a script and type

initialCondition = [-13,-12,52];timeInterval = [0,20];% Remember you need the @ in front of the function name[T,Y] = ode45(@Lorenz,timeInterval,initialCondition);xSolution = Y(:,1);ySolution = Y(:,2);zSolution = Y(:,3);

Looking in Matlab’s workspace, you see we now have two new variables T

and Y. T holds all the time steps while Y is a matrix with 3 columns. The firstcolumn is the approximate solution for x, the second column is y, and the thirdcolumn is z. We’ve already pulled out each column into new variables calledxSolution, ySolution, and zSolution. We can plot each of these against timeto see the solution for each variable. Or, we can plot them against each otherto generate solutions in phase space.

% plot x solution against timeplot(T,xSolution);% plot y solution against timefigure;plot(T,ySolution);% plot z solution against timefigure;plot(T,zSolution);% plot all 3 against each other (i.e. PHASE SPACE)% Since our system is 3d, we must use plot3 to see our 3d phase spacefigure;plot3(xSolution,ySolution,zSolution);

Chaos

The plots we just made are quite interesting. Notice how the solution plots forx, y, and z look sort of periodic... but not quite. Also, in the phase portrait wesee the trajectory loop around and around in roughly the same shape. But itnever takes exactly the same path while it loops around. This is an example ofa chaotic system. The almost periodic trajectory is one characteristic of chaos.

Another characteristic of chaos is sensitive dependence on initial conditions.If you pick two initial conditions that are only a TEENY bit different from eachother, they will result in trajectories that are VERY different. Run the followingcode to see an example.

4

%% Solve Lorenz system for two very close initial conditionsinitialCondition1 = [-13,-12,52];initialCondition2 = [-13.01,-12,52];timeInterval = [0,20];% Remember you need the @ in front of the function name[t1,Y1] = ode45(@Lorenz,timeInterval,initialCondition1);[t2,Y2] = ode45(@Lorenz,timeInterval,initialCondition2);

%% Plot the 2 solutions% plot all 3 against each otherfigure;plot3(Y1(:,1),Y1(:,3),Y1(:,2));hold on;plot3(Y2(:,1),Y2(:,3),Y2(:,2));

Sensitive dependence on initial conditions was firstdiscovered by Lorenz, in this very system. Lorenzcalled it the “butterfly effect,” a term you’ve proba-bly heard before. It means that a tiny change in initial conditions (like a flap ofa butterfly wing) can result in massive changes to the system later on (like a hur-ricane). Because of this, weather is extremely hard to predict. There is a limiton how accurately we can measure the current weather conditions. But eventhe tiniest inaccuracies of measurement cause huge errors in our predictions.

3 The Damped, Driven Pendulum

The pendulum consists of a bob of mass m hang-ing on a rod of length L. We ignore the massof the rod. The rod can turn freely in the planearound a peg at the top end. The pendulum isallowed to make full circular swings around thepeg, and we allow θ ∈ (−∞, ∞). For example ifthe pendulum starts at θ = 0 and swings all theway around once counterclockwise, then we sayθ = 2π.

The forces acting on the bob are:

• gravity: mg sin θ

• friction: bLθ

Friction is another word for damping.

• drive: A cos(αt)

This force comes from outside the pendu-lum. We could choose any type of drivingfunction; here we chose a cosine functiondependent on time. The parameters A andα represent the amplitude and frequency ofthe drive.

5

One way to physically produce the driveforce is to move the pendulum up and downas it swings. This YouTube video1 demon-strates a driven pendulum. In the video,they choose the amplitude A and frequencyα to make the inverted pendulum a stableequilibrium. We’ll explore other values of Aand α.

Newton’s second law says that force equals mass times acceleration:

F = ma

So if we add up all the forces on the pendulum, that’s the total force F . We alsohave acceleration = Lθ. (Because the acceleration in θ is θ, so the accelerationof the BOB is Lθ.) Putting these together,

−mg sin θ − bLθ +A cosαt = mLθ

(The minus signs come in because different forces act in different directions onthe bob.) This differential equation describes the motion of a pendulum. It’susually rewritten like this:

mLθ + bLθ +mg sin θ = A cos(αt) (1)

where m is the mass of the bob, L is the length of the rod, g is the constantfor gravity, b is a parameter describing the damping (friction), and A and α areparameters for the drive.

4 Problems

Before you start, watch this extremely helpful YouTube video 2. It’s a shortphysics lecture covering this very material, about 20 minutes long. Some of thekey points:

2:40 A computer animation of a pendulum. The box in the upper right plots themotion in phase space, that is, θ versus ω. There are two long triangularboxes on the bottom. The one on the top plots θ against time. The oneon the bottom plots the drive force against time.

3:30-4:00 good explanation of phase space

6:30-7:45 shows what happens to phase space when damping is added

1“Inverted Pendulum.” Harvard Natural Sciences Lecture Demonstrations.https://www.youtube.com/watch?v=5oGYCxkgnHQ

2“Chaos II: The Not-So-Simple Pendulum.” Philip Moriarty, School of Physics & Astron-omy, University of Nottingham, UK. https://www.youtube.com/watch?v=Ddj6X8Ljdg8

6

8:00 adds sinusoidal drive force (this is basically equivalent to our cosine driveforce)

11:00-13:00 describes why he wants to keep θ between −π and π in his plot, to makethe plot simpler. We will do something similar, but we’ll keep θ between0 and 2π.

13:00 chooses drive parameters so that frequency of drive matches natural fre-quency of of pendulum

14:30-18:15 Demonstrates a phenomenon in phase space known as “period doubling”.This is extremely interesting, but you don’t need to understand it to dothe lab.

18:20 Choose drive parameters that result in chaotic behavior

18:20-end A great description of what chaos looks like in phase space. You can alsosee what the pendulum itself looks like.

1. Turn the second-order DE from equation 1 into a system of two first-orderDEs. Define ω = θ. Write the system in terms of θ and ω. This system istwo-dimensional, as opposed to the three-dimensional Lorenz system.

2. Physically, θ = 0 and θ = 2π are the same. Explain why. However, ω = 0and ω = 2π are NOT the same. Explain why.

For the rest of the problems, assume that m = 0.1 kg and L = 0.1 m, and thatg is the force of gravity, with the appropriate units. For problems 3 - 7, assumethat b = 0, α = 0, and A = 0. This way, there is no damping and no driving.We’ll add in damping and driving later.

You will need to plot trajectories in phase space. We did this already for theLorentz system; refer back to those instructions if you need help. In the pen-dulum system, phase space is two-dimensional (while the Lorenz system wasthree-dimensional). Thus, you will use plot instead of plot3. You should plotθ on the horizontal axis, and ω on the vertical axis. Be sure to pick an appro-priate time interval for all the trajectories you plot.

3. Show analytically that (θ, ω) = (0, 0) is an equilibrium point of the system.What behavior does this point represent for the pendulum? What happensif the system is disturbed slightly from this point?

4. Plot a trajectory in phase space starting at initial condition (0.01, 0) todemonstrate what happens if the system is slightly disturbed from (0, 0).Interpret your plot.

5. Show analytically that (θ, ω) = (π, 0) is an equilibrium point of the sys-tem. What behavior does this point represent for the pendulum? Whathappens if the system is disturbed slightly from this point?

7

6. Plot a trajectory starting at initial condition (3, 0) to demonstrate whathappens if the system is slightly disturbed from (π, 0). Interpret your plot.

7. A phase-space portrait is a plot that includes multiple different trajecto-ries, showing the different types of behavior in different regions of phasespace. Figure 2 shows a phase-space portrait for the undamped, non-driven pendulum. Identify different types of trajectories in the plot.

Figure 2: Phase-space portrait for pendulum with no damping or driving

Describe the physical behavior corresponding to each type of trajectory.

8. For the trajectories you described, which direction are they traveling inphase space (i.e., left to right, right to left, clockwise, counterclockwise)?You may have to try plotting a few trajectories to figure it out.

9. Based on the phase space portrait: If the pendulum was sitting at θ = 0,how fast would you have to hit it so that it starts swinging around andaround in full circles? How long will it continue this behavior?

Now we’ll start playing with the parameters for damping and forcing, and seewhat happens to the behavior. You may have to modify the m-file that calculatesthe system derivatives, or make a new m-file.

10. Turning on damping by setting b = .25. Plot trajectories in phase spacefrom initial conditions (−2π, 30) and (1, − 15). Describe why they aredifferent from the undamped version. No matter what the initial conditionis, what do you predict for every trajectory?

11. Leave b = .25, and turn on the drive force. Use drive frequency α = .374and drive amplitude A = 1.74. Plot a trajectory starting at (0, 0). Is thistrajectory periodic or not? Try plotting the trajectory for a long timeinterval (more than 1000 seconds).

12. Repeat the above problem, but this time plot θ mod 2π. This keeps θbetween 0 and 2π so you can get a more clear picture of phase space.Matlab tips:

8

• If thetaSolution is the solution for θ, then type thetaSolution =

mod(thetaSolution,2*pi) before plotting.

• Every time the original trajectory travels in a full loop, it crossesθ = 2π. When you do θ mod 2π, now the trajectory jumps fromθ = 2π to θ = 0 before continuing on. This will produce a weirdhorizontal line in your plot each time. To get rid of these, you shouldplot with dots or circles instead of lines.

• You may also want to change the size of the dots or circles, becausethere are so many of them. In Matlab, you can do this by typingplot(x,y,’o’,’markersize’,.5). The ’o’ says plot circles, andthe number after ’markersize’ tells Matlab how big to make them.

13. Leave b = .25 and α = .374. Experiment with different values for A. Findanother value that produces a chaotic trajectory. Also find a value thatproduces a periodic trajectory. Hand in plots for both.

14. In an autonomous system, trajectories never cross each other in phasespace. Explain why. In a non-autonomous system, trajectories can crossin phase space. Explain why.

9