n=15;
ngraph=100;


deff('y=h(x)','y=(1)./(1+(10).*(x.^2))');
//----------------------------------------------------------
function P=Lagrange(x,y);


[un,npoints]=size(x);

P=poly(0,'x','coeff');
X=poly(0,'x');


for i=1:npoints
		Pi=poly(y(i),'x','coeff');
		for k=1:npoints
				if i<>k then Pi=Pi*(X-x(k))/(x(i)-x(k)); end;
		end;
		P=P+Pi;
end;

endfunction;
//----------------------------------------------------------

xequi=linspace(-1,1,n);
xtche=cos(%pi/(2*n)*(1:2:(2*n-1)));
xgraph=linspace(-1,1,ngraph);


hequi=h(xequi);
htche=h(xtche);
P=Lagrange(xequi,hequi);
Q=Lagrange(xtche,htche);

hgraph=h(xgraph);
Pgraph=horner(P,xgraph);
Qgraph=horner(Q,xgraph);

clf();
plot2d([xgraph;xgraph;xgraph]',[hgraph;Pgraph;Qgraph]',leg='fonction exacte@points equirepartis@points de Tchebychev');

erequi=max(abs(hgraph-Pgraph));
ertche=max(abs(hgraph-Qgraph));

printf('erreur avec points equirepartis= %f\n',erequi);
printf('erreur avec points de Tchebychev= %f\n',ertche);
