n=15;

nPlotPoints=101;

xLeft=-5;
xRight=5;


xValues=linspace(xLeft,xRight,n+1);
fValues=atan(xValues);

xPlotValues=linspace(xLeft,xRight,nPlotPoints);
fPlotValues=atan(xPlotValues);
yPlotValues=zeros(1,nPlotPoints);

for i=1:nPlotPoints;

  yPlotValues(i)=Lagrange(n+1,xValues,fValues,xPlotValues(i));

end

figure(1)
clf

plot(xPlotValues,yPlotValues,'--')
hold on
plot(xPlotValues,fPlotValues,'-.')
plot(xPlotValues,fPlotValues-yPlotValues,'-')
hold off

legend('y(x)','f(x)','error')
xlabel('x')
ylabel('f(x)')
axis([-5 5 -2.5 2.5])
title(strcat('n=',num2str(n)))
