www.gusucode.com > globaloptim 案例源码程序 matlab代码 > globaloptim/ObtainAllPSOutputsExample.m

    %% Obtain All Outputs  
% To examine the |patternsearch| solution process, obtain all outputs.   

%% 
% Create the following two-variable objective function. On your MATLAB(R)
% path, save the following code to a file named |psobj.m|. 
%
% <include>psobj.m</include>
%
%% 
% Set the objective function to |@psobj|. 
fun = @psobj;  

%% 
% Find the unconstrained minimum of the objective, starting from the point
% |[0,0]|. Return the solution, |x|, the objective function value at the
% solution, |fun(x)|, the exit flag, and the output structure. 
x0 = [0,0];
[x,fval,exitflag,output] = patternsearch(fun,x0) 

%%
% The |exitflag| is |1|, indicating convergence to a local minimum. 

%%
% The |output| structure includes information such as how many iterations
% |patternsearch| took, and how many function evaluations. Compare this
% output structure with the results from <docid:gads.buxe8xt-5>. In
% that example, you obtain some of this information, but did not obtain,
% for example, the number of function evaluations.