function matlab7() global count countmax close all; functions = {@easy,@difficult}; for i=1:length(functions) u = functions{i}; count = 0; countmax = 100000; xi = -2:.1:2; [X Y Z] = meshgrid(xi,xi,xi); U = u(X,Y,Z); figure; slice(X,Y,Z,U,[-1.2,.8,2],[2],[-2]) fprintf('\n Count %d : Global minimum = %14.7e',count,min(min(min(U)))); count = 0; countmax = 200; [x,y,z] = minimumSearch(u); fprintf('\n ------------------------\n (x,y,z) = %14.7e %14.7e %14.7e \n',x,y,z) fprintf('\n Count %d : Obtained value = %14.7e \n',count,u(x,y,z)) end end function u = easy(x,y,z) global count countmax; count = count+ prod(size(x)); if (count > countmax) error('Too many evaluations : my poor guy !'); end u = (x-0.1).^2 + (y - 0.4).^2 + (z - 0.3).^2; end function u = difficult(x,y,z) global count countmax; count = count+ prod(size(x)); if (count > countmax) error('Too many evaluations : my poor guy !'); end u = sin(3*y-x.^2+1)+7 *cos(2*y.^2-2*x)+ 4 *sin(3*y-z.^2+1) + 2* cos(2*y.^2-2*z); end