function grafinterp_lagr(funz,xnodi,a,b)


global axinterp axerrore axleb


fnodi = feval(funz,xnodi);
xi=linspace(a,b,100);

[yi,leb]=int_lag(xnodi,fnodi,xi);
yteor = feval(funz,xi);
yteor = yteor(:);
yi    = yi(:);

axes(axinterp);
cla

line(xi, yi ,'color','g')
line(xi,yteor,'color','r')
title('Interpolazione di Lagrange','Fontsize',16);

grid on
line(xnodi,fnodi,'color','g','LineStyle','*')



axes(axerrore);
cla

erri=(yi-yteor);
grid on
line(xi, erri ,'color','g')
title('errore','Fontsize',8)


set(axleb,'visible','on')
axes(axleb)
cla
grid on
line(xi, leb ,'color','g')
title('Funzione di Lebesgue','Fontsize',8)



function [y,leb] = int_lag(xnodi,f,x)

x = x(:);
xnodi=xnodi(:);
n =length(xnodi);
m = length(x);
em =ones(1,m);
en = ones(1,n-1);

for i=1:n
  den = prod(xnodi(i)-xnodi([1:i-1,i+1:n]));
  L(i,:)=prod( (x*en)' - (xnodi([1:i-1,i+1:n])*em))/den;
end

y = sum(diag(f)*L);
y = y(:);

if nargout == 2
  leb=sum(abs(L));
end




