Main Content

optimset

Create or modify optimization options structure

Description

options = optimset(Name,Value) returns options with specified parameters set using one or more name-value pair arguments.

example

optimset (with no input or output arguments) displays a complete list of parameters with their valid values.

options = optimset (with no input arguments) creates an options structure options where all parameters are set to [].

options = optimset(optimfun) creates options with all parameter names and default values relevant to the optimization function optimfun.

example

options = optimset(oldopts,Name,Value) creates a copy of oldopts and modifies the specified parameters using one or more name-value pair arguments.

example

options = optimset(oldopts,newopts) combines an existing options structure oldopts with a new options structure newopts. Any parameters in newopts with nonempty values overwrite the corresponding parameters in oldopts.

example

Examples

collapse all

Set options for fminsearch to use a plot function and a stricter stopping condition than the default.

options = optimset('PlotFcns','optimplotfval','TolX',1e-7);

Minimize Rosenbrock's function starting from the point (–1,2), and monitor the minimization process by using the options. Rosenbrock's function has a minimum value of 0 at the point (1,1).

fun = @(x)100*((x(2) - x(1)^2)^2) + (1 - x(1))^2; % Rosenbrock's function
x0 = [-1,2];
[x,fval] = fminsearch(fun,x0,options)

Figure Optimization Plot Function contains an axes object. The axes object with title Current Function Value: 4.73054e-16, xlabel Iteration, ylabel Function value contains an object of type scatter.

x = 1×2

    1.0000    1.0000

fval = 
4.7305e-16

Create a structure containing the default options for the fzero solver.

options = optimset('fzero');

View the default value of the TolX option for fzero.

tol = options.TolX
tol = 
2.2204e-16

Set options to use a function tolerance of 1e-6.

oldopts = optimset('TolFun',1e-6);

Modify options in oldopts to use the 'optimplotfval' plot function and a TolX value of 1e-6.

options = optimset(oldopts,'PlotFcns','optimplotfval','TolX',1e-6);

View the three options that you set.

disp(options.TolFun);
   1.0000e-06
disp(options.PlotFcns);
optimplotfval
disp(options.TolX);
   1.0000e-06

Overwrite the corresponding parts of one options structure with a different options structure by using optimset.

oldopts = optimset('Display','iter','TolX',1e-6);
newopts = optimset('PlotFcns','optimplotfval','Display','off');
options = optimset(oldopts,newopts);

Both oldopts and newopts set the value of the Display option. Check that newopts overwrites oldopts for this option.

options.Display
ans = 
'off'

Check the values of the other two options.

options.TolX
ans = 
1.0000e-06
options.PlotFcns
ans = 
'optimplotfval'

Input Arguments

collapse all

Optimization solver, specified as a name or function handle. The returned options structure has nonempty entries for the specified solver only.

Example: options = optimset('fzero')

Example: options = optimset(@fminsearch)

Data Types: char | string | function_handle

Previous optimization options, specified as a structure. The output options is the same as oldopts, except for the specified parameters.

Example: options = optimset(oldopts,'TolX',1e-6)

Data Types: struct

New optimization options, specified as a structure. The output options is the same as newopts, and also includes nonempty parameters of oldopts that are empty in newopts.

Example: options = optimset(oldopts,newopts)

Data Types: struct

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: options = optimset('TolX',1e-6,'PlotFcns',@optimplotfval)

You only need to enter enough leading characters to define the option name uniquely. optimset ignores the case (uppercase or lowercase) for option names.

Level of display, specified as the comma-separated pair consisting of 'Display' and one of these values:

  • 'notify' — Display output only if the function does not converge.

  • 'final' — Display just the final output.

  • 'off' or 'none' — Display no output.

  • 'iter' — Display output at each iteration (not available for lsqnonneg).

Display is available for all optimization solvers.

Example: options = optimset('Display','iter')

Data Types: char | string

Flag to check whether function values are valid, specified as the comma-separated pair consisting of 'FunValCheck' and the value 'off' or 'on'. When the value is 'on', solvers display an error when the objective function returns a value that is complex or NaN.

FunValCheck is available for fminbnd, fminsearch, and fzero.

Example: options = optimset('FunValCheck','on')

Data Types: char | string

Maximum number of function evaluations, specified as the comma-separated pair consisting of 'MaxFunEvals' and a positive integer.

MaxFunEvals is available for fminbnd and fminsearch.

Example: options = optimset('MaxFunEvals',2e3)

Data Types: single | double

Maximum number of iterations, specified as the comma-separated pair consisting of 'MaxIter' and a positive integer.

MaxIter is available for fminbnd and fminsearch.

Example: options = optimset('MaxIter',2e3)

Data Types: single | double

Output function, specified as the comma-separated pair consisting of 'OutputFcn' and a function name or function handle. Specify multiple output functions as a cell array of function handles. An output function runs after each iteration, enabling you to monitor the solution process or stop the iterations. For more information, see Optimization Solver Output Functions.

OutputFcn is available for fminbnd, fminsearch, and fzero.

Example: options = optimset('OutputFcn',{@outfun1,@outfun2})

Data Types: char | string | cell | function_handle

Plot functions, specified as the comma-separated pair consisting of 'PlotFcns' and a function name or function handle. Specify multiple plot functions as a cell array of function handles. A plot function runs after each iteration, enabling you to monitor the solution process or stop the iterations. For more information, see Optimization Solver Plot Functions.

The built-in plot functions are as follows:

  • @optimplotx plots the current point.

  • @optimplotfval plots the function value.

  • @optimplotfunccount plots the function count (not available for fzero).

PlotFcns is available for fminbnd, fminsearch, and fzero.

Example: options = optimset('PlotFcns','optimplotfval')

Data Types: char | string | cell | function_handle

Termination tolerance on the function value, specified as the comma-separated pair consisting of 'TolFun' and a nonnegative scalar. Iterations end when the current function value differs from the previous value by less than TolFun, relative to the initial function value. See Tolerances and Stopping Criteria.

TolFun is available for fminsearch only.

Example: options = optimset('TolFun',2e-6)

Data Types: single | double

Termination tolerance on x, the current point, specified as the comma-separated pair consisting of 'TolX' and a nonnegative scalar. Iterations end when the current point differs from the previous point by less than TolX, relative to the size of x. See Tolerances and Stopping Criteria.

TolX is available for all solvers.

Example: options = optimset('TolX',2e-6)

Data Types: single | double

Output Arguments

collapse all

Optimization options, returned as a structure. Values for parameters you do not set are [], which causes solvers to use the default values of these parameters.

Limitations

  • optimset sets options for the four MATLAB® optimization solvers: fminbnd, fminsearch, fzero, and lsqnonneg. To set options for Optimization Toolbox™ or Global Optimization Toolbox solvers, the recommended function is optimoptions (Optimization Toolbox).

  • optimset cannot set options for some Optimization Toolbox solvers, such as intlinprog. Use optimoptions (Optimization Toolbox) instead.

  • optimset cannot set most options for Global Optimization Toolbox solvers. Use optimoptions (Optimization Toolbox) instead.

Extended Capabilities

Version History

Introduced before R2006a