You are on page 1of 1

Implementation of Newton Divided Dierence Polynomial in Scilab

Dene y = f (x)
dene a function that plots data points
function plotpoints (m, k)
plot2d (m (1, :) , m (2, :) , k)// m is a 2 n vector and k is plot style
endfunction
dene a vector X containing the x coordinates and vector Y containing the y
coordinates of the data points.
dene a matrix named data with X in the rst row and Y in the second row.
dene n as the length of vector X or vector Y .
dene x as a polynomial variable: use poly command
dene an n n matrix D whose entries are all zero D = zeros(n, n) .
put the y values on the rst column of D
loop

f or j = 2 to n
f or k = j to n
D(k,, j1)D(k1, j1)
D (k, j) = xdata(
k )xdata(kj+1)
end
end
get the diagonal of D and place all the values in a vector, say vector dd.
get the transpose of dd, i.e.dd = dd0
dene a polynomial L as a product of the factors x x1 ,x x2 ,..., x xn ,
 put all these to a vector LL
 get the 1st mm elements of dd and LL
 get the polynomial interpolant by taking the matrix product of dd and LL
LL = [ ] ; L = 1;
loop
f or i = 1 to n 1

L=L*(x xdata (i));

LL=[LL,L];
end
LL = [1 LL];
LL = LL0 ;
dd = dd(1 : mm);
LL = LL(1 : mm);
npoly=dd*LL;
to plot, evaluate npoly at several values.
Note: use horner command
call plotpoints to plot the data points

You might also like