Integration af 1.ordens differentialligning
Euler's metode, Opgave 15 i Afsnit 20.1

Clear[x,y,f,F];

h=0.1; n=8;

x[0]=1; Do[x[i]=x[i-1]+h,{i,n}]

f[x_,y_]=(2/x)Sqrt[y-Log[x]]+1/x;  y[0]=0;

Do[y[i]=y[i-1]+h f[x[i-1],y[i-1]],{i,n}]

z=Table[{x[i-1],y[i-1]},{i,n+1}];

TableForm[z]

g1=ListPlot[z,PlotStyle->{PointSize[0.015],RGBColor[1,0,0]}]

F[x_]=Log[x](Log[x]+1); g2=Plot[F[x],{x,1,1.8}]

Show[g1,g2]

w=Table[{x[i-1],y[i-1],F[x[i-1]],F[x[i-1]]-y[i-1]},{i,n+1}];

TableForm[w]

Euler's forbedrede metode, Opgave 16

h=0.2; n=4; Do[x[i]=x[i-1]+h,{i,n}]

Do[{
k1 = h f[x[i-1],y[i-1]]; 
k2 = h f[x[i],y[i-1]+k1];
y[i] = y[i-1]+0.5(k1+k2)},{i,n}]

z=Table[{x[i-1],y[i-1]},{i,n+1}];

TableForm[z]

g3=ListPlot[z,PlotStyle->{PointSize[0.015],RGBColor[0,1,0]}]

Show[g1,g2,g3]

w=Table[{x[i-1],y[i-1],F[x[i-1]],F[x[i-1]]-y[i-1]},{i,n+1}];

TableForm[w]

Runge-Kutta metoden, Opgave 17

h=0.4; n=2; Do[x[i]=x[i-1]+h,{i,n}]

Do[{
k1 = h f[x[i-1],y[i-1]]; 
k2 = h f[x[i-1]+0.5h,y[i-1]+0.5k1];
k3 = h f[x[i-1]+0.5h,y[i-1]+0.5k2];
k4 = h f[x[i],y[i-1]+k3];
y[i] = y[i-1] + (k1+2k2+2k3+k4)/6},{i,n}]

z=Table[{x[i-1],y[i-1]},{i,n+1}];

TableForm[z]

g4=ListPlot[z,PlotStyle->{PointSize[0.015],RGBColor[0,0,1]}]

Show[g1,g2,g3,g4]

w=Table[{x[i-1],y[i-1],F[x[i-1]],F[x[i-1]]-y[i-1]},{i,n+1}];

TableForm[w]

Runge-Kutta metoden, Opgave 18

h=0.1; n=8; Do[x[i]=x[i-1]+h,{i,n}]

Do[{
k1 = h f[x[i-1],y[i-1]]; 
k2 = h f[x[i-1]+0.5h,y[i-1]+0.5k1];
k3 = h f[x[i-1]+0.5h,y[i-1]+0.5k2];
k4 = h f[x[i],y[i-1]+k3];
y[i] = y[i-1] + (k1+2k2+2k3+k4)/6},{i,n}]

z=Table[{x[i-1],y[i-1]},{i,n+1}];

TableForm[z]

g4=ListPlot[z,PlotStyle->{PointSize[0.015],RGBColor[0,0,1]}]

Show[g1,g2,g3,g4]

w=Table[{x[i-1],y[i-1],F[x[i-1]],F[x[i-1]]-y[i-1]},{i,n+1}];

TableForm[w]