Anda di halaman 1dari 14

NumericalAnalysisoftheDynamicsofaDoublePendulum

RojaNunna

Math53:Chaos!

ProfessorAlexanderBarnett

DartmouthCollege

Fall,2009

Aplanardoublependulumisasimplemechanical
systemthathastwosimplependulaattachedend
toendthatexhibitschaoticbehavior.Theaimof
thisprojectwillbetonumericallyanalyzethe
dynamicsofthedoublependulumsystem.First,the
physical system is introduced and a system of
coordinates is fixed, and then the Lagrangian and
the Hamiltonian equations of motions are derived.
Wewillfindthatthesystemisgovernedbyasetof
couplednonlinearordinarydifferentialequations
andusingthese,thesystemcanbesimulated.
FinallyweanalyzePoincarsections,thelargest
lyapunovexponent,progressionoftrajectories,and
Figure1:Schematicrepresentationofthe
changeofangularvelocitieswithtimeforcertain
constructionofasimpledoublependulumwhere
systemparametersatvaryinginitialconditions.
m1,L1,and1representthemass,lengthandthe

anglefromthenormaloftheinnerbobandm2,L2,
Systemofcoordinates
and2standforthemass,length,andtheangle
ThedoublependulumisillustratedinFig.1.Itis
fromthenormaloftheouterbob2.
convenienttodefinethecoordinatesintermsof

theanglesbetweeneachrodandthevertical.In
Equationsofmotion
thisdiagramm1,L1,and1representthemass,
Now,byresolvingthesequantitiesontohorizontal
lengthandtheanglefromthenormaloftheinner
andverticalcomponents,weobtainthepositionof
bobandm2,L2,and2standforthemass,length,
thecenterofmassofthetworods,where(x1,y1)
andtheanglefromthenormaloftheouterbob.To
arethepositionoftheinnerboband(x2,y2)isthe
simplyournumericalanalysis,letusassumethat
positionoftheouterbob.
m1=m2=mandL1=L2=l.Thatis,weconsidertwo

identicalrodswith( ).Assumethat
sin (1)
massesofrodscanbeneglectedbuttheirmoment
ofinertiashouldbeincludedtobetterreflectthe sin sin (2)
physicalsystemtheyrepresent1. cos (3)

cos cos (4)


TheLagranianisgivenby

(5)

(6)
Thefirsttermisthelinearkineticenergyofthe
centerofmassofthebodiesandthesecondtermis
therotationalkineticenergyaroundthecenterof
massofeachrod.Thelasttermisthepotential Simulationofthemotionforvariousinitial
energyofthebodiesinauniformgravitational conditionscanbeperformedbyrunningthe
field. attachedMATLABcodethatusesode45.
Plugginginthecoordinatesabove,weobtain
4 3 cos SomeTheory
Letusintroduceanewconceptofquasiperiodic
3 (7)
motion.Roughlyspeaking,theyrefertoalmost
Thereisonlyoneconservedquantity(theenergy), periodicmotion.Moremathematically,itcanbe
andnoconservedmomenta.Thetwomomenta thoughtofas5thetypeofmotionexecutedbya
maybewrittenas dynamicalsystemcontainingafinitenumberof
8 3 cos incommensurablefrequencies.
(8)
Fromequations14to17,weseethatthedynamics
2 3 cos
ofadoublependulumcanbedescribedwith4
(9) variables,thetwoanglesandtheircorresponding
Theseexpressionsmaybeinvertedtoget (angular)velocities,whichspanthefour
(10) dimensionalphasespaceofthesystem6.Sincethe
doublependulumisahamiltoniansystem,total
(11) energyisconserved(equation20)andthisreduces
Theremainingequationsofmotionformomentum thefourdimensionalphasespacetoathree
are dimensionalmanifold.Further,TheKAMtheorem
statesthatifahamiltoniansystemissubjectedtoa
sin
weaknonlinearperturbation,someoftheinvariant
3 (12) torithathavesufficientlyirrationalfrequencies
sin survive.Inotherwords,themotioncontinuestobe
quasiperiodic7.KAMtellsusthatatlowerenergies,
(13)3 thefunctionisintegrable(ithasasmanyconserved
Letsassumenowthat 1.Thisgivesusa quantitiesastherearedegreesoffreedominthe
setoffourequationsthatcanbeusedtosimulate system)8.Athighenergythependulumbehaves
thebehaviorofthedoublependulum likeasimplerotor,withthesystemrotatingrapidly
6 (14) inastretchedcofiguration(1=,2=0).Inthis
casethekineticenergytermsintheLagrangian
6 (15) dominatethepotentialenergytermsandmaybe
describedbysettingg=0intheequationsof
sin 3 (16)
motion.Thetotalangularmomentumisconserved,
sin (17) becauseintheabsenceofgravity,thereisno
Theconservedquantity,energyfunction,isgiven torqueonthependulum.Theresultingmotionof
by thesystemisregular(nonchaotic),becausea
systemwithtwodegreesoffreedomandtwo
constraints(conservationoftotalenergyandtotal
cos 2 angularmomentum)cannotexhibitchaos.It
(18) follows,forexample,thatthedoublesquare
pendulumwouldnotexhibitchaosifinstalledon
Substituitingtheabovesolvedequationsfor and
thespacestation9.Lowerenergiesandhigher
,weobtain
energies=periodicmotion.Fromthistheoretical
evidence,wehypothesizethatthebehaviorofa
2 (19) doublependulumvariesfromregularmotionat
Again,whenm=l=1, lowenergies,tochaosatintermediateenergies,
andbacktoregularmotionathighenergies10.
2
4
(20)


