## Optimization Solver Plot Functions

### What Is a Plot Function?

The `PlotFcns` field of the `options` 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, see Optimization Solver Output Functions.

You can use the `PlotFcns` 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 for `fzero`)

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 using `fminsearch` with 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. Call `fminsearch` starting from [2,1]:

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

```x = -0.6691 0.0000 ffinal = -0.4052``` 