% Vicol Vlad, small changes by M.O.
%
% This function evaluates the Lagrange interpolating polynomial of a
% function f, externally defined, with n equidistant nodes on
% the interval [-5,5]

function res = LagrangeN (x,n)

  v   = linspace (-5,5,n);
  sum = 0;

  for i=1:n
    prod = f(v(i));
    for j=1:n
        if (j~=i)
            prod = prod * (x-v(j))/ (v(i)-v(j));
        end
    end
    sum = sum + prod;
end

res=sum ;

        

