Set and Change Options
The recommended way to set options is to use theoptimoptions
function. For example, the following code sets thefmincon
algorithm tosqp
, specifies iterative display, and sets a small value for theConstraintTolerance
tolerance.
options = optimoptions('fmincon',...'Algorithm','sqp','Display','iter','ConstraintTolerance',1e-12);
Note
Useoptimset
instead ofoptimoptions
for thefminbnd
,fminsearch
,fzero
, andlsqnonneg
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 usingoptimoptions
.
options = optimoptions(options,'StepTolerance',1e-10);
Note
Ensure that you passoptions
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, useresetoptions
.
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 theOptimizeLive Editor task.
See Also
optimoptions
|resetoptions
|Optimize