Poincare
Poincaresectionsallowfastandinformativeinsight Simulations
intothedynamicsofthedoublependulum.The Letusstartwithlowenergyconditions.Usingthe
differenttypesofmotionappearasfinitenumber Hamiltonian,theenergycaneasilybecalculatedin
ofpointsforperiodicorbits,curvefillingpoints Joules.Whenwehaveinitialconditions=y0=
(invariantcurves)forquasiperiodicmotionand , , , =[0.2,0.2828,0,0],theenergy=
areafillingpointsforchaotictrajectories. 0.7809J.Atthislowenergyweexpectedperiodic
behavior.Theattachedcodetitledhamiltonian.m
WecanconstructatwodimensionalPoincare returnsthisvalueforaninputofy0.
sectionbylookingatthetrajectoryonlyatthose
pointswhentheouterpendulumpassesthe (Figures2,3,4,5,6areinAppendixA)Theperiodic
verticalposition,thatis2=0.Equation20then trajectoryoftheouterbobisclearfromfigure2a,
yieldsaquadraticequationfor2,withsolutions thePoincaresectionsarepresentedinfigure2b
andshowafinitenumberofpointsthatgrow
outwardswithtimebutformageneralpearshape.
Theplotin3Dformsapearshapewhenrotated
1 aboutthex1axis.Whenasecondtrajectoryis
(21) launchedatadistanceof109fromthisinitial
Wecannowplota( , )inthephasespaceof condition,weseefromfigure2dthattheymove
theinnerpendulumwhenthetwoconditions togetherindicatingthatthereisnochaos.When
0and 0arefulfilled. thelyapunovgraphisplotted,itisclearthatthe
lyapunovexponentisnegative(=3.426)andhence
LargestLyapunovExponent thesystemisnotchaotic.Theangularvelocitiesof
Sensitivedependenceoninitialconditionssmall theinnerandouterbobsareinphaseandperiodic
separationsbetweenarbitrarilycloseinitial furtherconfirmingthattheseinitialconditionsat
conditionsareamplifiedexponentiallyintimeis lowenergyareindicativeofthenonchaotic
thehallmarkofchaos.Theunderlyingcauseofthis regime.
behavior,namelytheexponentialgrowth,canbe
numericallyandanalyticallyevaluatedusing Asweincreasetheenergyto1.2807Jwiththeintial
lyapunovexponents.Largestlyapunov conditionsy0=[0.7,0.3825,0,0],weenterthequasi
exponents11,asiteffectivelygivesusthe periodicregime.Theperiodictrajectoryofthe
informationonthedivergenceoftwoclose outerbobisinfigure3aandweseethattheinner
trajectories.Wecanusethesamefirstorder andtheouterbobareoutofphase(also
equationsusedintheMATLABsimulationto exemplifiedintheangularvelocitiesgraphin3d.
evaluatetheexponent.Themethodtocalculate Figure3eshowsthattwocloselylaunched
thelyapunovexponentistofirstplotthenatural trajectoriesdonotdivergefromeachother.Using
logarithmoftheseparationbetweenthetwo thisdistanceseparation,whenthelyapunovgraph
closelylaunchedtrajectoriesagainsttimeandthen wasgeneratedin3e,weseethatthelyapunov
findtheslopeoftheregionwhereitisincreasing. exponentdoesnotremainentirelynegativeand
Asusual,positivelyapunovexponentsare startstobeginincreasingtopositivevalueswith
indicativeofchaoticbehavior. time.Theaveragelyapunovexponentis1.203
whichishigherthanfortheperiodiccondition.
Otherinformativeplots
Wecanalsoplotthefourvariablesthat Whentheenergyisfurtherincreasedtobe29.4J
characterizethesystemagainsteachothertogeta withinitialconditionsy0=[,,0.5,0].Werepeat
qualitativesenseofthebehaviorofthesystem.Itis thesameprocessandfindaaveragepositive
moredifficulttogaugewhatishappeningwiththe lyapunovexponentof1.906(figure4e).This
dynamicsofthesystemwithsuchplotsbutthey averagenumberwasobtainedbycalculatingthe
arestillindicativeofperiodicversuschaotic averageoverarangeofinitialconditionsaround
behavior. thisy0(figure4f).Weseeinfigure4athatthepath
Nowwehaveallthetoolstolookatsome oftheouterbobisrandomandunpredictable.The
simulationsandseeifthetheoryfitstheobserved Poincaresectionisclearlyareafillingandthetwo
behavior. closelylaunchedtrajectories(withaninitial
separationof109)startofftogetherbutmove
awayfromeachother.Theangularvelocitieswhich Letustakealookatfigure6,thathasother
arequalitativeindicators,alsoshowthatthereisno informativeplotsofthevariablesplottedagainst
regularbehavior.Alloftheseclearlyindicatethatat eachother.Thereisqualitativetrendindicatingthe
theseenergies,thesystemischaotic. systemstartsouttobeperiodic,inthesensethat
theshapeofthecurvescanbepredictedforlater
Sofarwefoundthatasweincreaseenergy,the times,tochaoticunpredictablebehaviorandfinally
systemmovesfrombeingperiodictoquasiperiodic backtoshapesresemblingperiodicity.Ineachof
tochaos.Now,ifweincreasetheenergyevenmore them,thetopleftistheanglesoftheinnerand
toreach104.25Jwithinitialconditionsy0=[,0, outerbob,toprighthastheangularvelocitiesof
0.5,0.5],weseethequasiperiodicstateagain! theinnerandtheouterbob.Bottomandleftand
Clearly,from5dthetrajectorieshavenotdiverged rightshowtheangleversusangularvelocityofthe
fromeachother.Also,thereisadecreaseinthe innerbobandtheouterbobrespectively.
lyapunovexponentto0.4320.Theangular
velocities(figure5c)areoutofphasetogether.The Thegraphsweregeneratedusingthecodes
trajectoryinfigure5aisacertainindicationof PoincareTrajecAngleEnergy.mandcrudelyap.m.
quasiperiodicmotion.AlthoughthePoincare TheyneedHamiltonian.m,doublependulum2.m
sectionsarealittledifficulttounderstand,the andzerocross2.mtowork.Allthecodeisattached
othergraphsareindicativeofquasiperiodic inAppendixB.
behaviorattheseenergies.

AppendixA:Figures
Poincare section (sin(x 2)=0, increasing)
trajectory 0.58
-1.6
b)
a)
-1.7 0.56

