% folium02.m
% fd, agreg Orsay, 24 novembre 2008  
% fd, 29 juin 2026
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
clear , format long
   
printf("folium02 ; folium de Descartes  et cosinusoide\n"); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

printf("\n"); 

hold off 
format long 

tt = [-.6 : .01 : 120] ; 
n = length(tt) ; 
x = zeros(n,1) ; y=x ; 

th = 0 ; 
for j = 1 : n ; 
x(j) = 3*tt(j) / (1+tt(j)**3) ; 
y(j) = tt(j) * x(j) ;  
% th = max ( th , abs ( x(j)**3 + y(j)**3 - 3*x(j)*y(j) ) ) ; 
end 


tt1 = [-80 : .01 : -1.5 ] ; 
n1 = length(tt1) ; 
x1 = zeros(n1,1) ; y1=x1 ; 

for j = 1 : n1 ; 
x1(j) = 3*tt1(j) / (1+tt1(j)**3) ; 
y1(j) = tt1(j) * x1(j) ;  
% th = max ( th , abs ( x1(j)**3 + y1(j)**3 - 3*x1(j)*y1(j) ) ) ;
end 
% th 

x2  = [-4 : .01 : 4] ;
n2 = length(x2)  ;  y2 = zeros(n2,1) ; 
for j = 1 : n2 ; 
y2(j) = cos ( x2(j) ) ;  end 


plot ( x , y , 'b;folium;' , x1,y1,  'b;;' , x2 , y2 ,  'r;cosinus;') 
axis equal 

title ('folium de descartes et cosinusoide') ;
print('04-a-folium-descartes-fonction-cosinus', '-djpg','-S891,630')  
pause(.5) 





  
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

nnewton = 4
  xalgo = zeros(nnewton,1) ; yalgo = zeros(nnewton,1) ; 
		     
xx = -3 ;  yy = 0 ; 
plot (xx , yy , 'm*;;' ) 
for j = 1 : nnewton 
xalgo(j) = xx ; yalgo(j) = yy ;

ff = zeros(2,1) ; 
ff(1,1) = xx**3 + yy**3 - 3*xx*yy ; 
ff(2,1) = yy - cos(xx) ;  ff ; 
df =  zeros(2,2) ; 
df(1,1) = 3*(xx**2 - yy) ;  
df(1,2) = 3*(yy**2 - xx) ;  
df(2,1) = sin(xx) ;   
df(2,2) = 1 ;  df ;
dd = - df \ ff ; 
xx = xx +  dd(1) ;
yy = yy +  dd(2) ;
%%%  plot (xx , yy , 'm*;;' )  %%% ; pause (.5) 
end 
xx , yy , dd
			      
hold off 
plot ( x , y , 'b;folium;' , x1,y1,  'b;;' , x2 , y2 ,  'r;cosinus;' , xalgo, yalgo, 'k*;;', xx , yy , 'ko;racine;' ) 
axis equal 
title ('folium de descartes et cosinusoide') ;
print('04-b-folium-descartes-fonction-cosinus-racine-1', '-djpg','-S891,630')  
pause(.5) 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hold off
nnewton = 5
xalgo = zeros(nnewton,1) ; yalgo = zeros(nnewton,1) ; 
xx = 1 ;  yy = 1.5 ; 
for j = 1 : nnewton
xalgo(j) = xx ; yalgo(j) = yy ;
ff = zeros(2,1) ; 
ff(1,1) = xx**3 + yy**3 - 3*xx*yy ; 
ff(2,1) = yy - cos(xx) ;  ff ; 
df =  zeros(2,2) ; 
df(1,1) = 3*(xx**2 - yy) ;  
df(1,2) = 3*(yy**2 - xx) ;  
df(2,1) = sin(xx) ;   
df(2,2) = 1 ;  df ;
dd = - df \ ff ; 
xx = xx +  dd(1) ;
yy = yy +  dd(2) ;  
end 
xx , yy , dd 

			      
hold off 
plot ( x , y , 'b;folium;' , x1,y1,  'b;;' , x2 , y2 ,  'r;cosinus;' , xalgo, yalgo, 'k*;;', xx , yy , 'ko;racine;' ) 
axis equal 
title ('folium de descartes et cosinusoide') ;
print('04-c-folium-descartes-fonction-cosinus-racine-2', '-djpg','-S891,630')
pause(.5) 

hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hold off
nnewton = 6
xalgo = zeros(nnewton,1) ; yalgo = zeros(nnewton,1) ; 

xx = 3 ;  yy = -1.5 ;  
for j = 1 : nnewton
xalgo(j) = xx ; yalgo(j) = yy ;
ff = zeros(2,1) ; 
ff(1,1) = xx**3 + yy**3 - 3*xx*yy ; 
ff(2,1) = yy - cos(xx) ;  ff ; 
df =  zeros(2,2) ; 
df(1,1) = 3*(xx**2 - yy) ;  
df(1,2) = 3*(yy**2 - xx) ;  
df(2,1) = sin(xx) ;   
df(2,2) = 1 ;  df ;
dd = - df \ ff ; 
xx = xx +  dd(1) ;
yy = yy +  dd(2) ;  
plot (xx , yy , 'c*;;' ) 
end 
xx , yy , dd 

		      
hold off 
plot ( x , y , 'b;folium;' , x1,y1,  'b;;' , x2 , y2 ,  'r;cosinus;' , xalgo, yalgo, 'k*;;', xx , yy , 'ko;racine;' ) 
axis equal 
title ('folium de descartes et cosinusoide') ;
print('04-d-folium-descartes-fonction-cosinus-racine-3', '-djpg','-S891,630')


