Plot Functions
What Is a Plot Function?
ThePlotFcns
field of theoptions
structure specifies one or more functions that an optimization function calls at each iteration to plot various measures of progress. Pass a function handle or cell array of function handles. The structure of a plot function is the same as the structure of an output function. For more information on this structure, seeOutput Functions.
You can use thePlotFcns
option with the following MATLAB®optimization functions:
The predefined plot functions for these optimization functions are:
@optimplotx
plots the current point@optimplotfval
plots the function value@optimplotfunccount
plots the function count (not available forfzero
)
To view or modify a predefined plot function, open the function file in the MATLAB Editor. For example, to view the function file for plotting the current point, enter:
edit optimplotx.m
Example: Plot Function
View the progress of a minimization usingfminsearch
with the plot function@optimplotfval
:
Write a file for the objective function. For this example, use:
function f = onehump(x) r = x(1)^2 + x(2)^2; s = exp(-r); f = x(1)*s+r/20;
Set the options to use the plot function:
options = optimset('PlotFcns',@optimplotfval);
Call
fminsearch
starting from [2,1]:[x ffinal] = fminsearch(@onehump,[2,1],options)
MATLAB returns the following:
x = -0.6691 - 0.0000 ffinal = -0.4052