-1.8
0.54

-1.9
velocity

0.52

x3
-2
0.5
-2.1

0.48
-2.2

-2.3 0.46

-0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 -0.1 -0.05 0 0.05 0.1
position x1

Poincare section (sin(x 2)=0, increasing) Angular velocities


1.5

d)
c) 1

0.55 0.5
x4

0.5 0

-0.5
0.45

1.2
6 -1
1.1
4
1 2
-1.5
x3 0 1 2 3 4 5 6 7 8 9 10
x1

Trajectories of two intial points with a distance 10-9


-1.93
lyapunov exponent
e) 0
-1.94
-1
f)
-2
-1.95
-3

-1.96 -4

-5
-1.97
-6

-1.98 -7

-8
-1.99
-9

-2 -10
0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10



Figure2:y0=[0.2,0.2828,0,0]producesperiodicmotion.a)Trajectoryoftheouterbob;b)2DPoincaremap
forthesectionwhentheouterbobishangingverticallyi.e2=0;c)3DPoincaremapwhenthepositionofthe
outerbobisatzeroi.esin2=0;d)angularvelocitiesoftheouterandtheinnerbobagainsttime;e)Trajectories
oftwocurvesatadistanceof109betweenthem;f)Illustratesthenegativelyapunovexponent.

Poincare section (sin(x 2)=0, increasing)

