%
%  Some code for plotting cardinal polynomials
%  and the interpolating polynomial for n=3 data
%  points.
%
%  Input data below:
%
X=[1,2,4,5,6,7];
Y=[-1,-2,-1,-1,-1,1];
N=length(X);
%
%  Initialize variables to be plotted
%
xmin=min(X);
xmax=max(X);
x=xmin:0.05:xmax;
n=length(x);
%
clear L;
for i=1:N
    L(i,:)=ld(i,x,X);
end;
%
%
% Make the figures
%  
figure(1)
hold off
plot(X,Y,'r*')
hold on
for i=1:N
    plot(x,L(i,:),'b-')
end;
plot(x,zeros(1,n),'m:',x,ones(1,n),'m:')
for i=1:N
    plot([X(i),X(i)],[Y(i),1],'m:')
end
title('Cardinal Polynomials')
xlabel('x')
%
%
%
figure(2)
y=zeros(1,n);
for i=1:N
    y=y+Y(i)*L(i,:);
end;
plot(X,Y,'r*',x,y,'b-')
title('Interpolating Polynomial')

