Wednesday, May 9, 2012

Newtons Forward Interpolation Using Matlab


function fp=forward_interpolation(x,y,p)
n=length(x);
for i=1:n
    diff(i,1)=y(i);
end
for j=2:n
    for i=1:n-j+1
        diff(i,j)=diff(i+1,j-1)-diff(i,j-1);
    end
end
answer=y(1);
h=x(2)-x(1);
s=(p-x(1))/h;
for i=1:n-1
    term=1;
    for j=1:i
        term=term*(s+j-1)/j;
    end
    answer=answer+term*diff(1,i+1);
end
fp=answer;

Arguments sent to the function are:- lagrange(xdataset,ydataset,interpolating point)

Reactions:

1 comment: