Mathematical pendulum (conservative system)

Total energy

ωdom=3;
θdom=6.7;
Allenergy=(1/2) ω^2-Cos[θ];
Plot3D[Allenergy,
{ω,-ωdom,ωdom},
{θ,-θdom,θdom},
AxesLabel->{ "Kinetic en. ω","Potential en. θ","Energy E(θ,ω)"},
ColorFunction->"Aquamarine",
MeshFunctions -> {#3&},
BoxRatios->{1,1,1},
PlotRange->{-1.0,3},ClippingStyle->None,LabelStyle->20,ImageSize->Large]

Phase portrait and integrated solution (interactive)

Clear[diffΘ,diffω,Θ,ω]
imagesize=380;maxT=45;

diffΘ=ω;
diffω=-Sin[Θ];
difΘ=ω[t];
difω=-Sin[Θ[t]];

splot=StreamPlot[{diffΘ,diffω},{Θ,-2 π,2 π},{ω,-3,3},FrameLabel->{Θ[t],ω[t]},ImageSize->imagesize,LabelStyle->15];
fixedp=Graphics[{PointSize[0.03],Red,Point[{{-2 π,0},{-π,0},{0,0},{π,0},{2 π,0}}]}];
Manipulate[
integration=NDSolve[{
Θ'[t]==difΘ,
ω'[t]==difω,
Θ[0]==point[[1]],ω[0]==point[[2]]},
{Θ,ω},{t,0,T}];
trajectory=ParametricPlot[
Evaluate[{Θ[t],ω[t]}/.integration],
{t,0,T},PlotStyle->Black];
solx=Plot[
Evaluate[Θ[t]/.integration],
{t,0,T},PlotRange-> All,AxesLabel-> {t,Θ[t]},PlotLabel->"Angle",ImageSize->imagesize,LabelStyle->15,PlotStyle->Black];
soly=Plot[
Evaluate[ω[t]/.integration],
{t,0,T},PlotRange-> All,AxesLabel-> {t,ω[t]},PlotLabel->"Angular velocity",ImageSize->imagesize,LabelStyle->15,PlotStyle->Black];
Grid[{{Show[splot,trajectory,fixedp],soly},{solx}},Frame->All],
{{T,0.5 maxT,"Integration time, t"},1,maxT,Appearance->"Labeled"},
{{point,{-π,0.01}},Locator}, SaveDefinitions->True,TrackedSymbols:>{T,point}]

Phase portrait and periodic boundary

plot=StreamPlot[{y,-Sin[x]},{x,-π,π},{y,-3,3},Frame->None,Epilog->{PointSize->Large,Point[{{0,0},{π,0},{-π,0}}]}];
First[Normal@plot]/.  a_Arrow:>(a/. {x_Real,y_Real}:>{Cos[x],Sin[x],y})//Graphics3D;
Show[%,Graphics3D@{LightGray,Cylinder[{{0,0,-3},{0,0,3}}]},Boxed->False]

Creation of this notebook was supported by IT Academy program of Information Technology Foundation for Education (HITSA).