Documentation

Plot Functions

What Is a Plot Function?

ThePlotFcnsfield of theoptionsstructure 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 thePlotFcnsoption with the following MATLAB®optimization functions:

The predefined plot functions for these optimization functions are:

  • @optimplotxplots the current point

  • @optimplotfvalplots the function value

  • @optimplotfunccountplots 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 usingfminsearchwith the plot function@optimplotfval:

  1. 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;
  2. Set the options to use the plot function:

    options = optimset('PlotFcns',@optimplotfval);
  3. Callfminsearchstarting from [2,1]:

    [x ffinal] = fminsearch(@onehump,[2,1],options)
  4. MATLAB returns the following:

    x = -0.6691 - 0.0000 ffinal = -0.4052

Related Topics