hgrie's private definitions

Plot options

red=RGBColor[1,0,0];
green=darkgreen;(*RGBColor[0,1,0];*)
darkgreen=CMYKColor[1,0,1,.5];
blue=RGBColor[0,0,1];
darkblue= CMYKColor[1,1,0,.3];
violet=RGBColor[.6,0,1];
white=RGBColor[1,1,1];
black=RGBColor[0,0,0];
fillcolour=RGBColor[0.572549, 0.564706, 1];
grey=GrayLevel[.85];
slidegrey=GrayLevel[.6];
solid=Dashing[{1,0}]; (*solid*)
dotdashed=Dashing[{0.005,0.02,0.02,0.02}]; (*dot-dashed*)
middashed=Dashing[{0.02,0.02}];(*mid dashed*)
longdashed=Dashing[{0.04,0.02}]; (*long dashed*)
dashed=middashed; (* CHOOSE DASHING!!!!!*)
dotted=Dashing[{0.003,0.015}]; (*dotted*)
axes=None;
imagesize=Automatic;

figimagesizeexp={290,200};
figimagesize={400*12.5/14.1*10.7/10.6,400/GoldenRatio};
figimagesize2=1.5{400*12.5/14.1*10.7/10.6,400/GoldenRatio};
figimagesizeArray2=1.5 {2*357.9553057674295`,(400/GoldenRatio)};
figimagesizeArray3=1.5 {3*357.9553057674295`,(400/GoldenRatio)};
plotoptions={
Background->white,
Frame->True,
Prolog->AbsoluteThickness[1],
ImageSize-> figimagesize};

define correct ticks for θ ∈[0;180] degree

thetatableprelim=Table[{i,"",{3/900,0}},{i,0,180,5}];
thetatablenumbers=Table[{i,StringForm["``",i],{6/900,0}},{i,0,180,30}];
thetatablenonumbers=Table[{i,"",{6/900,0}},{i,0,180,30}];
thetatableup=Union[
Delete[thetatableprelim,Table[{i},{i,1,Dimensions[thetatableprelim][[1]],6}]],
thetatablenonumbers];
thetatabledown=Union[
Delete[thetatableprelim,Table[{i},{i,1,Dimensions[thetatableprelim][[1]],6}]],
thetatablenumbers];

Plot Options which depend on the math..ematica version

math 6 and higher does not know any more about "DisplayTogether" and other stuff (curse Wolfram)

Most noticable: 
The plot options "MaxRecursion -> 0" and "PerformanceGoal -> "Speed"" dramatically increas the speed with which plots are rendered -- without a real loss of accuracy in the plots!!
Thus: use "plotoptions" for thorough plots, and "prelimplotoptions" for quick plots.

Append[plotoptions,BaseStyle->{FontFamily->"Times",Italic}];
prelimplotoptions=Append[plotoptions,PerformanceGoal->"Speed"];
Append[prelimplotoptions,MaxRecursion->0];
circle[colour_,thickness_]:=Graphics/@{{colour,thickness,Circle[{0,0},1]}}
disk[colour_]:=Graphics/@{{colour,Disk[{0,0},1]}}
emptytriangle[colour_,thickness_]:=Graphics/@{{colour,thickness,Line[{{1,0},{0,Sqrt[3]},{-1,0},{1,0}}]}}
filledtriangle[colour_]:=Graphics/@{{colour,Polygon[{{1,0},{0,Sqrt[3]},{-1,0}}]}}
emptysquare[colour_,thickness_]:=Graphics/@{{colour,thickness,Line[{{-0.5,-0.5},{0.5,-0.5},{0.5,0.5},{-0.5,0.5},{-0.5,-0.5}}]}}
filledsquare[colour_]:=Graphics/@{{colour,Polygon[{{-0.5,-0.5},{0.5,-0.5},{0.5,0.5},{-0.5,0.5}}]}}
emptydiamond[colour_,thickness_]:=Graphics/@{{colour,thickness,Rotate[Line[{{-0.5,-0.5},{0.5,-0.5},{0.5,0.5},{-0.5,0.5},{-0.5,-0.5}}],45 Degree,{0,0}]}}
filleddiamond[colour_]:=Graphics/@{{colour,Rotate[Polygon[{{-0.5,-0.5},{0.5,-0.5},{0.5,0.5},{-0.5,0.5}}],45 Degree,{0,0}]}}

