How should the `sum` function be used in CVX?

In this code, when I use sum(y) <= Y, the solver tells me there is no solution. However, when I define an intermediate variable tmp = tmp + y in a loop (with tmp pre-defined as 0), and then add the constraint tmp <= Y, the solver finds a solution.

cvx_begin
cvx_solver MOSEK

variable v(n) complex
variable y(m,1)
variable T
variable z(m,1)
variable e(m,1)

expressions T1(m,1) T2(m,1)
for k=1:K
T1(k) = quad_over_lin(sqrt(r(k)*D), z(k));
T2(k) = quad_over_lin(sqrt(r(k)DC), y(k));
end

minimize(T)

subject to

norm(b,2) <= 1;
sum(y) <= Y;

T >= sum(T1+T2)/m;

for j=1:m
y(j) >= 1e-10;
z(j) <= Blog(1 + Pe(j)G/(Nd(j)^a))/log(2);
e(j) <= 2*real(v0’*S(:,:,j)*v) - norm(S(:,:,j)'*v0)^2;
end

cvx_end

It sounds like sum(y) <= Y is the constraint you want. You don’t say what exactly the solver and CVX reports when you say there is no solution.

You don’t show the code for your loop, but because ``yis a vector, perhaps you are imposing the vector constraintm*y <= Y, i.e., each element of ymust be <=Y/m`, which I don’t think is what you want.

Thank you for your reply. The solver didn’t report any errors; it just showed an optimal value (cvx_optval): +Inf. Since the problem became infeasible in the first iteration, I didn’t show the loop code.

Save both internal problems to a file

cvx_solver_settings('write', 'dump.ptf')

and compare.

Beware that if the problem was dualized by CVX then things will not be where you expect them, but you should be able to find the differences.

Alternatively share full log outputs from both variants.