Advertisement
tomdodd4598

Untitled

Apr 24th, 2021
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. {m,M,l,L,g}={1,1,1,1,10};
  2. x1=l Sin[\[Theta][t]];
  3. y1=-l Cos[\[Theta][t]];
  4. x2=l Sin[\[Theta][t]]+L Sin[\[Theta][t]+\[Alpha][t]];
  5. y2=-l Cos[\[Theta][t]]-L Cos[\[Theta][t]+\[Alpha][t]];
  6. \[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;
  7. time=60;
  8. Needs["VariationalMethods`"]
  9. eqs=EulerEquations[\[ScriptCapitalL],{\[Theta][t],\[Alpha][t]},t];
  10. s=NDSolve[{eqs,\[Theta][0]==Pi/4,\[Alpha][0]==Pi/8,\[Theta]'[0]==0,\[Alpha]'[0]==0},{\[Theta],\[Alpha]},{t,0,time}]
  11.  
  12. "Double Pendulum Motion:"
  13. 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}];
  14. 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