Motion of a Simple Pendulum with Damping

f[x_]:=If[x≥Pi,-Pi+(x-Pi),If[x≤-Pi,Pi+(x+Pi),x]];
Evolution2[n_,{x0_,v0_},dt_,k_,d_]:=Module[{flow={},i=0,x=x0,v=v0,tmpx=0,tmpv=0,a=0},
For[i=1,i≤n,
AppendTo[flow,{x,v}];
tmpx=x;
tmpv=v;
a=-k Sin[x]-d v;
v+=a dt;
x+=v dt;x=f[x];
;i++];
flow];

Manipulate[
l=Evolution2[700,{0,v},0.02`,1/e,d];Grid[{{Show[ListPlot[l,PlotRange->{{-π-0.2,π+0.2},{-Abs[v]-0.3,Abs[v]+0.3}},ImageSize->{275,275},AxesLabel->{Style["θ",Bold],Style["ω",Bold]},ImagePadding->25],Graphics[{Red,PointSize[0.03],Point[{l[[a,1]],l[[a,2]]}]}]],Graphics[{{EdgeForm[Thick],Red,Rotate[Disk[{0,0.4`},{0.05`,0.4`}],l[[a,1]]+Pi,{0,0}]},{Blue,PointSize[0.02`],Point[{0,0}]},{Dashed,Pink,Circle[{0,0},0.8`]},{Dashed,Blue,Line[{{-1,0},{1,0}}]}},PlotRange->1,ImageSize->{275,275}]}},Frame->All],
{{a,1,"step"},1,500,1},
{{e,1,"pendulum length"},1,2.5},
{{v,2,"angular velocity"},-10,10},
{{d,0,"damping"},0,1},TrackedSymbols->Manipulate,SaveDefinitions->True]

THIS NOTEBOOK IS THE SOURCE CODE FROM

"Motion of a Simple Pendulum with Damping" from The Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/MotionOfASimplePendulumWithDamping/

Contributed by: Bartosz Naskrecki

A full-function Wolfram Mathematica system (Version 6 or higher) is required to edit this notebook.
GET WOLFRAM MATHEMATICA »

© The Wolfram Demonstrations Project & Contributors   |   Terms of Use   |   Make a new version of this Demonstration »