Thursday, December 30, 2010

Newton's Interpolation toolbox

Newton's interpolation for a given set of points is interpolating them to a polynomial. For a given number of points Nthe degree of the resulting polynomial will be N-1”. 

And here you are some snapshots



The following Scilab code is used for this interpolation method



//This tool box is not working right for 4 points or less

labels=["Independent variable name"];
[ok,name]=getvalue("Enter the independent variable name (i.e., x, w, Shady)",labels,...
list("str",-1),["x"]);

//Generating array of random numbers (two columns width)
array=rand(10,2);
editvar array;

//don't copy and paste the following lines till you edit the array

x=array(:,1); y=array(:,2);

lst=list(x,y);

for m=1:max(size(x))-2,
n=1:max(size(x))-m;
c=(lst(m+1)(n+1)-lst(m+1)(n))./(lst(1)(m+n)-lst(1)(n));
lst(m+2)=c;end;

//Defining a protected variable "s"
s=%s;

pol=0;

for m=3:max(size(x)),
mat=1;
for n=1:m-2,
a=s-lst(1)(n);
mat=a*mat;
end;
c=mat*lst(m)(1);
pol=pol+c;
end;

pol=pol+lst(2)(1);

varn(pol,name)  //Show the polynomial "pol"