The recommended way to set 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 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);
To reset an option to its default, use resetoptions
.
options = resetoptions(options,'StepTolerance');
Reset more than one option at a time by passing a cell array of option names, such as
{'Algorithm','StepTolerance'}
.
Note
Ensure that you pass options
in your solver call, as shown in
this example.
[x,fval] = fmincon(@objfun,x0,[],[],[],[],lb,ub,@nonlcon,options);
You can also set and change options using the Optimize Live Editor Task.
Optimize | optimoptions
| resetoptions