trajectory
0.32
b)
-1.8
a) 0.3

0.28
-1.85
0.26
-1.9
0.24
velocity

x3
-1.95
0.22

-2 0.2

-2.05 0.18

0.16
-2.1
0.14
-2.15
-0.25 -0.2 -0.15 -0.1 -0.05 0 0.05 0.1 0.15 0.2 0.25 -0.06 -0.04 -0.02 0 0.02 0.04 0.06
position x1

Poincare section (sin(x 2)=0, increasing) Angular velocities


0.6
d)
c) 0.4

0.3 0.2

0.25 0
x4

0.2
-0.2

0.15
-0.4

-0.2 6 -0.6
-0.4 4
2
-0.6 -0.8
x3 0 0 1 2 3 4 5 6 7 8 9 10
x1

lyapunov exponent
2
Trajectories of two intial points with a distance 10-9 f)
-1.9
1
-1.91 e)
0
-1.92
-1
-1.93

-1.94 -2

-1.95 -3

-1.96
-4
-1.97
-5
-1.98
-6
-1.99

-2 -7
0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10


Figure3:y0=[0.2,0.2828,0,0]producesquasiperiodicmotion.a)Trajectoryoftheouterbob;b)2DPoincare
mapforthesectionwhentheouterbobishangingverticallyi.e2=0;c)3DPoincaremapwhentheposition
oftheouterbobisatzeroi.esin2=0;d)angularvelocitiesoftheouterandtheinnerbobagainsttime;e)
Trajectoriesoftwocurvesatadistanceof109betweenthem;f)slowlyincreasinglyapunovexponent.

trajectory Poincare section (sin(x 2)=0, increasing)
2

a) b)
1.5

1 0

0.5 -10
velocity

-20

x4
0
-30
-0.5
-40

-1
30
20 6
-1.5
10 4
0
2
-10
-2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 0
x3 x1
position

Trajectories of two intial points with a distance 10-9


Angular velocities
2
10
d)
8 c) 1.5

6
1
4
0.5
2

0 0

-2 -0.5

-4
-1
-6
-1.5
-8

-10 -2
0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10

lyapunov exponent
22
e)
20 average lyapunov exponent
2.5

18 f)
2
16

14 1.5

12
1

10
0.5
8

0
6

4 -0.5
0 1 2 3 4 5 6 7 8 9 10 0 10 20 30 40 50 60 70 80 90 100


Figure4:y0=[,,0.5,0]produceschaos!a)Trajectoryoftheouterbob;b)2DPoincaremapforthesection
whentheouterbobishangingverticallyi.e2=0;c)angularvelocitiesoftheouterandtheinnerbobagainst
time;d)Trajectoriesoftwocurvesatadistanceof109betweenthem;e)positivelyapunovexponent;f)
averagelyapunovexponentforvariousinitialconditions.

trajectory
Poincare section (sin(x 2)=0, increasing)

a) b)
1.5
0

-10
0.5
v elocity

0 -20

x3
-0.5
-30

-1
-40
-1.5

-50
-2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 -500 -400 -300 -200 -100 0
position x1

Angular velocities
3.5 Trajectories of two intial points with a distance 10- 9
2
c)
3
d)
1.5
2.5

