function p=lagrange(x,y)
n=length(x);
p=zeros(1,n);
for k=1:n
    L=poly([x(1:k-1),x(k+1:n)]);
    Q=L/polyval(L,x(k));
    p=p+Q*y(k);
end
    