Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {m,M,l,L,g}={1,1,1,1,10};
- x1=l Sin[\[Theta][t]];
- y1=-l Cos[\[Theta][t]];
- x2=l Sin[\[Theta][t]]+L Sin[\[Theta][t]+\[Alpha][t]];
- y2=-l Cos[\[Theta][t]]-L Cos[\[Theta][t]+\[Alpha][t]];
- \[ScriptCapitalL]=(m/2)(D[x1,t]^2+D[y1,t]^2)+(M/2)(D[x2,t]^2+D[y2,t]^2)-m g y1-M g y2;
- time=60;
- Needs["VariationalMethods`"]
- eqs=EulerEquations[\[ScriptCapitalL],{\[Theta][t],\[Alpha][t]},t];
- s=NDSolve[{eqs,\[Theta][0]==Pi/4,\[Alpha][0]==Pi/8,\[Theta]'[0]==0,\[Alpha]'[0]==0},{\[Theta],\[Alpha]},{t,0,time}]
- "Double Pendulum Motion:"
- plt=Plot[-l-L-2,{x,-l-L-0.5-M/10,l+L+0.5+M/10},PlotRange->{-l-L-0.5-M/10,l+L+M/10}];
- Animate[Show[plt,Graphics[{Line[{{0,0},{l*Sin[\[Theta][t]],-l*Cos[\[Theta][t]]}}]}],Graphics[{Line[{{l*Sin[\[Theta][t]],-l*Cos[\[Theta][t]]},{l*Sin[\[Theta][t]]+L*Sin[\[Theta][t]+\[Alpha][t]],-l*Cos[\[Theta][t]]-L*Cos[\[Theta][t]+\[Alpha][t]]}}]}],Graphics[{Red,Ball[{l*Sin[\[Theta][t]],-l*Cos[\[Theta][t]]},m/10]}],Graphics[{Red,Ball[{l*Sin[\[Theta][t]]+L*Sin[\[Theta][t]+\[Alpha][t]],-l*Cos[\[Theta][t]]-L*Cos[\[Theta][t]+\[Alpha][t]]},M/10]}],AspectRatio->Automatic]/.s,{t,0,time},AnimationRate->1, AnimationRunning->False,RefreshRate->120]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement