optimset
Create or modify optimization options structure
Syntax
Description
returns options
= optimset(Name,Value
)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.
(with no input
arguments) creates an options structure options
= optimsetoptions
where all
parameters are set to []
.
creates a copy of options
= optimset(oldopts
,Name,Value
)oldopts
and modifies the specified parameters
using one or more name-value pair arguments.
Examples
Create Nondefault Options
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)
x = 1×2
1.0000 1.0000
fval = 4.7305e-16
Create Default Options for Solver
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
Modify Options
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
Update Options Structure Using New Options Structure
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
optimfun
— Optimization solver
name | function handle
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
oldopts
— Previous optimization options
structure
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
newopts
— New optimization options
structure
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.
Display
— Level of display
'notify'
(default) | 'final'
| 'off'
| 'none'
| 'iter'
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
FunValCheck
— Flag to check whether function values are valid
'off'
(default) | 'on'
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
MaxFunEvals
— Maximum number of function evaluations
500
for fminbnd
, 200*(number of variables)
for fminsearch
(default) | positive integer
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
MaxIter
— Maximum number of iterations
500
for fminbnd
, 200*(number of variables)
for fminsearch
(default) | positive integer
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
OutputFcn
— Output function
[]
(default) | function name | function handle | cell array of function handles
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
PlotFcns
— Plot functions
[]
(default) | function name | function handle | cell array of function handles
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 forfzero
).
PlotFcns
is available for
fminbnd
, fminsearch
, and
fzero
.
Example: options =
optimset('PlotFcns','optimplotfval')
Data Types: char
| string
| cell
| function_handle
TolFun
— Termination tolerance on function value
1e-4
(default) | nonnegative scalar
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
TolX
— Termination tolerance on x
, the current point
1e-4
for fminbnd
and fminsearch
, eps
for
fzero
,
10*eps*norm(c,1)*length(c)
for
lsqnonneg
(default) | nonnegative scalar
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
options
— Optimization options
structure
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
, andlsqnonneg
. To set options for Optimization Toolbox™ or Global Optimization Toolbox solvers, the recommended function isoptimoptions
(Optimization Toolbox).optimset
cannot set options for some Optimization Toolbox solvers, such asintlinprog
. Useoptimoptions
(Optimization Toolbox) instead.optimset
cannot set most options for Global Optimization Toolbox solvers. Useoptimoptions
(Optimization Toolbox) instead.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Code generation does not support the syntax that has no input or output arguments:
optimset
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.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced before R2006a
See Also
optimget
| fminbnd
| fminsearch
| fzero
| lsqnonneg
| optimoptions
(Optimization Toolbox)
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)