% Evaluate Newton polynomial via shifted Horner's method
% Polynomial is assumed to have Newton interpolant form
% Coefficents computed using divided differences.
% K. Ming Leung, 02/26/03
% Example here is from Heath

clear all;
% Input data
ti=[-2; 0; 1];
yi=[-27; -1; 0];
% Compute coefficients:
x = dividedDifference1(ti,yi);

t=-3:0.1:2; % Points to plot
% Evaluate interpolant via shifted Horner's method
N=length(x); % N=n+1
p = x(N);
for k=N-1:-1:1
    p = x(k)+(t-ti(k)).*p;
end

% Plot the resulting fit:
plot(t,p,'-b',ti,yi,'r*');
xlabel('t');
ylabel('y');
title('Newton Interpolation');