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.
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
.
[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.
[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
.
Examples
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)
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
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
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:
'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 forlsqnonneg
).
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:
@optimplotx
plots the current point.@optimplotfval
plots the function value.@optimplotfunccount
plots the function count (not available forfzero
).
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
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
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.optimset
cannot set options for some Optimization Toolbox solvers, such asintlinprog
. Use optimoptions instead.optimset
cannot set most options for Global Optimization Toolbox solvers. Use optimoptions instead.
Extended Capabilities
Usage notes and limitations:
- Code generation does not support the syntax that has no input or output arguments:
- Functions specified in
options
must be supported for code generation. - The input argument
optimfun
must be a function that is supported for code generation. - The fields of the options structure
oldopts
must be fixed-size fields. - Code generation ignores the
Display
option. - Code generation does not support the additional options in an options structure created by the Optimization Toolbox
optimset
function. If an input options structure includes the additional Optimization Toolbox options, then the output structure does not include them.
Version History
Introduced before R2006a