QP with quadratic constraints using fmincon
9 views (last 30 days)
Show older comments
I have to compute an objective function asfollows :
min q(y) = 0.5*y'*Q*y + f'y
subject to norm(y,2)=1
I am using the following code in matlab
options=optimoptions('fmincon','Algorithm','interior-point');
[x,fval] = fmincon(@(x)(0.5*x'*Q*x + F'*x),x0,[],[],[],[],[], [],@nonlncon,options);
function [c,ceq ] = nonlncon(x )
c = [];
ceq = norm(x,2)-1;
end
Is this formulation correct ?
0 Comments
Accepted Answer
Matt J
on 1 Nov 2013
Edited: Matt J
on 16 Nov 2021
It might be a bit safer to formulate ceq differentiably
ceq=norm(x)^2-1
You could also consider providing gradient calculations for the objective function and constraints, since the formulae for those are fairly simple.
Lastly, I would point out that the problem has a closed form solution, which you might consider if your problem dimension is not too large,
2 Comments
Matt J
on 1 Nov 2013
Edited: Matt J
on 1 Nov 2013
I forgot to mention that Q is p.s.d and there will be no inequality constraints.
No harm that you didn't. It doesn't affect my response above.
fmincon might work better with the following options
options=optimoptions(@fmincon,'GradObj','on','GradConstr','on','Algorithm','interior-point','Display','off');
and by providing analytical gradients as I mentioned earlier. You should, of course, always run with at least 4 arguments
[x,fval, exitflag, output]=fmincon(...)
and use exitflag/output to check that the optimization was successful.
More Answers (0)
See Also
Categories
Find more on Quadratic Programming and Cone Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!