QP with quadratic constraints using fmincon

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 ?

 Accepted Answer

Matt J
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

Thanks for your code.
I forgot to mention that Q is p.s.d and there will be no inequality constraints. My Q is large, of the order of 4096-by-4096. If I use my code, will I get incorrect answers ? I tried running my code and the solution vector x does not satisfy norm(x,2)-1 = 0
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.

Sign in to comment.

More Answers (0)

Categories

Asked:

on 1 Nov 2013

Edited:

on 16 Nov 2021

Community Treasure Hunt

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

Start Hunting!