Code covered by the BSD License

# Numerical Methods Using MATLAB, 3e

### John Mathews (view profile)

20 Aug 2002 (Updated )

Companion Software

H=hamming(f,T,Y)
```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 and
%         Y is the vector of ordinates

% NUMERICAL METHODS: MATLAB Programs
%(c) 1999 by John H. Mathews and Kurtis D. Fink
%To accompany the textbook:
%NUMERICAL METHODS Using MATLAB,
%by John H. Mathews and Kurtis D. Fink
%ISBN 0-13-270042-5, (c) 1999
%PRENTICE HALL, INC.

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;
cold=0;

for k=4:n-1

%Predictor
pnew=Y(k-3)+(4*h/3)*(F(2:4)*[2 -1 2]');

%Modifier
pmod=pnew+112*(cold-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;
cold=cnew;
F(4)=feval(f,T(k+1),Y(k+1));
end

H=[T' Y'];

```