Set and Change Optimization Options
The recommended way to set optimization options is to use the optimoptions
function. For example, the following code sets the
fmincon
algorithm to sqp
, specifies
iterative display, and sets a small value for the ConstraintTolerance
tolerance.
options = optimoptions('fmincon',... 'Algorithm','sqp','Display','iter','ConstraintTolerance',1e-12);
Note
Use optimset
instead of
optimoptions
for the fminbnd
,
fminsearch
, fzero
, and
lsqnonneg
solvers. These are the solvers that do not
require an Optimization Toolbox™ license.
You can change options in several ways. For example, you can use dot notation.
options.StepTolerance = 1e-10;
Or, you can change options using optimoptions
.
options = optimoptions(options,'StepTolerance',1e-10);
Note
Ensure that you pass options
in your solver call, as shown in
this example.
[x,fval] = fmincon(@objfun,x0,[],[],[],[],lb,ub,@nonlcon,options);
To reset an option to its default value, use resetoptions
.
options = resetoptions(options,'StepTolerance');
Reset more than one option at a time by passing a cell array of option names.
options = resetoptions(options,{'Algorithm','StepTolerance'});
You can also set and change options using the Optimize Live Editor task.
See Also
optimoptions
| resetoptions
| Optimize