Here is my cvx code

``````cvx_begin
variable E_user(n) nonnegative
variable z nonnegative
expression sigma(n)
expression Sigma(n)
expression Omega(n)
expression A(n)
expression B(n)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%             sigma=zeros(1,K_num); Sigma=zeros(1,K_num); Omega=zeros(1,K_num);

% Calculate sigma
for t=1:K_num
my_hold=zeros(M*N,M*N);
for i=1:K_num
if i~=t
my_hold=my_hold+E_user(i)*G_DDMA(:,:,i)*G_DDMA(:,:,i)';
end
end
sigma(t)=trace(pinv(D(:,:,t))*U(:,:,t)*H(:,:,t)*my_hold*H(:,:,t)'*U(:,:,t)'*(pinv(D(:,:,t)))');
end

% Calculate Sigma
for t=2:K_num
my_hold=zeros(M*N,M*N);
for i=2:K_num
if i~=t
my_hold=my_hold+E_user(i)*G_DDMA(:,:,i)*G_DDMA(:,:,i)';
end
end
Sigma(t)=trace(pinv(D(:,:,1))*U(:,:,1)*H(:,:,1)*my_hold*H(:,:,1)'*U(:,:,1)'*(pinv(D(:,:,1)))');
end
my_hold=zeros(M*N,M*N);
for i=3:K_num
my_hold=my_hold+E_user(i)*G_DDMA(:,:,i)*G_DDMA(:,:,i)';
end
Sigma(1)=trace(pinv(D(:,:,2))*U(:,:,2)*H(:,:,2)*my_hold*H(:,:,2)'*U(:,:,2)'*(pinv(D(:,:,2)))');

% Calculate Omega
for i=2:K_num
Omega(i)=trace(pinv(D(:,:,1))*U(:,:,1)*H(:,:,1)*G_DDMA(:,:,i)*G_DDMA(:,:,i)'*H(:,:,1)'*U(:,:,1)'*(pinv(D(:,:,1)))');
end
Omega(1)=trace(pinv(D(:,:,2))*U(:,:,2)*H(:,:,2)*G_DDMA(:,:,1)*G_DDMA(:,:,1)'*H(:,:,2)'*U(:,:,2)'*(pinv(D(:,:,2)))');

sigma=real(sigma);
Sigma=real(Sigma);
Omega=real(Omega);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=2:n
A(i)=(N0+alpha*sigma(i)+E_user(i))*(N0+E_user(1)+alpha*Sigma(1));
B(i)=(N0+alpha*Sigma(i))*(N0+E_user(1)+alpha*Sigma(1)+E_user(i)*Omega(1));
end
A(1)=(N0+alpha*sigma(1)+E_user(1))*(N0+E_user(2)+alpha*Sigma(2));
B(1)=(N0+alpha*Sigma(1))*(N0+E_user(2)+alpha*Sigma(2)+E_user(1)*Omega(2));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

maximize (z)
E_sum=0;
for i=1:n
E_sum=E_sum+E_user(i);
end
subject to
E_sum<=E_total;
for i=2:n
log(2*beta(i)*sqrt(A(i)) -  beta(i)^2*B(i) )/log(2)>=z;
end
log(2*beta(1)*sqrt(A(1)) - beta(1)^2*B(1) )/log(2)>=z;
cvx_end
``````

I have following error when cvx is going to generate A(i)

``````Disciplined convex programming error:
Invalid quadratic form(s): not a square.

``````

I believe the error comes from I have made variables production when generate A(i), is there any method to fix this?

Perhaps you can help us out by telling us exactly which statement triggered the error message? If it involves `trace`, you might be able to use the reformulation
`trace (A*A') = square_pos(norm(A,'fro'))` , and use cyclic permutation invariance of trace to rearrange the argument of `trace` to get it in this form if needed.

If that does not handle your situation, your first task is to prove your optimization problem is convex (concave objective being maximized, and all constraints convex, all holding jointly with respect to the CVX variables (accounting for anything going on in the CVX expressions).

Thank you for your answer, the error is triggered by this line in my cvx code.

I think the error is because I made variable product…But I have to do this way…

That is non-convex. So it would appear that CVX is not the right tool for this problem. Perhaps you can try a local or global (non-convex) nonlinear optimization solver under YALMIP.

Thank you so much for your explaination, it makes sense.