2 1

1.5 0.5

1
0
0.5
-0.5
0
-1
-0.5

-1 -1.5

-1.5 -2
0 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 12 14 16 18 20


lyapunov exponent
8 average lyapunov exponent
1.2
e) f)
6
1

4 0.8

0.6
2

0.4
0
0.2

-2
0

-4 -0.2
0 1 2 3 4 5 6 7 8 9 10 0 10 20 30 40 50 60 70 80 90 100
1

Figure5:y0=[,0,0.5,0.5]producesquasiperiodicmotion.a)Trajectoryoftheouterbob;b)2DPoincaremap
forthesectionwhentheouterbobishangingverticallyi.e2=0;c)angularvelocitiesoftheouterandthe
innerbobagainsttime;d)Trajectoriesoftwocurvesatadistanceof109betweenthem;e)slightlypositive
lyapunovexponent;f)averagelyapunovexponentforvariousinitialconditions.



angles angular velocities angles angular velocities
0.4 0.2 0.4 0.2

0.2 0.1 0.2 0.1

0 0 0 0

-0.2 -0.1 -0.2 -0.1

-0.4 -0.2 -0.4 -0.2


-0.4 -0.2 0 0.2 0.4 -0.4 -0.2 0 0.2 0.4 -0.2 -0.1 0 0.1 0.2 -0.2 -0.1 0 0.1 0.2

positions and momentum of 1 positions and momentum of 1 positions and momentum of 1 positions and momentum of 1
0.4 0.2 0.2 0.2

0.2 0.1 0.1 0.1

0 0 0 0

-0.2 -0.1 -0.1 -0.1

-0.4 -0.2 -0.2 -0.2


-0.4 -0.2 0 0.2 0.4 -0.4 -0.2 0 0.2 0.4 -0.2 -0.1 0 0.1 0.2 -0.4 -0.2 0 0.2 0.4


angles angular velocities
15 2
angles angular velocities
600 15
10 1

5 0 400 10

0 -1 200 5

-5 -2
0 5 10 15 20 0 1 2 3 4 0 0
0 20 40 60 -5 0 5 10
positions and momentum of 1 positions and momentum of 1
4 2 positions and momentum of 1 positions and momentum of 1
10 15

3 1
5 10
2 0

0 5
1 -1

0 -2 -5 0
0 5 10 15 20 -5 0 5 10 15 0 20 40 60 0 200 400 600

Figure6:Ineachsquare,thetopleftistheanglesoftheinnerandouterbob,toprighthastheangularvelocitiesofthe
innerandtheouterbob.Bottomandleftandrightshowtheangleversusangularvelocityoftheinnerbobandtheouter
bobrespectively.Thetopleftsquareshowsperiodicbehavior,thetoprightsquareindicatesquasiperiodicakaalmost
periodicbehavior,thebottomleftsquarehasthechaoticsystemdepictedandthebottomrightsquarestartstohaving
resemblancestoperiodicbehavior.

AppendixB:MATLABcodes

Animationofthependulum

doublependulumAnimation.m
% modified from http://math.la.asu.edu/~kawski/MATLAB/matlab.html
%comments by Roja

function out=dpend()
if nargin < 5
n=3;
end
%declare variables
global m1 m2 L1 L2 g;
m1 = 2;
m2 = 1;
g = 1;
L1 = 1;
L2 = sqrt(3);
dt = 0.1;
y0 = [-pi 0 -pi 2*rand(1,1)-1];
t0 = 0;
twin=30;
r1 = (L1+L2)/20*sqrt(m1/(m1+m2));
r2 = (L1+L2)/20*sqrt(m2/(m1+m2));
%size the animation window
LL = 1.2 * ( L1 + L2 );
% re-use data while disk is being plotted
bx = cos(pi*[0:0.1:2]);
by = sin(pi*[0:0.1:2]);

% initial positions (delete previous images later)


