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

14 ビュー (過去 30 日間)
nikio
nikio 2017 年 11 月 30 日
編集済み: nikio 2017 年 12 月 1 日
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
Kaushik Lakshminarasimhan 2017 年 11 月 30 日
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 Center および File ExchangeQuadratic 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