# Trace of a quadratic form

``````clc;
clear;
close all;
c1=conj(transpose((randn(1,3)+sqrt(-1)*randn(1,3))));
c1_h=conj(transpose(c1));
s=c1*c1_h;
h1=transpose((randn(1,3)+sqrt(-1)*randn(1,3)));
h1_h=conj(transpose(h1));
v=h1*h1_h;
cvx_begin
variable LM(3,3);
minimize( trace(s*LM* v*conj(transpose(LM))) );
cvx_end
``````

Result on matlab give:

``````??? Error using ==> cvx.mtimes at 126
Disciplined convex programming error:
Only scalar quadratic forms can be specified in CVX``````

Please read this section of the documentation very carefully. Models must be constructed according to those rules or they will be rejected—even if they are convex. I cannot emphasize that enough: even if you know your model is convex, you must still enter it according to those rules.

CVX is rejecting your model here because the product inside the trace is not a convex quadratic form. CVX isn’t actually a full-fledged parser; every single sub-expression must obey the rules. However, we know that the overall expression is convex.

How do you rewrite it? Well, actually, it’s pretty much the same way you would prove that it is convex: by expressing it in a simpler manner. Using the fact that \mathop{\textrm{Tr}}(ABC)=\mathop{\textrm{Tr}}(CAB)=\mathop{\textrm{Tr}}(BCA) whenever the products are well-formed, you can rewrite
\$\$\mathop{\textrm{Tr}}(c_1c_1^HL_Mh_1h_1^HL_M^H)=c_1^HL_Mh_1h_1^HL_M^Hc_1= |c_1^HL_Mh_1|^2.\$\$
And this, in turn can be written in CVX as simply `square_abs(c1'*LM*h1)`.

Note however that you have not specified your matrix `LM` to be complex.