optimoptions
Create optimization options
Syntax
Description
returns a set of default options for theoptions
= optimoptions(SolverName
)SolverName
solver.
returnsoptions
= optimoptions(SolverName
,Name,Value
)options
with specified parameters set using one or more name-value pair arguments.
returns a copy ofoptions
= optimoptions(oldoptions
,Name,Value
)oldoptions
with the named parameters altered with the specified values.
returns default options for theoptions
= optimoptions(SolverName
,oldoptions
)SolverName
solver, and copies the applicable options inoldoptions
tooptions
.
Examples
Create Default Options
Create default options for thefmincon
solver.
options = optimoptions('fmincon')
选择= fmincon选项:选择使用的电流Algorithm ('interior-point'): (Other available algorithms: 'active-set', 'sqp', 'sqp-legacy', 'trust-region-reflective') Set properties: No options set. Default properties: Algorithm: 'interior-point' BarrierParamUpdate: 'monotone' CheckGradients: 0 ConstraintTolerance: 1.0000e-06 Display: 'final' EnableFeasibilityMode: 0 FiniteDifferenceStepSize: 'sqrt(eps)' FiniteDifferenceType: 'forward' HessianApproximation: 'bfgs' HessianFcn: [] HessianMultiplyFcn: [] HonorBounds: 1 MaxFunctionEvaluations: 3000 MaxIterations: 1000 ObjectiveLimit: -1.0000e+20 OptimalityTolerance: 1.0000e-06 OutputFcn: [] PlotFcn: [] ScaleProblem: 0 SpecifyConstraintGradient: 0 SpecifyObjectiveGradient: 0 StepTolerance: 1.0000e-10 SubproblemAlgorithm: 'factorization' TypicalX: 'ones(numberOfVariables,1)' UseParallel: 0 Show options not used by current Algorithm ('interior-point')
Create Nondefault Options
Set options forfmincon
to use thesqp
algorithm and at most 1500 iterations.
options = optimoptions(@fmincon,'Algorithm','sqp','MaxIterations',1500)
选择= fmincon选项:选择使用的电流Algorithm ('sqp'): (Other available algorithms: 'active-set', 'interior-point', 'sqp-legacy', 'trust-region-reflective') Set properties: Algorithm: 'sqp' MaxIterations: 1500 Default properties: CheckGradients: 0 ConstraintTolerance: 1.0000e-06 Display: 'final' FiniteDifferenceStepSize: 'sqrt(eps)' FiniteDifferenceType: 'forward' MaxFunctionEvaluations: '100*numberOfVariables' ObjectiveLimit: -1.0000e+20 OptimalityTolerance: 1.0000e-06 OutputFcn: [] PlotFcn: [] ScaleProblem: 0 SpecifyConstraintGradient: 0 SpecifyObjectiveGradient: 0 StepTolerance: 1.0000e-06 TypicalX: 'ones(numberOfVariables,1)' UseParallel: 0 Show options not used by current Algorithm ('sqp')
Update Options
Update existing options with new values.
Set options for thelsqnonlin
solver to use thelevenberg-marquardt
algorithm and at most 1500 function evaluations
oldoptions = optimoptions(@lsqnonlin,'Algorithm','levenberg-marquardt',...“MaxFunctionEvaluations',1500)
oldoptions = lsqnonlin options: Options used by current Algorithm ('levenberg-marquardt'): (Other available algorithms: 'trust-region-reflective') Set properties: Algorithm: 'levenberg-marquardt' MaxFunctionEvaluations: 1500 Default properties: CheckGradients: 0 Display: 'final' FiniteDifferenceStepSize: 'sqrt(eps)' FiniteDifferenceType: 'forward' FunctionTolerance: 1.0000e-06 MaxIterations: 400 OutputFcn: [] PlotFcn: [] SpecifyObjectiveGradient: 0 StepTolerance: 1.0000e-06 TypicalX: 'ones(numberOfVariables,1)' UseParallel: 0 Show options not used by current Algorithm ('levenberg-marquardt')
IncreaseMaxFunctionEvaluations
to 2000.
options = optimoptions(oldoptions,“MaxFunctionEvaluations',2000)
options = lsqnonlin options: Options used by current Algorithm ('levenberg-marquardt'): (Other available algorithms: 'trust-region-reflective') Set properties: Algorithm: 'levenberg-marquardt' MaxFunctionEvaluations: 2000 Default properties: CheckGradients: 0 Display: 'final' FiniteDifferenceStepSize: 'sqrt(eps)' FiniteDifferenceType: 'forward' FunctionTolerance: 1.0000e-06 MaxIterations: 400 OutputFcn: [] PlotFcn: [] SpecifyObjectiveGradient: 0 StepTolerance: 1.0000e-06 TypicalX: 'ones(numberOfVariables,1)' UseParallel: 0 Show options not used by current Algorithm ('levenberg-marquardt')
Use Dot Notation to Update Options
Update existing options with new values by using dot notation.
Set options for thelsqnonlin
solver to use thelevenberg-marquardt
algorithm and at most 1500 function evaluations
options = optimoptions(@lsqnonlin,'Algorithm','levenberg-marquardt',...“MaxFunctionEvaluations',1500)
options = lsqnonlin options: Options used by current Algorithm ('levenberg-marquardt'): (Other available algorithms: 'trust-region-reflective') Set properties: Algorithm: 'levenberg-marquardt' MaxFunctionEvaluations: 1500 Default properties: CheckGradients: 0 Display: 'final' FiniteDifferenceStepSize: 'sqrt(eps)' FiniteDifferenceType: 'forward' FunctionTolerance: 1.0000e-06 MaxIterations: 400 OutputFcn: [] PlotFcn: [] SpecifyObjectiveGradient: 0 StepTolerance: 1.0000e-06 TypicalX: 'ones(numberOfVariables,1)' UseParallel: 0 Show options not used by current Algorithm ('levenberg-marquardt')
IncreaseMaxFunctionEvaluations
to 2000 by using dot notation.
options.MaxFunctionEvaluations = 2000
options = lsqnonlin options: Options used by current Algorithm ('levenberg-marquardt'): (Other available algorithms: 'trust-region-reflective') Set properties: Algorithm: 'levenberg-marquardt' MaxFunctionEvaluations: 2000 Default properties: CheckGradients: 0 Display: 'final' FiniteDifferenceStepSize: 'sqrt(eps)' FiniteDifferenceType: 'forward' FunctionTolerance: 1.0000e-06 MaxIterations: 400 OutputFcn: [] PlotFcn: [] SpecifyObjectiveGradient: 0 StepTolerance: 1.0000e-06 TypicalX: 'ones(numberOfVariables,1)' UseParallel: 0 Show options not used by current Algorithm ('levenberg-marquardt')
Copy Options to Another Solver
Transfer nondefault options for thefmincon
solver to options for thefminunc
solver.
Set options forfmincon
to use the sqp algorithm and at most 1500 iterations.
oldoptions = optimoptions(@fmincon,'Algorithm','sqp','MaxIterations',1500)
oldoptions = fmincon options: Options used by current Algorithm ('sqp'): (Other available algorithms: 'active-set', 'interior-point', 'sqp-legacy', 'trust-region-reflective') Set properties: Algorithm: 'sqp' MaxIterations: 1500 Default properties: CheckGradients: 0 ConstraintTolerance: 1.0000e-06 Display: 'final' FiniteDifferenceStepSize: 'sqrt(eps)' FiniteDifferenceType: 'forward' MaxFunctionEvaluations: '100*numberOfVariables' ObjectiveLimit: -1.0000e+20 OptimalityTolerance: 1.0000e-06 OutputFcn: [] PlotFcn: [] ScaleProblem: 0 SpecifyConstraintGradient: 0 SpecifyObjectiveGradient: 0 StepTolerance: 1.0000e-06 TypicalX: 'ones(numberOfVariables,1)' UseParallel: 0 Show options not used by current Algorithm ('sqp')
Transfer the applicable options to thefminunc
solver.
options = optimoptions(@fminunc,oldoptions)
options = fminunc options: Options used by current Algorithm ('quasi-newton'): (Other available algorithms: 'trust-region') Set properties: CheckGradients: 0 FiniteDifferenceType: 'forward' MaxIterations: 1500 OptimalityTolerance: 1.0000e-06 PlotFcn: [] SpecifyObjectiveGradient: 0 StepTolerance: 1.0000e-06 Default properties: Algorithm: 'quasi-newton' Display: 'final' FiniteDifferenceStepSize: 'sqrt(eps)' HessianApproximation: 'bfgs' MaxFunctionEvaluations: '100*numberOfVariables' ObjectiveLimit: -1.0000e+20 OutputFcn: [] TypicalX: 'ones(numberOfVariables,1)' UseParallel: 0 Show options not used by current Algorithm ('quasi-newton')
The algorithm option does not transfer tofminunc
because'sqp'
is not a valid algorithm option forfminunc
.
Find Solver and Default Options for Optimization Problem
Create an optimization problem and find the default solver and options.
rngdefaultx = optimvar('x',3,'LowerBound', 0);expr = x ' *(眼(3)+ randn (3)) * x - randn(1、3)*x; prob = optimproblem('Objective',expr); options = optimoptions(prob)
options = quadprog options: Options used by current Algorithm ('interior-point-convex'): (Other available algorithms: 'active-set', 'trust-region-reflective') Set properties: No options set. Default properties: Algorithm: 'interior-point-convex' ConstraintTolerance: 1.0000e-08 Display: 'final' LinearSolver: 'auto' MaxIterations: 200 OptimalityTolerance: 1.0000e-08 StepTolerance: 1.0000e-12 Show options not used by current Algorithm ('interior-point-convex')
The default solver isquadprog
.
Set the options to use iterative display. Find the solution.
options.Display ='iter'; sol = solve(prob,'Options',options);
Solving problem using quadprog. Your Hessian is not symmetric. Resetting H=(H+H')/2. Iter Fval Primal Infeas Dual Infeas Complementarity 0 2.018911e+00 0.000000e+00 2.757660e+00 6.535839e-01 1 -2.170204e+00 0.000000e+00 8.881784e-16 2.586177e-01 2 -3.405808e+00 0.000000e+00 8.881784e-16 2.244054e-03 3 -3.438788e+00 0.000000e+00 3.356690e-16 7.261144e-09 Minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
sol.x
ans =3×11.6035 0.0000 0.8029
Input Arguments
SolverName
—Solver name
character vector|string|function handle
Solver name, specified as a character vector, string, or function handle.
Example:'fmincon'
Example:@fmincon
Data Types:char
|function_handle
|string
oldoptions
—Options created withoptimoptions
options object
Options created with theoptimoptions
function, specified as an options object.
Example:oldoptions = optimoptions(@fminunc)
prob
—Problem object
OptimizationProblem
object|EquationProblem
object
Problem object, specified as anOptimizationProblem
object or anEquationProblem
object. Createprob
using theProblem-Based Optimization WorkfloworProblem-Based Workflow for Solving Equations.
The syntaxes usingprob
enable you to determine the default solver for your problem and to modify the algorithm or other options.
Example:prob = optimproblem('Objective',myobj)
, wheremyobj
is an optimization expression
Name-Value Arguments
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
, whereName
is the argument name andValue
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 encloseName
in quotes.
Example:optimoptions(@fmincon,'Display','iter','FunctionTolerance',1e-10)
setsfmincon
options to have iterative display and aFunctionTolerance
of1e-10
.
For relevant name-value pair arguments, consult the options table for your solver:
fgoalattain
options
fmincon
options
fminimax
options
fminunc
options
fseminf
options
fsolve
options
ga
options
(Global Optimization Toolbox)gamultiobj
options
(Global Optimization Toolbox)intlinprog
options
linprog
options
lsqcurvefit
options
lsqlin
options
lsqnonlin
options
paretosearch
options
(Global Optimization Toolbox)particleswarm
options
(Global Optimization Toolbox)patternsearch
options
(Global Optimization Toolbox)quadprog
options
simulannealbnd
options
(Global Optimization Toolbox)surrogateopt
options
(Global Optimization Toolbox)
Output Arguments
options
— Optimization options
options object
Optimization options for theSolverName
solver, returned as an options object.
Alternative Functionality
Live Editor Task
TheOptimizeLive Editor task lets you set options visually. For an example, seeOptimize Live Editor Task with fmincon Solver.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Code generation supports a limited set of options for each solver. For the supported options, see each solver reference page:
fmincon
Code Generationfsolve
Code Generationlsqcurvefit
Code Generationlsqnonlin
Code Generationquadprog
Code Generation
Version History
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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)