%% Example 1.2
% Lagrange Polynomial Interpolation of Runge Function
%
% Interpolation of the Runge function using 
% 11 NON equally spaced points on [-1,1]
% (data points are more finely spaced near ends)


%% Define Vectors
x = [-1:0.01:1];
X = [-1.00 -0.95 -0.81 -0.59 -0.31 0.00 0.31 0.59 0.81 0.95 1.00];

y = 1./(1+25*x.^2);
Y = 1./(1+25*X.^2);

%% Lagrange Interpolation
pol = lagrange_interp(X,Y,x);

%% Generate plots
plot(x,pol,'k',x,y,'k--',X,Y,'k.');
legend('Lagrange Polynomial','Expected behavior','Data Points');
axis([-1 1 -0.05 1.2]);