CVX does not satisfy one of the conditions of the problem

I’m having trouble with a CVX code. It solves a problem with three constraints, but the solution always violates the last one. The problem is as:

``````            cvx_begin
variable F1(nR,nR) complex
fo4 = 0;
for m = 1:M
num = ssigma_we*(ssigma_wR*norm(gop{m})^2+alpha(m)* ...
trace(real(gop{m}'*H{m}*H{m}.'*F1*conj(H{m})* ...
H{m}'*gop{m})));

den = ssigma_wR*norm(gop{m})^2*(ssigma_we+alpha(m)* ...
trace(real(Hev{m}*H{m}.'*F1*conj(H{m})*Hev{m}')));
fo4 = fo4 + tav(m)*log(real(2*w{m}*sqrt(num) - w{m}^2*den))/log(2);
end
maximize(fo4);
subject to
abs(trace(F1))-PT <= 0;
F1 == hermitian_semidefinite(nR);
for m = 1:M
num = ssigma_we*(ssigma_wR*norm(gop{m})^2+alpha(m)* ...
trace(real(gop{m}'*H{m}*H{m}.'*F1*conj(H{m})* ...
H{m}'*gop{m})));

den = ssigma_wR*norm(gop{m})^2*(ssigma_we+alpha(m)* ...
trace(real(Hev{m}*H{m}.'*F1*conj(H{m})*Hev{m}')));

R0(m) - tav(m)*real(log(real(2*w{m}*sqrt(num) - w{m}^2*den)))/log(2) <= 0;
end
cvx_end
``````

Any ideas on how to fix it? Maybe adjustments to the constraint definition or the problem setup?

Despite the preceding for loop, your objective function is based only on m = M, because `f04` is overwritten every time through the for loop.

As for the apparent constraint violation, the inequality constraint in the fro loop could appear to not be satisfied even if it is actually satisfied, because it involves the expressions `num` and `den` The only way yo determine whether the constraint is actually satisfied is to recompute those expressions after cvx_end, using the optimal value of the variables.

As well, it is possible the constraint is violated by up to solver feasibility tolerance, but is still considered by CVX and the solver to be satisfied.

More details:
CVX variables are populated with their optimal values after `cvx_end`, but CVX expressions (whether declared as such or not) are not necessarily populated with their optimal values after `cvx_end`. So to get the optimal values of CVX expressions, you need to compute them after `cvx_end`, starting with the CVX optimal variable values.

The optimization is performed correctly even though the populated values for the expressions might not be correct. That reflects a CVX design decision. At the expense of some additional computation, CVX could have been written to automatically populate CVX expressions with their final optimal value, but was not designed that way. At minimum, the CVX Users’ Guide should have been clear and explicit about this (design decision), but is not.