Example
Consider the initial value problem
,
in
and
.
With the exact solution
.
The Adams-Bashforth method of order three is given by
,
the Adams-Moulton Method of order three is given by
For
, we need
,
and
to start the calculation. Consider a step-size
, we will then use fourth-order Runge-Kutta to find estimates for
and
:
> f:=(t,y)->-y+t+1;y:=t->t+exp(-t);
> h:=0.1;w[0]:=1.;t[0]:=0;
> for i from 0 to 2 do k[1]:=h*f(t[i],w[i]):k[2]:=h*f(t[i]+h/2,w[i]+k[1]/2):k[3]:=h*f(t[i]+h/2,w[i]+k[2]/2):k[4]:=h*f(t[i]+h,w[i]+k[3]): t[i+1]:=t[i]+h;w[i+1]:=w[i]+(k[1]+2*k[2]+2*k[3]+k[4])/6; print(t[i+1],w[i+1],abs(w[i+1]-y(t[i+1]))); od:
So we have our estimates for
and
. In addition, the estimate for
has been calculated as well, to compare with the results obtained from the predictor-corrector pair.
The Adams=Bashforth method then yields:
> wab[3]:=w[2]+(h/12)*(23*f(t[2],w[2])-16*f(t[1],w[1])+5*f(t[0],w[0]));
> errab:=abs(wab[3]-y(t[3]));
We now have a predicted value. The corrector step uses the Adams-Moulton Method:
> wam[3]:=w[2]+(h/12)*(5*f(t[3],wab[3])+8*f(t[2],w[2])-f(t[1],w[1]));
> erram:=abs(wam[3]-y(t[3]));
Which is clearly more accurate.
Why is this result not as accurate as the estimate obtained by the Fourth Order Runge-Kutta Method?
One option now is to iterate using the Adams-Moulton formula:
> wam2[3]:=w[2]+(h/12)*(5*f(t[3],wam[3])+8*f(t[2],w[2])-f(t[1],w[1]));
> erram2:=abs(wam2[3]-y(t[3]));
> wam3[3]:=w[2]+(h/12)*(5*f(t[3],wam2[3])+8*f(t[2],w[2])-f(t[1],w[1]));
> erram3:=abs(wam3[3]-y(t[3]));
> wam4[3]:=w[2]+(h/12)*(5*f(t[3],wam3[3])+8*f(t[2],w[2])-f(t[1],w[1]));
> erram4:=abs(wam4[3]-y(t[3]));
>
> wam5[3]:=w[2]+(h/12)*(5*f(t[3],wam4[3])+8*f(t[2],w[2])-f(t[1],w[1]));
> erram5:=abs(wam4[3]-y(t[3]));
>
As you can see, convergenc may be slow and may not improve the accuracy. Alternative options are to repeat the calculations using a smaller step-size or use a higher order predictor-corector pair.
In practice iteration is only seldom used.
>
>