Fourth order Runge-Kutta
Starting from the form,
one can derive the Runge-Kutta method of order 4, which is a very popular method:
;
;
;
;
;
>
The plot below illustrates its graphical interpretation: use the slope at the starting point to predict the value at the midpoint,
, then recalculate the slope at this estimated point and use this slope to find a better estimate at the midpoint. This third estimate for the slope is then used to predict a value at
, and a fourth estimate for the slope is calculated at this estimate as well. Then all four estimates for the slope are used in a weighted average and a final estimate is calculated.
> y:=t->t+exp(-t);
> f:=(t,y)->-y+t+1;
> k[1]:=0.4*f(0,1):k[2]:=0.4*f(0.2,1+k[1]/2):k[3]:=0.4*f(0.2,1+k[2]/2):
> k[4]:=0.4*f(0.4,1+k[3]):
> with(plots):pl1:=plot(y(t),t=0..0.6,y=0.9..1.1):
> pl2:=plot([t,1+f(0,1)*t,t=0..0.3],color=blue):
> pl3:=plot([0.2,t,t=0..1+f(0,1)*0.2],color=blue):
>
### WARNING: the definition of the type `symbol` has changed'; see help page for details
pl4:=plot([[0.2,1]],style=point,symbol=diamond):
> pl5:=plot([0.2+t,1+f(0.2,1)*t,t=-0.1..0.1],color=magenta):
> pl6:=plot([0.2,t,t=0..1.+k[2]/2],color=blue):
> pl7:=plot([t,1+k[2]/0.4*t,t=0..0.3],color=magenta):
> pl8:=plot([0.2+t,1+k[2]/2+k[3]/0.4*t,t=-0.1..0.1],color=green):
> pl9:=plot([0.4,t,t=0..1.+k[3]],color=blue):
> pl10:=plot([t,1+k[3]/0.4*t,t=0..0.45],color=green):
> pl11:=plot([0.4+t,1+k[3]+k[4]/0.4*t,t=-0.1..0.1],color=orange):
> pl12:=plot([0.4,t,t=0..1.+(k[1]+2*k[2]+2*k[3]+k[4])/6],color=blue):
> pl13:=plot({[t,1+(k[1]+2*k[2]+2*k[3]+k[4])*t/(6*0.4),t=0..0.45]},color=black):
> display({pl.(1..13)});
>