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)
** minimize quad_form(x,lambda)**
** 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

I think this may help: http://cvxr.com/cvx/doc/advanced.html#eliminating-quadratic-forms

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

mcg
(Michael C. Grant)
December 10, 2015, 8:59pm
5
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

mcg
(Michael C. Grant)
December 11, 2015, 2:29pm
8
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!