function lagrange(xi,x,y)

n = columns(x);

for i = 1:n
   p(i) = 1;
   for j = 1:n
      if (j~=i)
       p(i) = (xi-x(j))/(x(i)-x(j))*p(i);
      endif
   endfor
endfor

yi = 0;
for i = 1:n
   yi = yi + p(i)*y(i);
endfor
yi
end