Documentation Center

  • Trial Software
  • Product Updates

Set Options

How to Set Options

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');

Options Table

OptionDescriptionSolvers

Display

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 Iterative Display.

  • 'off' displays no intermediate steps.

  • 'final' displays just the final output.

fminbnd, fminsearch, fzero, lsqnonneg

FunValCheck

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

MaxFunEvals

The maximum number of function evaluations allowed. The default value is 500 for fminbnd and 200*length(x0) for fminsearch.

fminbnd, fminsearch

MaxIter

The maximum number of iterations allowed. The default value is 500 for fminbnd and 200*length(x0) for fminsearch.

fminbnd, fminsearch

OutputFcn

Display information on the iterations of the solver. The default is [] (none). See Output Functions.

fminbnd, fminsearch, fzero

PlotFcns

Plot information on the iterations of the solver. The default is [] (none). For available predefined functions, see Plot Functions.

fminbnd, fminsearch, fzero

TolFun

The termination tolerance for the function value. The default value is 1.e-4. See Tolerances and Stopping Criteria.

fminsearch

TolX

The termination tolerance for x. The default value is 1.e-4. See Tolerances and Stopping Criteria.

fminbnd, fminsearch, fzero, lsqnonneg

Tolerances and Stopping Criteria

The number of iterations in an optimization depends on a solver's stopping criteria. 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 doesn't 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.

  • TolX is a lower bound on the size of a step, meaning the norm of (xi – xi+1). If the solver attempts to take a step that is smaller than TolX, the iterations end. Solvers sometimes use TolX as a relative bound, meaning iterations end when |(xi – xi+1)| < TolX*(1 + |xi|), or a similar relative measure.

  • TolFun is a lower bound on the change in the value of the objective function during a step. If |f(xi) – f(xi+1)| < TolFun, the iterations end. Solvers sometimes use TolFun as a relative bound, meaning iterations end when |f(xi) – f(xi+1)| < TolFun(1 + |f(xi)|), or a similar relative measure.

  • MaxIter is a bound on the number of solver iterations. MaxFunEvals is a bound on the number of function evaluations.

Output Structure

The output structure includes the number of function evaluations, the number of iterations, and the algorithm. The structure appears when you provide fminbnd or fminsearch with a fourth output argument, as in

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

or

[x,fval,exitflag,output] = fminsearch(@three_var,v);

The output structure is not an option that you choose with optimset. It is an optional output for fminbnd and fminsearch.

Was this topic helpful?