Perturbative Solution of the Pendulum etc., see "Approximations" chapter pp.21ff

Re-scale time in units of ω0=(g/l)^(1/2) ≡ 2 π, 
i.e. t=1 corresponds to _one_ cycle/orbit.

Exact and approximate solutions

LO solution (note: LO frequency!)

approximateLO[t_,amplitude_]=amplitude Cos[2π t]

NLO solution (note: LO frequency in _all_ terms!)

approximateNLO[ϵ_,t_,amplitude_]=amplitude Cos[(1-ϵ 3amplitude^2/4)^(1/2)2π t]+ϵ amplitude^3/32(Cos[(1-ϵ 3amplitude^2/4)^(1/2)2π t]-Cos[3(1-ϵ 3amplitude^2/4)^(1/2)2π t])

Solution to the pendulum, ϵ=1/6:

exact[ϵ_,tmax_,amplitude_]:=ϕ[t]/.NDSolve[{D[ϕ[t],{t,2}]+(2π )^2Sin[ϕ[t]]==0,ϕ[0]==amplitude,ϕ'[0]==0},ϕ[t],{t,0,tmax}][[1]]

Compare ϕ(t)

Compare -- you can play with the parameters.

{ϵ=1/6,tmax=4,amplitude=1};
Print[StringForm["expansion parameter ϵ: ``; amplitude: ``; max. time tmax: `` → rel. frequency at NLO: ``",ϵ,tmax,amplitude,N[(1-ϵ 3amplitude^2/4)^(1/2)]]]
Print["Left: ϕ(t); Right: relative deviation 1-ϕ(t)/ϕexact(t). Red solid: exact; green dotted: LO; blue dashed: NLO"]
exact[t_]=exact[ϵ,tmax,amplitude];
GraphicsGrid[{{Plot[{approximateLO[t,amplitude],approximateNLO[ϵ,t,amplitude],exact[t]},{t,0,tmax},Evaluate[plotoptions],PlotStyle->{{dotted,green},{dashed,blue},{solid, red}},FrameLabel->{"t [2π(l/g)^(1/2)]","ϕ(t)",StringForm["ϵ=``, A=``, ωrel(NLO)=``",ϵ,amplitude,N[(1-ϵ 3amplitude^2/4)^(1/2)]]}],
Plot[{1-approximateLO[t,amplitude]/exact[t],1-approximateNLO[ϵ,t,amplitude]/exact[t]},{t,0,tmax},Evaluate[plotoptions],PlotStyle->{{dotted,green},{dashed,blue},{solid, red}},FrameLabel->{"t [2π(l/g)^(1/2)]","1-ϕ(t)/ϕexact(t)",StringForm["ϵ=``, A=``, ωrel(NLO)=``",ϵ,amplitude,N[(1-ϵ 3amplitude^2/4)^(1/2)]]}]
}}]
Clear[ϵ,tmax,amplitude]

Compare exact and aproximate frequencies:

Print[StringForm["expansion parameter ϵ: ``",ϵ=1/6]]
Print["Left: ω(A); Right: relative deviation 1-ω(A)/ωexact(A). Red solid: exact; green dotted: LO; blue dashed: NLO"]
exactω[amplitude_]:=2π/NIntegrate[(2/(Cos[ϕ]-Cos[amplitude]))^(1/2),{ϕ,-amplitude,amplitude}]
approximateωLO[amplitude_]:=1
approximateωNLO[ϵ_,amplitude_]:=(1-ϵ 3amplitude^2/4)^(1/2)
GraphicsGrid[{{
Plot[{approximateωLO[amplitude],approximateωNLO[ϵ,amplitude],exactω[amplitude]},{amplitude,0.01,2},Evaluate[plotoptions],PlotStyle->{{dotted,green},{dashed,blue},{solid, red}},FrameLabel->{"amplitude","ω [(g/l)^(1/2)]",StringForm["ϵ=``",ϵ]}],
Plot[{1-approximateωLO[amplitude]/exactω[amplitude],1-approximateωNLO[ϵ,amplitude]/exactω[amplitude]},{amplitude,0.01,2},Evaluate[plotoptions],PlotStyle->{{dotted,green},{dashed,blue},{solid, red}},FrameLabel->{"amplitude","1-ω/ωexact",StringForm["ϵ=``",ϵ]}]
}}]
Clear[ϵ]