x1= L1*sin(y0(1));
y1=-L1*cos(y0(1));
x2=x1+L2*sin(y0(3));
y2=y1-L2*cos(y0(3));
b4=plot([0,x1],[0,y1],'k-','LineWidth',2);
hold on
b3=plot([x1,x2],[y1,y2],'k-','LineWidth',2);
b1=fill(x1+r1*bx,y1+r1*by,'magenta');
b2=fill(x2+r2*bx,y2+r2*by,'black');
% scale the window to fit the double pendulum
axis([-LL LL -LL LL])

for N=[1:1000]
% save the old angles and positions
posold=[x1 y1 x2 y2]';
yold=y0;
% solve the systems of odes until next frame
[t,y]=ode45('doublependulum2',[t0,t0+dt],y0,[],9.8,1,1,1,1);
% keep the new angles and delete the old ones
y0=y(size(y,1),:);
clear y
clear t
% translate angles into [-pi,pi]
y0(1)=mod(y0(1)+pi,2*pi)-pi;
y0(3)=mod(y0(3)+pi,2*pi)-pi;
t0=t0+dt;

% delete the old pictures of the pendulum


% calculate the new positions
x1 = L1*sin(y0(1));
y1 = - L1*cos(y0(1));
x2 = x1 + L2*sin(y0(3));
y2 = y1 - L2*cos(y0(3));
% plot the path of the pendulumsin last time interval (overlay)
plot([posold(1) x1],[posold(2) y1],'magenta');
plot([posold(3) x2],[posold(4) y2],'black');
% plot the images of the pendulums at new positions (overlay)
set(b4,'xdata',[0,x1],'ydata',[0,y1]);
set(b3,'xdata',[x1,x2],'ydata',[y1,y2]);
set(b1,'xdata',x1+r1*bx,'ydata',y1+r1*by);
set(b2,'xdata',x2+r2*bx,'ydata',y2+r2*by);
drawnow
pause(0.01)
end

figure(myfig);
pause
close(myfig)

Systemofequations
Doublependulum2.m
%define a function that calculates the dynamics of the double pendulum
%flag determines initial positions and velocities of the inner and outer
%bob. Equations 14 to 17
function xprime=doublependulum2(t,x,flag,g,l1,l2,m1,m2)
xprime=zeros(4,1);
xprime(1) = 6*(2*x(3)-3*cos(x(1)-x(2))*x(4))/(16-9*cos(x(1)-x(2))^2);
xprime(2) = 6*(8*x(4)-3*cos(x(1)-x(2))*x(3))/(16-9*cos(x(1)-x(2))^2);
xprime(3) = -(xprime(1)*xprime(2)*sin(x(1)-x(2))+3*g*sin(x(1)))/2;
xprime(4) = -(-xprime(1)*xprime(2)*sin(x(1)-x(2))+g*sin(x(2)))/2;
end

CalculatingEnergyofthefunction
Hamiltonian.m

%function to calculate energy using equation 20


function energy = hamiltonian(y0)
t1 = y0(1);
t2 = y0(2);
v1 = y0(3);
v2 = y0(4);
g = 9.8;
energy = abs(((3*(v2^2)-2*v1*v2*cos(t1-t2))/(2+2*(sin(t1-t2)^2)))-2*g*cos(t1)-
g*cos(t2));
end

DefiningtheconstantsurfaceforthePoincaresection
Zerocross2.m

function [v,ist,df] = zerocross2(t,x,varargin)% varargin absorbs unwanted


parameters flag,g,l1, etc
% event function for test_poincare.m

v = sin(x(2)); % event is x(2)=0 (ie when v is zero)


%v = x(2);
ist = 1; % if true, terminate evolution when this event occurs
df = 1; % increasing sense only


Producingthetrajectoryoftheouterbob,Poincaresection,angularvelocitygraphandenergyofthesystem
PoincareTrajecAngleEnergy.m

clear
%Code mainly adapted from Alexander Barnett
%declare time step
T = 10;
%y0 = [0;0;-2;0]; % close to regular
%y0 = [pi;pi;0;0];
% y0 = [pi;pi;.5;0]; % chaotic
% y0=[0.5233;0;0.5233;0]%periodic
y0 = [0.2,0.2828,0,0]%perfect periodic with energy = 0.7809
%y0 = [0.2,-0.2828,0,0]%perfect quasiperiodic with energy = 0.7809
%y0 = [27.8;0;1.22;2.62] %perfect KAM scenario
%y0 = [0,0,2,20]
%y0 = [0,0,1,20];
y0 =[pi;0;.5;.5];%high energy

