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["Global`*"] (* unsets all used variables so far *)

Numerical solution of differential equations

Coefficients and local errors of linear multistep methods

{α,β}=MyGetLMMCoefficients["Adams-Bashforth",4]
{ρ[z]=MyPolynomial[α,z],σ[z]=MyPolynomial[β,z]}
{order,errorConstants}=MyOrderOfAccuarcyOfLMM[α,β]

Comparison of several linear multistep and Runge-Kutta methods

Here we solve a scalar linear ODE

((du(t))/(dt))=f(u(t),t)=λ u(t),     u((Subscript[t, 0])=0)=(Subscript[u, 0])

Its solution is

u(t)=(Subscript[u, 0]) (e^(λ(t-(Subscript[t, 0]))))

We use this solution to initialize multistep methods.

λ=-5.0;
f[u_,t_]:={λ u[[1]]};
t0=0.0;
u0=1.0;
T=1.0;
k=0.1;
n=IntegerPart[T/k];
mydataLMM1=MyODESolveUsingLMM[MyGetLMMCoefficients["Euler",1], f, t0, {{u0}}, k, n];
mydataLMM2=MyODESolveUsingLMM[MyGetLMMCoefficients["Adams-Bashforth",2], f, t0, {{u0},{u0 Exp[λ k]}}, k, n];
mydataLMM3=MyODESolveUsingLMM[MyGetLMMCoefficients["Adams-Bashforth",4], f, t0, {{u0},{u0 Exp[λ k]},{u0 Exp[λ 2k]},{u0 Exp[λ 3k]}}, k, n];
mydataLMM4=MyODESolveUsingLMM[MyGetLMMCoefficients["Most Accurate 2-step Explicit",2], f, t0, {{u0},{u0 Exp[λ k]}}, k, n];
ps=0.02;
p1=ListPlot[{Map[Flatten,mydataLMM1],Map[Flatten,mydataLMM2],Map[Flatten,mydataLMM3]},Joined->False,PlotStyle->{{Blue,PointSize[ps]},{Green,PointSize[ps]},{Black,PointSize[ps]}}];
punstable=ListPlot[{Map[Flatten,mydataLMM4]},Joined->True,PlotStyle->{Orange}];

mydataRK1=MyODESolveUsingRK[MyGetRKCoefficients["Classical",1],f,t0,{u0},k,n];
mydataRK2=MyODESolveUsingRK[MyGetRKCoefficients["Classical",2],f,t0,{u0},k,n];
mydataRK3=MyODESolveUsingRK[MyGetRKCoefficients["Classical",4],f,t0,{u0},k,n];
p2=ListPlot[{Part[Map[Flatten,mydataRK1],All,{1,2}],Part[Map[Flatten,mydataRK2],All,{1,2}],Part[Map[Flatten,mydataRK3],All,{1,2}]},Joined->False,PlotStyle->{{Blue,PointSize[ps]},{Green,PointSize[ps]},{Black,PointSize[ps]}}];

pexact=Plot[u0 Exp[λ(t-t0)],{t,t0,T},PlotStyle->Red,AxesOrigin->{0,0},PlotRange->{0.0,1.0}];
GraphicsRow[{Show[{pexact,p1,punstable}],Show[{pexact,p2}]},ImageSize->Full]

Initialization with incorrect values

λ=0.0;
f[u_,t_]:={λ u[[1]]};
t0=0.0;
u0=0.0;
T=1.0;
k=0.1;
n=IntegerPart[T/k];
mydataLMM1=MyODESolveUsingLMM[MyGetLMMCoefficients["Euler",1], f, t0, {{u0}}, k, n];
mydataLMM2=MyODESolveUsingLMM[MyGetLMMCoefficients["Adams-Bashforth",2], f, t0, {{u0},{u0+k}}, k, n];
mydataLMM3=MyODESolveUsingLMM[MyGetLMMCoefficients["Adams-Bashforth",4], f, t0, {{u0},{u0 +k},{u0 +2k},{u0 +3k}}, k, n];
mydataLMM4=MyODESolveUsingLMM[MyGetLMMCoefficients["Most Accurate 2-step Explicit",2], f, t0, {{u0},{u0 +k}}, k, n];
ps=0.02;
p1=ListPlot[{Map[Flatten,mydataLMM1],Map[Flatten,mydataLMM2],Map[Flatten,mydataLMM3]},Joined->False,PlotStyle->{{Blue,PointSize[ps]},{Green,PointSize[ps]},{Black,PointSize[ps]}}];
punstable=ListPlot[{Map[Flatten,mydataLMM4]},Joined->True,PlotStyle->{Orange}];

pexact=Plot[u0 Exp[λ(t-t0)],{t,t0,T},PlotStyle->Red,AxesOrigin->{0,0},PlotRange->{-0.1,1.0}];
Show[{pexact,p1,punstable}]

Instability for final time steps k

M=4; (* highest order to use *)
λ=-10;
t0=0.0;
u0=1.5;
T=5.0;
f[u_,t_]:={λ(u[[1]]-Cos[t])-Sin[t]};
sol[t_]:=Exp[λ(t-t0)](u0-Cos[t0])+Cos[t];
k=0.04;
n=IntegerPart[T/k];
N[λ k]
inivals={{sol[t0]},{sol[t0+k]},{sol[t0+2k]},{sol[t0+3k]}};
nsol[lmm_,ini_]:=MyODESolveUsingLMM[lmm,f,t0,ini,k,n];
colors={Red,Blue,Green,Orange};
Do[
{α,β}=MyGetLMMCoefficients["Adams-Bashforth",j];
plot[j]=ListPlot[Map[Flatten,nsol[{α,β},inivals[[1;;j]]]],
PlotStyle->{colors[[j]],PointSize[0.01]},Joined->False],
{j,1,M}
];
Show[{Plot[Cos[t],{t,0,T},PlotStyle->Gray,AxesOrigin->{0,0}], Plot[sol[t],{t,t0,T}],Table[plot[j],{j,1,M}]},PlotRange->{{0,T},{Min[-1,u0],Max[1.0,u0]}}]

M=5;
λ=-10;
k=0.04;
colors={Red,Blue,Green,Orange,Purple};
Do[
{α,β}=MyGetLMMCoefficients["Adams-Bashforth",j];
ρ[z_]:=MyPolynomial[α,z];
σ[z_]:=MyPolynomial[β,z];
bb[θ_]=ρ[Exp[I θ]]/σ[Exp[I θ]];
region[j]=ParametricPlot[{Re[bb[θ]],Im[bb[θ]]},{θ,0,2π},PlotRange->{{-2.5,2},{-1.5,1.5}},PlotStyle->colors[[j]]]
,{j,1,M}
];Show[Table[region[j],{j,1,M}],Graphics[{PointSize[Large],Black,Point[{λ k,0}]}]]