%% Monitor Optimization Process
% Set options to monitor the process as fminsearch attempts to locate a minimum.
% Set options to plot the objective function at each iteration.

options = optimset('PlotFcns',@optimplotfval);

% Set the objective function to Rosenbrock's function,
% f(x) = 100(x_2 - x_1^2)^2 + (1 - x_1)^2.
% The function is minimized at the point x = [1,1] with minimum value 0.
%
% Set the start point to x0 = [-1.2,1] and minimize Rosenbrock's function using fminsearch.

fun = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
x0 = [-1.2,1];
x = fminsearch(fun,x0,options)

% Copyright 2012 The MathWorks, Inc.