clear; clc; close all; draw=1; tpause=0.5; L=0.5; method='fr'; %'sd';%'powell';%'fr';%'newton'; fun=@fun6; x=0:0.1:10; y=0:0.1:10; x0=[2.5,1]'; % fun=@fun5; % x=0.5:0.01:2; % y=0.5:0.01:2; % x0=[1.2,1.2]'; %fun=@fun10; %x0=[1,1,1]'; n=length(x0); if n~=2 draw=0; end if draw close all; [xx,yy]=meshgrid(x,y); [f,c]=size(xx); for i=1:f for j=1:c f(i,j)=fun([xx(i,j),yy(i,j)]); end end mesh(xx,yy,f); set(gca,'FontSize',14); xlabel('x1');ylabel('x2');zlabel('f(x1,x2)'); figure; contour(xx,yy,f,'ShowText','on'); set(gca,'FontSize',14); xlabel('x1');ylabel('x2'); end switch method case 'sd' [xn,yn,index]=stepestdescendent(fun,x0,L,draw,tpause); case 'newton' [xn,yn,index]=newton(fun,x0,draw,tpause); case 'fr' [xn,yn,index]=fletches_reeves(fun,x0,L,draw,tpause); case 'powell' [xn,yn,index]=powell(fun,x0,L,draw,tpause); end