function gradient2d0() %%%%%%%%%%%%%% close all x(1)=1.0 x(2)=-1.2 t=0.00001 kmax=1000 for i=1:kmax; if (norm(g(x))<1e-5) break end ii=i d=-g(x) %t=RL(x,d) %t=RL_Armijo(x,d) t=RL_Goldestein(x,d) %t=RL_Wolf(x,d) x=x+t*d %thep=thetap(t,x,d) abs_grad_f=norm(g(x)) f_val=f(x) y(i,:)=x; end %%%%%%%%%%%%%%%%% %%% Partie Plot %%%%%%%%%%%%%%%%% x1 = -1.5:0.1:1.5; x2= -1.5:0.1:1.5; [x1,x2] = meshgrid(x1,x2); Z = 100*(x2-x1.^2).^2 + (1-x2).^2; contourf(x1,x2,Z,30); hold on plot(y(:,1),y(:,2),'w-o') colormap jet fontsz=16; xlabel('$x$','Interpreter','latex','FontSize',fontsz) ylabel('$y$','Interpreter','latex','FontSize',fontsz) title({'Acheminement des iter\''ees de la m\''ethode du gradient'},'Interpreter','latex') %%%%%%%%%%%%%%%%% function d=f(x); % d = (x(1)-1).^2+(x(2)-1).^2; d=100*(x(2)-x(1).^2).^2 + (1-x(1)).^2; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function d=g(x); %d(1) = 2*(x(1)-1);%d(2) = 2*(x(2)-1); d(1)=-(400*(x(2)-x(1).^2)).*x(1)-2+2*x(1); d(2)=200*x(2)-200*x(1).^2; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function y=theta(t,x,d); y=f(x+t*d); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function y=thetap(t,x,d); y=g(x+t*d)*d'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%Recherche lineaire %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function tk=RL(x,d); kmax=150; a=0.0; b=1e-3; beta=10; %%%%Chercher le premier pas for i=1:100; if (thetap(b,x,d)>=0) break else b=beta*b; end end %%%%%%%% for i=1:kmax; tk=(a+b)/2; if (abs(thetap(tk,x,d))<1e-5) %2.0) break elseif (thetap(tk,x,d)<0) a=tk; else b=tk; end end %%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%RL Amijo%%%%%%%%%%%%%%%%%% function t=RL_Armijo(x,d) m=.3d0; t1=0.095; for i=1:150 t=(t1^i); if (theta(t,x,d) <= (m*t*thetap(0,x,d))+theta(0,x,d)) break end end %%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%%%%%%RL Goldestein%%%%%%%% % function t=RL_Goldestein(x,d) % m1=.3d0; % m2=.7d0; % alfa=10d0; % lambda=.5d0; % t=0.0001; % td=0; % tg=0; % hhh= (m1*t*thetap(0,x,d))+theta(0,x,d) % for i=1,150 % if ((theta(t,x,d) <= (m1*t*thetap(0,x,d))+theta(0,x,d)) && (theta(t,x,d) >= (m2*t*thetap(0,x,d))+theta(0,x,d))) % break % if(theta(t,x,d) > (m1*t*thetap(0,x,d))+theta(0,x,d)) % td=t % end % if (theta(t,x,d) < (m2*t*thetap(0,x,d))+theta(0,x,d)) then % tg=t % end % if (td==0) then % t=alfa*tg % else % t=td*lambda+((1-lambda)*tg) % end % end % end % %%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%RL Wolf%%%%%%%%% function t=RL_Goldestein(x,d) m1=.3; m2=.7; alfa=10; lambda=.5; t=0.001; td=0; tg=0; for i=1:50 if ((theta(t,x,d) <= (m1*t*thetap(0,x,d))+theta(0,x,d)) && (theta(t,x,d) >= (m2*t*thetap(0,x,d))+theta(0,x,d))) break if(theta(t,x,d) > (m1*t*thetap(0,x,d))+theta(0,x,d)) then td=t; end if ((theta(t,x,d) <= (m1*t*thetap(0,x,d))+theta(0,x,d)) &&(theta(t,x,d) < (m2*t*thetap(0,x,d))+theta(0,x,d))) tg=t; end if (td==0) then t=alfa*tg; else t=td*lambda+((1-lambda)*tg); end end end %%%%%% %%%%%%%%%RL Wolf%%%%%%%%% function t=RL_Wolf(x,d) m1=.3; m2=.7; alfa=10; lambda=.5; t=0.002; td=0; tg=0; for i=1:150 if ((theta(t,x,d) <= (m1*t*thetap(0,x,d))+theta(0,x,d)) && (thetap(t,x,d) >= (m2*thetap(0,x,d)))) break if(theta(t,x,d) > (m1*t*thetap(0,x,d))+theta(0,x,d)) then td=t; end if ((theta(t,x,d) <= (m1*t*thetap(0,x,d))+theta(0,x,d)) && (thetap(t,x,d)<(m2*thetap(0,x,d)))) tg=t; end if (td==0) then t=alfa*tg; else t=td*lambda+((1-lambda)*tg); end end end