Dynamical Systems

(Author: Jorge Finke)

Clear All

The damped nonlinear pendulum

The damped nonlinear pendulum

Contributed by: Enrique Zeleny

“The Damped Nonlinear Pendulum” from the Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/TheDampedNonlinearPendulum/

Manipulate[Module[{θ,t,sol},
sol=NDSolve[{θ''[t]+γ θ'[t]+((ω0)^2) Sin[θ[t]]==0,θ[0]==pt[[1]],θ'[0]==pt[[2]]},θ,{t,0,tmax}][[1]];Labeled[Grid[{{Show[If[plottype=="stream",StreamPlot,StreamDensityPlot][{y,- ((ω0)^2)Sin[x]-γ y},{x,-π,π},{y,-1,1},PerformanceGoal->ControlActive["Speed","Quality"],StreamPoints->Coarse,StreamScale->Large],
Quiet@ParametricPlot[Evaluate[{Mod[θ[t],2π,-π],θ'[t]}/.sol],{t,0,tmax},AspectRatio->1,PlotRange->{{-π,π},{-1,1}},Frame->True,PlotStyle->Red,Exclusions->{Evaluate[Abs[Mod[θ[t]/.sol,2π]]]==π},PerformanceGoal->ControlActive["Speed","Quality"]],FrameTicks->{{{-π,-π},{-π/2,"-π/2"},{0,0},{π/2,"π/2"},{π,π}},Automatic,None,None},LabelStyle->Directive["Italic",14],FrameLabel->{{Row[{"θ'(",Style["t",Italic],")"}],None},{Row[{"θ(",Style["t",Italic],")"}],None}},ImageSize->{250,250}],Quiet@Plot[Evaluate[Mod[θ[t]/.sol,2π,-π]],{t,0,tmax},PlotRange->{{0,100},{-π,π}},LabelStyle->Directive["Italic",14],FrameLabel->{{Row[{"θ(",Style["t",Italic],")"}],None},{Style["t",Italic],None}},AspectRatio->1,Frame->True,ImageSize->{250,250},PlotStyle->Blue,Exclusions->{Evaluate[Mod[θ[t]/.sol,2π,-π]]==3.1,Evaluate[Mod[θ[t]/.sol,2π,-π]]==-3.1},FrameTicks->{Automatic,{{-π,-π},{-π/2,"-π/2"},{0,0},{π/2,"π/2"},{π,π}},None,None},Epilog->Inset[Graphics[{Line[{{0,0},{Cos[θ[tmax]-π/2],Sin[θ[tmax]-π/2]}/.sol}],Blue,Point[{0,0}],Red,Point[{Cos[θ[tmax]-π/2],Sin[θ[tmax]-π/2]}/.sol]},PlotRange->1.2,Frame->True,FrameTicks->None],Scaled[{.86,.85}],Automatic,{30,30}]]}}],Text@Row[{"θ(0) = ",NumberForm[pt[[1]],{3,2}],"   θ'(0) = ",NumberForm[pt[[2]],{3,2}]}],Top,LabelStyle->Directive[Bold,14]]],
{{ω0,.9,"(Subscript[ω, 0])"},-1.,1,Appearance->"Labeled"},
{{γ,.3},0,1,Appearance->"Labeled"},
{{pt,{1.25,-.4}},{-π,-1},{π,1},ControlType->Locator},
{{tmax,15.,"t"},1.,100.,Appearance->"Labeled"},
{{plottype,"stream","plot type"},{"stream","density"}},
SynchronousUpdating->False]

Controlling the pendulum

invPendulum=(StateSpaceModel[0, 1, 0, 0, 0, 0, -((g (-m-M))/(l M)), 0, 0, 0, -(1/(l M)), -(1/(l M))-((-m-M)/(l m M)), 0, 0, 0, 1, 0, 0, -((g m)/M), 0, 0, 0, (1/M), 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, ]);

feedbackgains = StateFeedbackGains[invPendulum, {-1+ 5I, -1-5I, -3+I, -3-I}, Method->"Ackermann"]

output=OutputResponse[{SystemsModelStateFeedbackConnect[invPendulum,feedbackgains]/.{M->5.6,m->0.53,l->1.7,g->9.8},{-.03,0,0,0}},{0},{t,4}];

xx[tt_]:=Re[(output[[1]])/.t->tt]
θθ[tt_]:=Re[(output[[2]])/.t->tt]

Animate[Style[{Graphics[{
Translate[{EdgeForm[Thick],{Transparent,Rectangle[{-1.5,0},{6.5,2.5}]},Line[{{1.5,2.5},{2.5,3.5},{3.5,2.5}}],{DotDashed,Line[{{2.5,-1},{2.5,10.5}}]},Arrowheads[Small],Arrow[Table[{-10*Sign[θθ[T]]*Sin[dt]+2.5,10*Cos[dt]},{dt,0,Abs[θθ[T]],Pi/200}],{0,.1}]},{10xx[T] ,0}],
Translate[{Rotate[{EdgeForm[Black],{FaceForm[Transparent],Rectangle[{2.25,2.75},{2.75,9}]}, {DotDashed,Line[{{2.5,3},{2.5,10.5}}]}},θθ[T],{2.5,3}], PointSize[Medium], Point[{2.5, 3}],Point[{2.5, 1.5}]},{10xx[T],0} ],
Translate[Rotate[{{EdgeForm[Thick],White,Disk[]},Line[{{0,1},{0,0}}]},-10xx[T]],{10xx[T] ,0}],
Translate[Rotate[{{EdgeForm[Thick],White,Disk[{5,0}]},Line[{{5,1},{5,0}}]},-10xx[T]],{10xx[T] ,0}] ,
Arrow[{{8, 1.5}, {2.5+10xx[T], 1.5}}],Arrow[{{9, 1.5}, {10, 1.5}}], Line[{{10,10},{10,-1},{-2,-1}}], Text[Style[x,Medium, Blue], {8.5, 1.5}],Text[Style[θ,Medium, Red], {2.8+10xx[T], 9.75}] },PlotRange->{{-5,10},{-2,11}}
],Plot[{If[T>t, xx[t],0],If[T>t, θθ[t],0] }, {t,0,4}, PlotRange->{{0,4},{-.15, .15}},PlotStyle->{Blue,Red},Epilog->Inset[Column[{Style["x(t)",10,Blue],Style["θ(t)",10,Red]}],{3,0.05}],AxesLabel->{"t"}]} ,ImageSizeMultipliers->{1,1}],{T,0,4},AnimationRunning->False ,SaveDefinitions->True]