s=ode45(@doublependulum2,[0,T],y0,[],0,1,1,1,1);
t = 0:0.01:T; x = deval(s,t)';
x1=sin(x(:,1));
y1=-cos(x(:,1));
x2=x1+sin(x(:,2));
y2=y1-cos(x(:,2));

figure; plot(x2,y2); axis equal; xlabel('position');ylabel('velocity');title


('trajectory')
tmax = 1e2; % max time to wait until next intersection
ns = 1000; % how many intersection (iterations of P map)

tp = nan*(1:ns); yp = nan*zeros(numel(y0),ns); yi = y0; % init arrays


figure;
for n=1:ns
s = ode45(@doublependulum2, [0, tmax], yi,
odeset('Events',@zerocross2,'abstol',1e-9),0,9.8,1,1,1,1);
if isempty(s.xe), disp('no intersection found!');
else tp(n) = s.xe(end); yi = s.ye(:,end); yp(:,n) = yi;
%plot3(mod(yi(1),2*pi),yi(3),yi(4),'+'); hold on; if mod(n,10)==0, drawnow; end
% note it's in 3d now
plot(yi(1),yi(4));hold on; if mod(n,10)==0, drawnow; end
end
end
xlabel('x_1'); ylabel('x_3'); zlabel('x_4'); axis vis3d;
title('Poincare section (sin(x_2)=0, increasing)');

figure;
plot(t,x(:,3),'magenta',t,x(:,4),'black');title('Angular velocities');
energy = hamiltonian(y0)

Calculatesthelyapunovexponent,theaveragelyapunovexponentandtracestheseparationofclosetrajectories
Crudelyap.m

clear
nruns =100;
%for calculating average later
h = zeros(1,nruns);
%indexing of h
k = 1;
for j=1:nruns
% y0 = [pi+0.1*rand(1);pi;.5;0];
% y0 = [0+0.1*rand(1);0;-2;0];

%y0 = [pi;pi;10.515;-2.17];%periodic with T = 0.5


%y0 = [];%quasiperiodic;
y0 = [pi+0.1*rand(1);pi;0.5;0];%chaotic
%y0 = [pi;pi;0;0];
%y0 = [0;0;-2;0];%close to regular
%y0 = [27.8;0;1.22;2.62];
%y0 = [pi;0;0.5;0.5];
%y0 = [0;0;2;20];

%y0 = [pi;0;5;5];%high energy


%y0 = [0.2;0.2828;0;0];%perfect periodic with energy = 0.7809
%y0 = [0.2+0.1*rand(1);-0.2828;0;0];
%y0 = [0.2;-0.2828;0;0];%perfect quasiperiodic with energy = 0.7809
T = 20;

o = odeset('abstol',1e-14);
s=ode45(@doublependulum2,[0,T],y0,o,0,1,1,1,1); % note changes
eps = 1e-9;
s2 = ode45(@doublependulum2,[0,T],y0+[eps;0;0;0],o,0,1,1,1,1); % note changes
t = 0:0.01:T; x = deval(s,t)';xe = deval(s2,t)';

x1=sin(x(:,1));
y1=-cos(x(:,1));
x2=x1+sin(x(:,2));
y2=y1-cos(x(:,2));
xe1 = sin(xe(:,1));
ye1=-cos(xe(:,1));
xe2 = xe1+sin(xe(:,2));
ye2= ye1-cos(xe(:,2));
%store the size
N = numel(ye2);

