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
In 1959, Richard Wesley Hamming from Bell Telephone Laboratories, Murray Hill, New Jersey, proposed a stable predictor-corrector method for ordinary differential equations, which now bears his name. He improved classical Milne--Simpson method by replacing unstable corrector rule by a stable one.
Journal of the ACM, Volume 6, Issue 1, Jan. 1959, pages 37-47.
Example. Let us start with the Riccati equation \( y' = x^2 + y^2 \) subject to the initial condition \( y(0) =-1 . \) Its solution is expressed through Bessel functions:
Plot[d[x], {x, 0, 5.5}, PlotStyle -> Thick]

function H=hamming(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: H=[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
pnew=y(k-3)+(4*h/3)*(F(2:4)*[2 -1 2]');
% Modifier
pmod=pnew+112*(yold-pold)/121;
t(k+1)=t(1)+h*k;
F=[F(2) F(3) F(4) feval(f,t(k+1),pmod)];
% Corrector
cnew=(9*y(k)-y(k-2)+3*h*(F(2:4)*[-1 2 1]'))/8;
y(k+1)=cnew+9*(pnew-cnew)/121;
pold=pnew;
yold=cnew;
F(4)=feval(f,t(k+1),y(k+1));
end
H=[t',y'];
Example. Hamming's solution to \( y' = 30-5y, \quad y(0) =1 \) over interval [0,10] with N = 50 steps produces oscillations. It is stabilized when N = 70.
Complete