Main Content

You can specify optimization parameters using an `options`

structure
that you create using the `optimset`

function.
You then pass `options`

as an input to the optimization
function, for example, by calling `fminbnd`

with
the syntax

x = fminbnd(fun,x1,x2,options)

or `fminsearch`

with the syntax

x = fminsearch(fun,x0,options)

For example, to display output from the algorithm at each iteration,
set the `Display`

option to `'iter'`

:

options = optimset('Display','iter');

Option | Description | Solvers |
---|---|---|

| A flag indicating whether intermediate steps appear on the screen. `'notify'` (default) displays output only if the function does not converge.`'iter'` displays intermediate steps (not available with`lsqnonneg` ). See Optimization Solver Iterative Display.`'off'` or`'none'` displays no intermediate steps.`'final'` displays just the final output.
| `fminbnd` , `fminsearch` , `fzero` , `lsqnonneg` |

| Check whether objective function values are valid. `'on'` displays an error when the objective function or constraints return a value that is complex or`NaN` .`'off'` (default) displays no error.
| `fminbnd` , `fminsearch` , `fzero` |

| The maximum number of function evaluations allowed. The
default value is | `fminbnd` , `fminsearch` |

| The maximum number of iterations allowed. The default
value is | `fminbnd` , `fminsearch` |

| Display information on the iterations of the solver.
The default is | `fminbnd` , `fminsearch` , `fzero` |

| Plot information on the iterations of the solver. The
default is | `fminbnd` , `fminsearch` , `fzero` |

| The termination tolerance for the function value. The
default value is | `fminsearch` |

| The termination tolerance for | `fminbnd` , `fminsearch` , `fzero` , `lsqnonneg` |

The number of iterations in an optimization depends on the *stopping
criteria* for the solver. These criteria include several *tolerances* you
can set. Generally, a tolerance is a threshold which, if crossed,
stops the iterations of a solver.

**Tip**

Generally, set the `TolFun`

and `TolX`

tolerances to well
above `eps`

, and usually above `1e-14`

.
Setting small tolerances does not guarantee accurate results. Instead, a solver
can fail to recognize when it has converged, and can continue futile iterations.
A tolerance value smaller than `eps`

effectively disables that
stopping condition. This tip does not apply to `fzero`

, which
uses a default value of `eps`

for
`TolX`

.

`TolX`

is a lower bound on the size of a step, meaning the norm of (*x*–_{i}*x*_{i+1}). If the solver attempts to take a step that is smaller than`TolX`

, the iterations end. Solvers generally use`TolX`

as a*relative*bound, meaning iterations end when |(*x*–_{i}*x*_{i+1})| <`TolX`

*(1 + |*x*|), or a similar relative measure._{i}`TolFun`

is a lower bound on the change in the value of the objective function during a step. If |*f*(*x*) –_{i}*f*(*x*_{i+1})| <`TolFun`

, the iterations end. Solvers generally use`TolFun`

as a*relative*bound, meaning iterations end when |*f*(*x*) –_{i}*f*(*x*_{i+1})| <`TolFun`

(1 + |*f*(*x*)|), or a similar relative measure._{i}`MaxIter`

is a bound on the number of solver iterations.`MaxFunEvals`

is a bound on the number of function evaluations.

**Note**

Unlike other solvers, `fminsearch`

stops
when it satisfies *both* `TolFun`

and `TolX`

.

The `output`

structure includes the number
of function evaluations, the number of iterations, and the algorithm.
The structure appears when you provide `fminbnd`

, `fminsearch`

, or `fzero`

with
a fourth output argument, as in

[x,fval,exitflag,output] = fminbnd(@humps,0.3,1);

The details of the `output`

structure for each
solver are on the function reference pages.

The `output`

structure is not an option that
you choose with `optimset`

. It is an optional output
for `fminbnd`

, `fminsearch`

,
and `fzero`

.