# 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?

%Parameters
lambda=[0.2 -0.2;-0.2 1.4];
G=[-1.35 -1.25;-eye(2)];
h=[-12e6;zeros(2,1)];
A=ones(1,2);
b=10e6;

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

** subject to**
** Gx<=h;**
** A
x==b;**
cvx_end

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

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

2 Likes

Probably a scaling issue. Rescale your problem so your coefficients are not so largeâ€¦

1 Like

It worked! Thank you so much!

Thank you! This also worked

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.

2 Likes

Thank you for sharing the relationship between the two solutions!