%This illustrate interpolation of sin(x) at equally spaced nodes.  
%Experiment different number
%of interpolation points. Also compare it with Taylor approximation.
 
% set the data points for interpolation
% x-coordinates in x and y-coordinates in y
x=-1:0.03:1;
x=x';
y=sin(10*x);
e=0.0;
u=(min(x)-e:0.005:max(x)+e)';  % set points in x-axis

% compute the interpolating polynomial
n = length(x);
v = zeros(size(u));
for k = 1:n
   w = ones(size(u));
   for j = [1:k-1 k+1:n]
      w = (u-x(j))./(x(k)-x(j)).*w;
   end
   v = v + w*y(k);
end

w=sin(10*u);
error=v-w;
plot(u,v, u,w, u, error);

 