%figure; plot(t, [y2 ye2], '-');title('Trajectories of two intial points with a


distance 10^-9')
logsep = zeros(1,N);
%loop fills matrix logsep with natural log of the changing separation
%between the initial trajectories
for i = 1:N
logsep(i) = (log(abs(y2(i)-ye2(i)))-log(eps));
end
%figure; plot(t,logsep);title('lyapunov exponent');
t1=5;
t2=0.7;
%stores the exponent in a matric
h(k) = (logsep(t1/0.01)-logsep(t2/0.01))/(t1-t2);
k=k+1;
end
figure;
%average lyapunov exponent
plot(1:j,h)
title('average lyapunov exponent');

Graphscorrespondingtotheotherinformativegraphssectionsoftheinputvariablesplottedagainsteachother
Equilibria.m

clear
T = 10;
%y0 = [0;0;0;10]; %really good
%y0 = [pi;pi;0.5;0];
%y0 = [0;0;-2;0];
%y0=[0;0;2;20];
%y0 = [27.8;0;1.22;2.62] %perfect KAM scenario
y0 = [0.2,-0.2828,0,0];
y0 = [pi;0;.5;.5]
%y0 = [pi;pi;0.5;0]
s=ode45(@doublependulum2,[0,T],y0,[],0,1,1,1,1);
t = 0:0.01:T; x = deval(s,t)';
%find energy for the inital conditions
energy = hamiltonian(y0)

%creates a plot with four figures of the variables plotted against each
%other
figure;
subplot(222)
plot(x(:,3),x(:,4));title('angular velocities')
subplot(221)
plot(x(:,1),x(:,2));title('angles')
subplot(223)
plot(x(:,1),x(:,3));title('positions and momentum of 1')
subplot(224)
plot(x(:,2),x(:,4));title('positions and momentum of 1')

EndnotesandReferences

1
Heyl,JeremyS."TheDoublePendulumFractal."DepartmentofPhysicsandAstronomy.UniversityofBritishColumbia,11
Aug.2008.Web.4Dec.2009.<http://tabitha.phas.ubc.ca/wiki/images/archive/3/37/20080811183757!Double.pdf>.
2
"DoublePendulumExercises."Areyousureyouwanttolookatthis?Web.04Dec.2009.
<http://pages.physics.cornell.edu/~myers/teaching/ComputationalMethods/ComputerExercises/DoublePendulum/double
pendulum.html>.
3
Haar,D.Ter.ElementsofHamiltonianMechanics(InternationalSeriesonNuclearEnergy).NewYork:PergamonPr,1971.
Print.
4
http://scienceworld.wolfram.com/physics/DoublePendulum.html
5
"DoublePendulumfromEricWeisstein'sWorldofPhysics."ScienceWorld.Web.04Dec.2009.
<http://scienceworld.wolfram.com/physics/DoublePendulum.html>.
6
Stachowiak,Tomasz,andToshioOkada."Anumericalanalysisofchaosinthedoublependulum."ScienceDirect(2006).
Chaos,solitionsandFractals.Www.elsevier.com/locate/chaos,10Aug.2005.Web.4Dec.2009.
<http://www.sciencedirect.com/science?_ob=MImg&_imagekey=B6TJ44H7T0J76
W&_cdi=5300&_user=4257664&_orig=search&_coverDate=07%2F31%2F2006&_sk=999709997&view=c&wchp=dGLbVlb
zSkWz&_valck=1&md5=ec827bbbd88de6e08e02922a969c6ca0&ie=/sdarticle.pdf>.
7
Poschel,Jurgen."ClassicalKAMTheorem."Lecture.Publikationen.Proc.Symp.PureMath,Dec.2000.Web.4Dec.2009.
<http://www.poschel.de/pbl/kam1.pdf>.
8
Barnett,Alexander."Usingode45forpoincaresection."Messagetotheauthor.29Nov.2009.Email.
9
Rafat,M.Z.,M.S.Wheatland,andT.R.Bedding."Dynamicsofadoublependulumwithdistributedmass."American
JournalofPhsyics(2006).UniversityofSydney,2006.Web.4Dec.2009.
<http://www.physics.usyd.edu.au/~wheat/preprints/DynamicsDoublePendulum.pdf>.

10
Chaos:AProgramCollectionforthePCByH.J.Korsch,HansJrgJodl,T.Hartmann,Pg.91

11
Rafat,M.Z.,M.S.Wheatland,andT.R.Bedding."Dynamicsofadoublependulumwithdistributedmass."American
JournalofPhsyics(2006).UniversityofSydney,2006.Web.4Dec.2009.
<http://www.physics.usyd.edu.au/~wheat/preprints/DynamicsDoublePendulum.pdf>.

Anda mungkin juga menyukai