

function p=lagrangeinterp(x,y)
%Solves a Lagrange interpolation problem
%INPUT
%x - nodes in a vector of size n+1
%y - avector of n+1 values 
%OUTPUT 
%p - coefficients of the polynomial in [x^(n),..,x,1] basis
%  wp(x) such taht p(x(k))=y(k) 
%EXAMPLE
%x=1:4;y=[1,-1,-2,4]'; p=lagrangeinterp(x,y);plot(s=linspace(1,4,300),polyval(p,s),x,y,"*")
  if(rows(y)!=length(x)) 
   warning("no of rows of y <> no of nodes in x");
   return; %exit the function
  end 
  V=vander(x);
  p=V\y;   
endfunction
