function [x1,dd1] = ajoute(x0,dd0,x,y)
  n = prod(size(x0));
  x1 = zeros(n+1,1);
  dd1 = zeros(n+1,1);
  den = zeros(n+1,1);
  
  dif = x-x0;
  den = [1 dif];
  
  x1 = [x x0];
  dd1(1) = y;
  
  for i=1:n, dd1(i+1)=(dd1(i)-dd0(i))/(den(i+1)), end
  
endfunction;

function y=evalue(xx,dd,t)
  n = prod(size(xx));
  y = zeros(t);
  p = ones(t);
  for i=1:n, 
    y=y+dd(i)*p
    p = p.*(t-xx(i))
  end
endfunction

t=-1:0.01:1;
xx=[];
dd=[];
goon = %T;
xbasc();
xset("colormap",jetcolormap(16));

replot(rect=[-1 -2 1 2]);
xtitle('Click gauche pour ajouter un point, droit pour sortir')

while goon
  [ibutton, x, y] = xclick(1);
  if ibutton == 5 goon = %F // click droit on arrete
  else // click gauche on rajoute le point
  plot2d(x,y,style=-1);  
  [xx, dd] = ajoute(xx, dd, x, y);
  nbpts = prod(size(xx));
  plot2d(t,evalue(xx,dd,t),style=nbpts);
  xtitle('nombre de points = '+string(nbpts)+' / click gauche ajoute un point, droit sortir');
  replot(rect=[-1 -2 1 2]);
  end
end;
  
  
