function x = dividedDifference(t,y)
% Divided difference method for computing coefficients
% in Newton's interpolant using a 2D array.
% Given data points: (t1, y1), ... (tN, yN)
% t is the row or column vector (t1 t2 ... tN)
% y is the row or column vector (y1 y2 ... yN)
% K. Ming Leung, 03/06/03

%t=[-2 0 1];
N=length(t);
F=zeros(N,N);
F(:,1)=y(:); %[-27; -1; 0];
for i=2:N
    for j=2:i
        F(i,j)=(F(i,j-1)-F(i-1,j-1))/(t(i)-t(i-j+1));
    end
end
x=diag(F);