# Scalar quadratic forms can be specified in CVX

I’m trying to solve a problem that a couple of intermediate variables are introduced to express the object function

,and these variables are non-convex.But the paper I refered that the whole problem is turned to convex to solve by cvx.I wonder how to figure out these intermediate variables.

If `A` is psd, `trace(W"*A*W)` can be reformulated as `square_pos(norm(sqrtm(A)*W,'fro'))`

I’ll let you sort through the more complicated cases. Making use of the cyclic permutation invariance of trace may help for more complicated instances of trace of product of matrices. Perhaps `matrix_frac` will be of some help.

But you need to understand why the problem is convex. And that can’t just be that it is convex because the paper said so.

In the future, please copy and paste code using the Preformatted text icon, rather than posting an image.

Thank you for your reply! It’s my first time to create the topic. I will take your advice to figure out convex problems. And I have one more problem is I express “A” in objective function(OBJ) with expression U and V, both U and V are consist of the non-convex “HWW’H’”, where “W” is variable matrix(Nt,d) and “H” is (NI,Nt).
The error is

``````错误使用 *
Disciplined convex programming error:
Only scalar quadratic forms can be specified in CVX
.

M1(:,:,i,m) = H(:,:,i)*W(:,:,m)*W(:,:,m)'*H(:,:,i)';%(NI,NI)intermediate variablesS中间变量，表示H1W1W1H1+H1W2W2W1+H2W1W1H2+H2W2W2H2
``````
``````cvx_begin
variable W(Nt,d,KI) complex
expression M1(NI,NI,KI,KI)
expression M2(NI,NI,KI)
expression M3(NI,NI,KI)
expression J(NI,NI,KI)
expression U(NI,d,KI)
expression V(d,d,KI)
expression A0(Nt,Nt,KI)
expression A(Nt,Nt)
expression OBJ
for i=1:KI
for m=1:KI
M1(:,:,i,m) = H(:,:,i)*W(:,:,m)*W(:,:,m)'*H(:,:,i)';%(NI,NI)intermediate variablesS中间变量，表示H1W1W1H1+H1W2W2W1+H2W1W1H2+H2W2W2H2
M2(:,:,i) = H(:,:,i)*W(:,:,i)*W(:,:,i)'*H(:,:,i)';%(NI,NI)intermediate variables中间变量，表示H1W1W1H1+H2W2W2H2
M3(:,:,i) = sum(M1(:,:,i,:),4);%(NI,NI)intermediate variables中间变量,m~=i
end
J(:,:,i) = M3(:,:,i) - M2(:,:,i) + sigmaI*eye(NI);%(NI,NI)Jk
U(:,:,i) = (J(:,:,i) + H(:,:,i)*W(:,:,i)*W(:,:,i)'*H(:,:,i)')^(-1)*H(:,:,i)*W(:,:,i) ;%intermediate variables(NI,d)
V(:,:,i) = ( eye(d) - W(:,:,i)'*H(:,:,i)'*(M3(:,:,i)+sigmaI(NI))^(-1)*H(:,:,i)*W(:,:,i) )^(-1);%intermediate variables(d,d)文献中的W
A0(:,:,i) = H(:,:,i)'*U(:,:,i)*V(:,:,i)*U(:,:,i)'*H(:,:,i);%(Nt,Nt)
A = sum(A0,3);%intermediate variables
%OBJ = square_pos(norm(vec(A*W(:,:,i)), 'fro')) - real(trace(V(:,:,i)*U(:,:,i)'*H(:,:,i)*W(:,:,i))) - ...
% - real(trace(V(:,:,i)*W(:,:,i)'*H(:,:,i)'*U(:,:,i))) ;
OBJ = sum(trace(W(:,:,i)'*A*W(:,:,i)),3) - sum(trace(V(:,:,i)*U(:,:,i)'*H(:,:,i)*W(:,:,i)),3) -...
sum(trace(V(:,:,i)*W(:,:,i)'*H(:,:,i)'*U(:,:,i)),3);
end
``````

You can 't explicitly formulate matrix quadratic forms. You can reformulate `trace(H*W*W'*H')` as ` square_pos(norm(H*W,'fro'))`.

As for other things, you better start by proving convexity. If it is a “DCP-constructive” proof, that will show you how to reformulate it in CVX. If it is not convex, CVX is not the right tool for the problem.