MATLAB Answers


quadprog: can't set options

Asked by Cory
on 18 May 2019 at 6:13
Latest activity Edited by Cory
on 18 May 2019 at 14:27
Hi folks, I'm trying to do some quadratic programming while setting the optimality tolerance and getting a few errors. When I try:
opts = optimoptions(@quadprog,'Algorithm','trust-region-reflective','OptimalityTolerance',1e-10);
[x,fval,flag] = quadprog(Q,L,[],[],[],[],zeros(n,1),ones(n,1),[],opts);
I get the error
Undefined function 'sqrt' for input arguments of type 'char'.
Error in sqpbox (line 73)
tolfun2 = sqrt(tolfunvalue);
Error in sqpmin (line 71)
[x,val,gopt,it,npcg,exitflag,lambda,msg] = sqpbox(c,H,mtxmpy,lb,ub,xstart, ...
Error in quadprog (line 426)
[X,fval,output,exitflag,lambda] = sqpmin(f,H,mtxmpy,X0,Aeq,Beq,lb,ub,verbosity, ...
Error in WelfareAnalysis (line 118)
[x,fval,flag] = quadprog(Q,L,[],[],[],[],zeros(n,1),ones(n,1),[],opts);
Running the algorithm without setting this option has it proceeding normally:
opts = optimoptions(@quadprog,'Algorithm','trust-region-reflective');
[x,fval,flag] = quadprog(Q,L,[],[],[],[],zeros(n,1),ones(n,1),[],opts);
Local minimum possible.
quadprog stopped because the relative change in function value is less than the sqrt of the function tolerance, the rate of change in the function value is slow, and no negative curvature was detected.
Solved unconstrained optimal policy for model 3; exit flag = 3
Why is a character / string being passed along when I set this option? How do I fix the error so I can set the tolerance as I please? Thanks!


What is the message just before that, telling you what kind of error it is? For example is it saying undefined variable tolfunvalue ?
(We do not have your data so we cannot test.)
on 18 May 2019 at 13:55
Sorry about that, I accidentally missed a line in copying the error. I fixed it earlier but in case it's not appearing the error is;
Undefined function 'sqrt' for input arguments of type 'char'.

Sign in to comment.

1 Answer

Answer by Cory
on 18 May 2019 at 14:26
Edited by Cory
on 18 May 2019 at 14:27
 Accepted Answer

Okay, after a lot of trial & error I figured this one out. Here's what the options displays
opts =
quadprog options:
Options used by current Algorithm ('trust-region-reflective'):
(Other available algorithms: 'interior-point-convex')
Set properties:
Algorithm: 'trust-region-reflective'
OptimalityTolerance: 1e-10
Default properties:
Display: 'final'
FunctionTolerance: 'default dependent on problem'
HessianMultiplyFcn: []
MaxIterations: 'default dependent on problem'
StepTolerance: 2.2204e-14
SubproblemAlgorithm: 'cg'
TypicalX: 'ones(numberOfVariables,1)'
In particular,
FunctionTolerance: 'default dependent on problem'
Setting OptimalityTolerance and NOT FunctionTolerance must short-circuit setting FunctionTolerance so it is trying to take sqrt('default dependent on problem') instead of sqrt([default value]). To me this seems like a bug but perhaps someone can explain why it's intended behavior.
The workaround (of course) is to also set FunctionTolerance.


Sign in to comment.