%  newtpoly02.m
%  fd, agreg Orsay, 24 novembre 2008
% fd, 29 juin 2026
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   clear , format long
   
printf("newtpoly02 ; valeur imposee d un polynome \n"); 
printf("          six mises en oeuvre de l algorithme de Newton \n"); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 


hold off 
format long 

x = [ 0.9 : .01 : 8.1 ] ; 
n = length(x) ; 
y=x ; 

th = 0 ; 
for j = 1 : n ; 
y(j) = (x(j)-1)*(x(j)-2)*(x(j)-3)*(x(j)-5)*(x(j)-7)*(x(j)-8)  ;  end 


aa = -40 
printf("\n")

for k=1 : 6
hold off 
if (k==1)  x0 = 1 ; end  
if (k==2)  x0 = 2 ; end  
if (k==3)  x0 = 3 ; end  
if (k==4)  x0 = 5 ; end  
if (k==5)  x0 = 7 ; end  
if (k==6)  x0 = 8 ; end

xx = x0 ; 
for j = 1 : 7  
valeur=poly (xx, aa) ; 
ff = valeur(1) ;  
df = valeur(2) ;  
dx = - ff / df ; 
### plot ( xx , ff+aa , '*r;;' )
xx = xx + dx ; 
end

printf("numero de la racine   ")
k 

printf("racine  ")
xx

printf("erreur  ")
dx
printf("\n")
  
%%% printf("racine ", xx,"\n")
%%% printf("erreur =", dx , "\n")

xaxex = zeros(2) ; xaxex(1) = .5 ;  xaxex(2) = 9.5 ; 
yaxex = zeros(2) ; yaxex(1) = 0. ;  yaxex(2) = 0. ; 
ym40axex = zeros(2) ; ym40axex(1) = -40. ;  ym40axex(2) = -40. ; 

plot ( xaxex, ym40axex , 'k;;' , x , y , 'b;polynome;',   xx,ff+aa,  'or;racine;') ; pause (.5) 

title ('algorithme de Newton') ;
if (k==1)  print('02-a-racine-numero-1', '-djpg','-S891,630')  end ; 
if (k==2)  print('02-b-racine-numero-2', '-djpg','-S891,630')  end ; 
if (k==3)  print('02-c-racine-numero-3', '-djpg','-S891,630')  end ; 
if (k==4)  print('02-d-racine-numero-4', '-djpg','-S891,630')  end ; 
if (k==5)  print('02-e-racine-numero-5', '-djpg','-S891,630')  end ; 
if (k==6)  print('02-f-racine-numero-6', '-djpg','-S891,630')  end ; 






end 
