# Only scalar quadratic forms can be specified in CVX

Sorry, I encountered a problem implementing codes in CVX as follows:
I have a constraint real(a+b*trace(R_arb*V)+c*trace(R_sum*V))+2*trace(R_arb*V*R_sum*V))<=0;
where a, b, c are positive real numbers, R_arb and R_sum are Hermitian matrices, and V is our optimized variable which is complex semidefinite,
but it came out that
error: Only scalar quadratic forms can be specified in CVX.

It shows that the problem appears in the last term trace(R_arb*V*R_sum*V), the codes work when I delete it. This is not a convex expression? I thought SDP is designed for solving the matrix problems and it should work for this.

CVX is designed to handle linear SDP problems, not arbitrary problems with matrices.

I believe your problem is not generally convex, unless `R_arb = R_sum`, in which case `trace(R_arb*V*R_sum*V) = sum(sum((R_arb*V).*(V*R_sum)))` would reduce to a sum of squares which CVX would accept.

Thank you. I found CVX can solve the problem like trace(A*Aâ€™), so I think I can employing EVD to convert the original problem to such form so that the following cede
`square_pos(norm(sqrt(D_arb)*U_arb*V*U_sum'*sqrt(D_sum),'fro'));`
is suitable for CVX, where D_arb and U_arb are diagnal eigenvalue matrix and corresponding eigenvector matrix.
Hope this thought can help anyone who has the same confussion.

CVX will accept that, but I donâ€™t see why it would be equal to `trace(R_arb*V*R_sum*V)`

This is the EVD of original function and the last term can be expressed as the code I provided. FYI.

Sorry. Youâ€™re correct. I used the MATLAB convention of eigenvector matrix (and didnâ€™t adjust accordingly), which is the transpose of what you used.

It might be a little simpler to express it as `square_pos(norm(sqrtm(R_arb)*V*sqrtm(R_sum),'fro')) `, which makes use of the same cyclic permutation of trace. And son of a bitch, I think Iâ€™ve previously done that on this forum, but missed it this time. So thanks for the painful reminder.

LoL, itâ€™s okay. Thank you for the recommendation of code adjustment and hope these discussions useful for others.

Or
`square_pos(norm(chol(R_arb)*V*chol(R_sum)','fro')) ` ,

1 Like

OK, itâ€™s a different decomposition method. Do you think these chenges should impact on the final results? If so, which one is better?

I have no reason to think any of them are better than any other. If everything were computed and solved in exact arithmetic, and the optimal solution were unique, then it shouldnâ€™t make any difference. However, in finite precision, the results could be different.

Pick whichever â€śfloats your boatâ€ť, as we say in the U.S.

Yeah, itâ€™s reasonable. Thank you.

1 Like