function s=lagrange(x,y,k) n=length(x) s=0 for i=1:n p=x p(i)=[] t=1 for j=1:n-1 t=t*(k-p(j))/(x(i)-p(j)) endfor s=s+y(i)*t endfor endfunction