MATLAB TUTORIAL for the First Course. Part III: Predictor-corrector 4

Prof. Vladimir A. Dobrushkin

This tutorial contains many matlab scripts.
You, as the user, are free to use all codes for your needs, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately. Any comments and/or contributions for this tutorial are welcome; you can send your remarks to

Email Vladimir Dobrushkin

Predictor-corrector 4
To approximate the solution to the initial value problem
\[ y' = f(x,y) , \qquad y(x_0 ) = y_0 \qquad\mbox{over the interval} \quad [a,b] = [x_0 , x_m ] \]
by using the Adams--Bashforth predictor
\[ p_{n+1} = y_{n} + \frac{h}{24} \left( -9\, f_{n-3} +37\,f_{n-2} - 59\,f_{n-1} + 55\,f_n \right) , \qquad n=3,4,\ldots . \]
and Adams--Moulton corrector
\[ y_{n+1} = y_n + \frac{h}{24} \left( f_{n-2} - 5\, f_{n-1} + 19\,f_n +9\,f_{n+1} \right) , \qquad n=3,4,\ldots . \]

function A=abm4(f,t,y)
% Input:    f is the function entered as a string 'f'
%           t is the vector of abscissas
%           y is the vector of ordinates
% Remark:   The first four coordinates of t and y must have 
%           starting values obtained with RK4
% Output:   A=[t',y'] where t is the vector of abscissas
%           y is the vector of ordinates
n=length(t);
if n < 5, break,end;
F=zeros(1,4); 
F=feval(f,t(1:4),y(1:4));
h=t(2)-t(1);
pold=0;
yold=0;
for k=4:n-1
    % Predictor
    p=y(k)+(h/24)*(F*[-9 37 -59 55]'); 
    t(k+1)=t(1)+h*k;
    F=[F(2) F(3) F(4) feval(f,t(k+1),p)];
    % Corrector
    y(k+1)=y(k)+(h/24)*(F*[1 -5 19 9]'); 
    F(4)=feval(f,t(k+1),y(k+1));
end
A=[t',y'];

Example. Hamming's solution to \( y' = 30-5y, \quad y(0) =1 \) over interval [0,10] with N = 37 steps produces oscillations. It is stabilized when N = 65.


Complete