Example
Let us compare the midpoint method on an example:
;
;
>
> f:=(t,y)->-y+t+1;w[0]:=1;t[0]:=0;wt[0]:=1;
> d1:=diff(f(t,y(t)),t);d2:=subs(diff(y(t),t)=f(t,y),y(t)=y,d1);
> df:=unapply(d2,(t,y));
> h:=0.1:for i from 0 to 9 do wt[i+1]:=wt[i]+h*(f(t[i],w[i])+h*df(t[i],wt[i])/2):w[i+1]:=w[i]+h*f(t[i]+h/2,w[i]+h*f(t[i],w[i])/2):t[i+1]:=t[i]+h: print(t[i+1],w[i+1],wt[i+1]) od:
Both Taylor's method and the Midpoint method yield the same result, but one does not need to evaluate the derivative of
analytically when using the Midpoint method.
>