% Problem interpolating a noisy straight line

% K. Ming Leung, 02/26/03

clear all; hold off;
ti=[0; 0.2; 0.8; 1.0; 1.2; 1.9; 2.0; 2.1; 2.95; 3.0];
yi=[0.01; 0.22; 0.76; 1.03; 1.18; 1.94; 2.01; 2.08; 2.9; 2.95];
x = dividedDifference1(ti,yi);
%x=[-27; 13; -4];

t=0:0.001:3;

N=length(x); % N=n+1
p = x(N);
for k=N-1:-1:1
    p = x(k)+(t-ti(k)).*p;
end
plot(t,p,'-b','lineWidth',2); hold on;
xlabel('t','FontSize',18);
ylabel('y','FontSize',18);
title('Interpolating a Noisy Straight Line','FontSize',18);
%plot([0 3],[0 3],'k-');
plot(ti,yi,'r.','markerSize',14);
% using a cubic spline
[xPlot, yPlot]=cubicSplineNaturalF(ti,yi,10);
plot(xPlot,yPlot,'g');