function gradient2d() %%%%%%%%%%%%%% x(1)=-1.5 x(2)=1.5 t=0.0001 kmax=10000 for i=1:kmax; d=-g(x); x=x+t*d abs_grad_f=norm(g(x)) f_val=f(x) y(i,:)=x; end %%%%%%%%%%%%%%%%% %%% Partie Plot %%%%%%%%%%%%%%%%% x1 = -3:0.1:3; x2= -3:0.1:3; [x1,x2] = meshgrid(x1,x2); Z = 100*(x2-x1.^2).^2 + (1-x2).^2; contourf(x1,x2,Z,10); hold on plot(y(:,1),y(:,2),'w.') colormap jet %%%%%%%%%%%%%%%%% 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=thetap(t,x,d); y=g(x+t*d)*d'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%Recherche lineaire %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function tk=RL(t,x,d); kmax=100 alpha=1.2 beta=0.9 for i=1:kmax; if (thetap(t)<0) t=alpha*t elseif (thetap(t)>0) t=beta*t end end