Infeasible but not?

The following is the code I have written. It involves a convex quadratic objective function. I am sure the QP is feasible as I have tried it out using quadprog in matlab. What could be wrong with the format?

lambda=[0.2 -0.2;-0.2 1.4];
G=[-1.35 -1.25;-eye(2)];

%Problem formulation
cvx_begin **
** variable x(2)

** minimize quad_form(x,lambda)**
** subject to**
** Gx<=h;**
** A

fprintf(1,’\nThe minimum return risk is %3.3f.\n’,cvx_optval);

1 Like

I’m sure someone with better experience will help. Is that your actual code? Why are their star characters at the start/end of some of your lines?

Also Gx<=h should be G*x<=h and Ax==b should be A*x==b

Also an output of your error message would help.

The syntax is fine, it just got messed up when I input it into this editor. I don’t know why. Anyway here is a screenshot:

1 Like

I think this may help:

Try rewriting quad_form(x,lambda) as norm(lambsqrt*x), where lambsqrt = “the square root of lambda.” I have used the link above to get this.

NOTE: Take what I say with a grain of salt :wink:


Probably a scaling issue. Rescale your problem so your coefficients are not so large…

1 Like

It worked! Thank you so much! :smile:

Thank you! This also worked :smile:

1 Like

Great. @perplexabot, well done too! Believe it or not, both solutions are related. By replacing your objective with its square root, it is not just in a more natural form for the solver, but it also has fewer scaling issues.


Thank you for sharing the relationship between the two solutions!