x = -5:1:5;
y = 1./(1+10*x.^2);
%syms t
n = length(x);
% contructing Lagrange polynomials L1, L2,..., Ln
L = zeros(1,n,'sym');
for i = 1:n
    L(i) = 1;
    z = x;
    z(i) = [];     % xx is an array obtained from array x by obmitting the i'th entry
    for j = 1:n-1
        L(i) = L(i)*(t - z(j))/(x(i)-z(j));
    end
end
% construct P = y1*L1 + y2*L2 + ... + yn*Ln
P = L*transpose(y);
%simplify(P)
ezplot(P,[-5 5])
hold on
f = @(x) 1/(1+10*x^2);
ezplot(f,[-5 5])