function c = newtondd(x,y)
% by Shelvean Kapita
% Newton divided differences
% computes coefficients of interpolating poly
% [x,y] columns of data points
n = length(x);
v = zeros(n); % initialize table
c = zeros(n,1); % initialize output coeffs
for j=1:n
    v(j,1)=y(j); % first column
end
for i=2:n % column i
    for j=1:n+1-i % fill column top to bottom
        v(j,i)=(v(j+1,i-1)-v(j,i-1))/(x(j+i-1)-x(j));
    end
end
for i=1:n
    c(i)=v(1,i);
end