quadprog 'trust-reg​ion-reflec​tive' algorithm error

13 次查看(过去 30 天)
Hello, I get an error using the "trust region reflective" algorithm for a quadratic problem:
Error using quadprog (line 406)
Option Algorithm = 'trust-region-reflective' but this algorithm does not solve
problems with the constraints you have specified. Run a different algorithm by
setting the Algorithm option. For information on applicable algorithms, see
Choosing the Algorithm in the documentation.
Unfortunately the problem in not convex, so no other algorithms are available, a minimal example code is the following:
H=[1 0;0 -1 ];
f = zeros(2,1);
A=[1 1];
b=1.2;
lb = zeros(2,1);
ub = ones(2,1);
x0=(ub+lb)/2;
options=optimoptions('quadprog','Algorithm','trust-region-reflective');
x = quadprog(H,f,A,b,[],[],[],[],x0,options);
as far as I can understand, the only limit to the use of this algorithm is that only equality constraints or bound constraints can be used but not both.
The only way to make quadprog work is removing the linear bounds (A and b), not very useful. But the problem has no equality constraints (Aeq=[],beq=[]) so I don't understand the error. Thank you for any advice

采纳的回答

Matt J
Matt J 2017-11-30
编辑:Matt J 2017-11-30
Apparently, the structure of your problem is outside the scope of quadprog, but there is always fmincon,
[x,fval,exitflag,output] = fmincon(@(x) x.'*H*x/2+f'*x ,x0,A,b,[],[],lb,ub);
Naturally, I would recommend that you improve the implementation of the objective function, incorporating also the SpecifyObjectiveGradient option.
  1 个评论
nikio
nikio 2017-12-1
编辑:nikio 2017-12-1
This solves the problem!
By the way I'm not sure on how to use the objective gradient: is it sufficient to set as true the SpecifyObjectiveGradient option or should I calculate the gradient and give it as an input somewhere?
[EDIT]:
I found an example in fmincon help, at the "include gradient" section:
it is necessary to calculate the gradient and to build a function with two outputs, one for the objective function and one for the gradient

请先登录,再进行评论。

更多回答(1 个)

Kaushik Lakshminarasimhan
As you said, the only limit to the use of this algorithm is that only equality constraints or bound constraints can be used but not both.
So, you can specify either Aeq & beq, or LB & UB, but not both. In your implementation, you are specifying inequality constraints ( A and b ). These are not the same as bound constraints which is why you're getting the error. If your problem is not convex, you can try this (untested) code: https://github.com/xiawei918/quadprogIP
  1 个评论
nikio
nikio 2017-12-1
As I needed a quick 'sure' and portable solution, I preferred fmincon, anyway I'll test soon the alternative function you suggested because I suppose it should work better on quadratic functions, thank you.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Quadratic Programming and Cone Programming 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by