www.gusucode.com > optim 案例源码 matlab代码程序 > optim/ExamineTheSolutionProcessExample.m

    %% Examine the Solution Process
% Choose |fminunc| options and outputs to examine the solution process.
%%
% Set options to obtain iterative display and use the |'quasi-newton'|
% algorithm.

% Copyright 2015 The MathWorks, Inc.

options = optimoptions(@fminunc,'Display','iter','Algorithm','quasi-newton');
%%
% The objective function is
%
% $$f(x) = x(1){e^{ - \left\| x \right\|_2^2}} + \left\| x
% \right\|_2^2/20.$$
fun = @(x)x(1)*exp(-(x(1)^2 + x(2)^2)) + (x(1)^2 + x(2)^2)/20;
%%
% Start the minimization at |x0 = [1,2]|, and obtain outputs that enable
% you to examine the solution quality and process.
x0 = [1,2];
[x,fval,exitflag,output] = fminunc(fun,x0,options)
%%
% * The exit flag |1| shows that the solution is a local optimum.
% * The |output| structure shows the number of iterations, number of
% function evaluations, and other information.
% * The iterative display also shows the number of iterations and function
% evaluations.