Quick guide to Mathematica

To get help, place the cursor on the function and press F1
To run all commands in one cell, place the cursor there and press Shift + Enter or Enter on the numerical keyboard.
Output of many commands is suppressed by ; at the end of the command. If you want to see the output, delete ;
Argument of functions must be in square brackets [...], braces {...} are for arrays, ranges etc., use double brackets [[...]] to access elements of arrays
expr /. {x -> a} means substitute a for x in expr, expr // function means apply function to expr, i.e. it is equivalent to function[expr].
D[f[x],x] = derivative of f[x] with respect to x.
To define a function of x one can use f[x_] := 1+(x^2), notice the underscore and the colon, or # nad & like in f := 1+((#)^2) &
N[expr] evaluates expr with machine precision, if you use the decimal point in the expression it will be also evaluated with machine precision
Special characters can be inserted by pressing Esc ... Esc, e.g. Esc p Esc gives π
Clear[...] is used to unset any variables which could have been assigned previously.
Some other useful commands: Simplify, Expand, Factor; Integrate, Series, Sum

Clear all symbols from previous evaluations to avoid problems

Clear["Global`*"]

Numerical solution of differential equation of physical pendulum

Solution using Mathematica built-in function from Wolfram Demonstration Project

Manipulate[
Module[{run,sol,z,app,a},
If[run==10,run=0];
sol=DSolve[{y''[x]+(9.8/l)*y[x]==0,y[0]==int,y'[0]==0},y,x];
z[x_]:=y[x]/.sol;
app=NDSolve[{θ1''[t]+(9.8/l)*Sin[θ1[t]]==0,θ1[0]==int,θ1'[0]==0},θ1,{t,0,10}];
a[t_]:=θ1[t]/.First[app];
Grid[{{
Graphics[{
{Thick,Line[{{0,0},{l*Sin[a[r]],-l*Cos[a[r]]}}]},
{Darker[Red],Disk[{0,0},.03]},
{Blue,Disk[{l*Sin[a[r]],-l*Cos[a[r]]},0.1(((30m)/(4π))^(1/3))]}},
PlotRange->{{-3.4,3.4},{3.4,-3.4}},ImageSize->{250,250}],Plot[{a[t],z[t]},{t,0,10},PlotRange->{{0,10},{-3.2,3.2}},PlotStyle->{{Thick,Blue},{Red}},ImageSize->{250,250},AspectRatio->1.2,Frame->True, PlotLegends->{"numerical","sin(θ) = θ"},FrameLabel->{"time","displacement"},Epilog->{Blue,PointSize[.06],Point[{r,a[r]}]}]}}]],
{{int,π/2,"initial angle θ(0)"},0,π,0.01,Appearance->"Labeled"},
Delimiter,
{{m,4,"mass m"},1,10,.01,Appearance->"Labeled"},
{{l,2.25,"length L"},1,3,.01,Appearance->"Labeled"},{{r,0,"release system"},0,10,.01,ControlType->Trigger,AnimationRate->.5},
TrackedSymbols:>{int,m,l,r}]

A black box solution using Mathematica

ϵ=0.0001;
T=100.0;
s1=NDSolve[{y''[x]+ Sin[y[x]]==0,y[0]==π+ϵ,y'[0]==0},y,{x,0,T}];
s2=NDSolve[{y''[x]+ Sin[y[x]]==0,y[0]==π-ϵ,y'[0]==0},y,{x,0,T}];
p1=Plot[{Evaluate[{y[x]}/.s1],Evaluate[{y'[x]}/.s1]},{x,0,T},PlotStyle->{Blue,Orange}];
p2=Plot[{Evaluate[{y[x]}/.s2],Evaluate[{y'[x]}/.s2]},{x,0,T},PlotStyle->{Green,Red}];
GraphicsRow[{p1,p2},ImageSize->Full]

Solution using the Euler method

(v^(n+1))=(v^n)+k f((v^n),(Subscript[t, n]))

order=1;
MyGetLMMCoefficients["Adams-Bashforth",order];
f[u_,t_]:={u[[2]],-Sin[u[[1]]]};
ϵ=0.1;
t0=0.0;
T=100.0;
k=0.01;
n=IntegerPart[T/k];
Print["ϵ = ",ϵ,", k = ",k,", n = ", n];
mydata1=MyODESolveUsingLMM[MyGetLMMCoefficients["Adams-Bashforth",order], f, t0, {{π+ϵ,0}}, k, n];
mydata2=MyODESolveUsingLMM[MyGetLMMCoefficients["Adams-Bashforth",order], f, t0, {{π-ϵ,0}}, k, n];
p1=ListPlot[{Part[Map[Flatten,mydata1],All,{1,2}],Part[Map[Flatten,mydata1],All,{1,3}]},Joined->False,PlotStyle->{Blue,Orange}];
p2=ListPlot[{Part[Map[Flatten,mydata2],All,{1,2}],Part[Map[Flatten,mydata2],All,{1,3}]},Joined->False,PlotStyle->{Green,Red}];
GraphicsRow[{p1,p2},ImageSize->Full]

Solution using the Runge-Kutta methods

(Subscript[y, s])=(v^n)+k (∑_(j=1)^r)(Subscript[a, sj]) f((Subscript[y, j]),(Subscript[t, n])+(Subscript[c, j]) k)   for   s=1,…,r
(v^(n+1))=(v^n)+k (∑_(j=1)^r)(Subscript[b, j])f((Subscript[y, j]),(Subscript[t, n])+(Subscript[c, j]) k)

order=2; (* here only 2 and 4 is implemented *)
Print["{c, A, b} = ",Map[MatrixForm,MyGetRKCoefficients["Classical",order]]]

order =4;
f[u_,t_]:={u[[2]],-Sin[u[[1]]]};
ϵ=0.0001;
t0=0.0;
T=100.0;
k=0.01;
n=IntegerPart[T/k];
Print["ϵ = ",ϵ,", k = ",k,", n = ", n];
mydata1=MyODESolveUsingRK[MyGetRKCoefficients["Classical",order],f,t0,{π+ϵ,0},k,n];
mydata2=MyODESolveUsingRK[MyGetRKCoefficients["Classical",order],f,t0,{π-ϵ,0},k,n];
p1=ListPlot[{Part[Map[Flatten,mydata1],All,{1,2}],Part[Map[Flatten,mydata1],All,{1,3}]},Joined->False,PlotStyle->{Blue,Orange}];
p2=ListPlot[{Part[Map[Flatten,mydata2],All,{1,2}],Part[Map[Flatten,mydata2],All,{1,3}]},Joined->False,PlotStyle->{Green,Red}];
GraphicsRow[{p1,p2},ImageSize->Full]

Solution using the linear multistep method

(∑_(j=0)^s)(Subscript[α, j])(v^(n+j))=k (∑_(j=0)^s)(Subscript[β, j])f((v^(n+j)),(Subscript[t, n+j]))

order=4; (* here only 2 and 4 works due to initialization using the Runge-Kutta method *)
Print["{α,β} = ",MyGetLMMCoefficients["Adams-Bashforth",order]]

f[u_,t_]:={u[[2]],-Sin[u[[1]]]};
ϵ=0.0001;
t0=0.0;
T=100.0;
k=0.01;
n=IntegerPart[T/k];
Print["ϵ = ",ϵ,", k = ",k,", n = ", n];
(* Initialization using the Runge-Kutta method of the same order *)
u0=MyODESolveUsingRK[MyGetRKCoefficients["Classical",order],f,t0,{π+ϵ,0},k,order-1];
mydata1=MyODESolveUsingLMM[MyGetLMMCoefficients["Adams-Bashforth",order], f, t0, u0[[All,2]], k, n];
(* Initialization using the Runge-Kutta method of the same order *)
u0=MyODESolveUsingRK[MyGetRKCoefficients["Classical",order],f,t0,{π-ϵ,0},k,order-1];
mydata2=MyODESolveUsingLMM[MyGetLMMCoefficients["Adams-Bashforth",order], f, t0, u0[[All,2]], k, n];
p1=ListPlot[{Part[Map[Flatten,mydata1],All,{1,2}],Part[Map[Flatten,mydata1],All,{1,3}]},Joined->False,PlotStyle->{Blue,Orange}];
p2=ListPlot[{Part[Map[Flatten,mydata2],All,{1,2}],Part[Map[Flatten,mydata2],All,{1,3}]},Joined->False,PlotStyle->{Green,Red}];
GraphicsRow[{p1,p2},ImageSize->Full]