# Aitken method for interpolation

• Dec 28th 2013, 05:15 AM
Nforce
Aitken method for interpolation
I have written aitken's method for interpolation in octave/matlab.

I would like know if it's right. Because i get this result if I call
Code:

`drawint(4)`
.

http://i.imgur.com/f77MINX.png

Here is the code, feel free to modify for correcting.

Code:

` function w = aitken(t,x,y)        % t is a vector of x axis values of points where we want to interpolate        % x and y are vectors of known points        % return value w is a vector of calculated points (aitken method) on y axis        n=length(y);        Z=zeros(n);        Z(1,:)=y;        temp=zeros(1,length(t));        for k=1:1:length(t)                for j=1:n-1                        for i=j+1:n                                Z(j+1,i)=(Z(j,i)*(t(k)-x(j))-Z(j,j)*(t(k)-x(i)))/(x(i)-x(j));                        end                end                temp(k)=Z(n,n);        end        w=temp;endfunction drawint(m)        x=0:pi/20:pi;        figure; clf;        plot(x,sin(x));        hold on;        step=(pi/m);        xf=0:step:pi;        yf=aitken(xf,x,sin(x))        plot(xf,yf,'r');end`