# Is there a mistake in this code?

function[U,V,T,x,B,W1,W2]=CVX_solver_P2(v,t,a,g,gama2,H1,H2)
cvx_begin sdp
variable W1(N,N)
variable W2(N,N)
variable U
variable V
variable x nonnegative
variable B nonnegative
maximize(U)
subject to
2vV-square(v) >=U;
2tT-square(t) >= gama2-x;
square(ax)+square(trace(H2W1)inv_pos(a)) <= 2trace(H2W2)-2x;
0<= trace(W1+W2) <=1;
W1==semidefinite(N);
W2==semidefinite(N);
0<=B<=1;
trace(H1W1)-gama2trace(H1W1)>= gama2inv_pos(1-B);
[1-B V;V trace(H1*W1)]==semidefinite(2);
[B*g T,T trace(H1*(W1+W2))]==semidefinite(2);
cvx_end
end

there is an error in the 3rd constraint(invalid constraint: convex<= complex affine)

Because you have no declared any variables to be complex, it must be the case that some of the input data is complex.

CVX does not allow complex inequalities. If the inequality really is supposed to be complex, you can use separate inequalities for the real and imaginary parts. Or maybe you just want the real part. It’s your problem, so you should know what it’s supposed to be.