optimset - Create or modify optimization options structure - MATLAB (original) (raw)

Create or modify optimization options structure

Syntax

Description

Create or modify options structure for MATLAB® solvers.

Note

optimoptions is recommended instead ofoptimset for all solvers except fzero,fminbnd, fminsearch, andlsqnonneg.

[options](#mw%5F26a029c3-04d6-4e6c-a96a-4deab77331b8) = optimset([Name,Value](#namevaluepairarguments)) 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](#mw%5F26a029c3-04d6-4e6c-a96a-4deab77331b8) = optimset (with no input arguments) creates an options structure options where all parameters are set to [].

[options](#mw%5F26a029c3-04d6-4e6c-a96a-4deab77331b8) = optimset([optimfun](#mw%5Fba9d19cb-7610-4f75-8bad-588ab9e7ec5e)) creates options with all parameter names and default values relevant to the optimization function optimfun.

example

[options](#mw%5F26a029c3-04d6-4e6c-a96a-4deab77331b8) = optimset([oldopts](#mw%5F07aa037e-1d1a-46b7-b67b-550ae5f73f14),[Name,Value](#namevaluepairarguments)) creates a copy of oldopts and modifies the specified parameters using one or more name-value pair arguments.

example

[options](#mw%5F26a029c3-04d6-4e6c-a96a-4deab77331b8) = optimset([oldopts](#mw%5F07aa037e-1d1a-46b7-b67b-550ae5f73f14),[newopts](#mw%5F9ba5e496-0144-47a1-af16-45410132f87d)) combines an existing options structure oldopts with a new options structure newopts. Any parameters in newopts with nonempty values overwrite the corresponding parameters inoldopts.

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.

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

options = optimset('fzero');

View the default value of the TolX option for fzero.

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.

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.

Check the values of the other two options.

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 outputoptions 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 outputoptions 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

collapse all

Specify optional pairs of arguments asName1=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:

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 orNaN.

FunValCheck is available forfminbnd, fminsearch, andfzero.

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 forfminbnd andfminsearch.

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 forfminbnd andfminsearch.

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 forfminbnd, fminsearch, andfzero.

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 Plot Functions and Output Function and Plot Function Syntax.

The built-in plot functions are as follows:

PlotFcns is available forfminbnd, fminsearch, andfzero.

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 forfminsearch 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 thanTolX, relative to the size ofx. 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. The returned values for parameters you do not set are [], which cause solvers to use the default values of these parameters.

Limitations

Extended Capabilities

expand all

Usage notes and limitations:

Version History

Introduced before R2006a