clear;
x=[-2:0.4:2];           % create a vector x of values from -2 jumping by ...
                        % 0.4 until it gets to 2
                        
y = exp(-5*x.^2);       % create a vector y = exp(-5x^2)
                        
xx=linspace(-2,2,100);  % create a vector xx of 100 evenly spaced numbers...
                        % between -2 and 2 

yy=exp(-5*xx.^2);       % create a vector yy = exp(-5xx^2)

P_xx = polyinterp(x, y, xx); 
% P_xx is the Lagrange interpolating polynomial that  
% interpolates the points in the vectors x and y 
% at the values in the vector xx.   
% That is, P_xx = P(xx) where P is the Lagrange interpolating polynomial 
% through (x(1),y(1)),(x(2),y(2)), ...,(x(n),y(n))

figure(1); plot(x,y,'o',xx,yy,xx,P_xx );
legend('Interpolating points','y = f(x)', 'y=P(x)')