# How do I limit the optimization variable to be non-negative when I'm using the sedumi solver

I want to use sedumi to solve a linear optimization problem, where Sk is the optimization variable, and it requires a value between 0 and 1.So, i write like this

cvx_begin
variable Sk(K,M) nonnegative;
minimize sum(sum(Ttotal(:,:)))
subject to
for k=1:K
for m=1:M
Sk(k,m)<=1;
end
end
cvx_end

It turns out that Sk is only less than 1, but it’s not greater than or equal to zero. Even if I add the “Sk(k,m)>=0” constraint, Sk will still be negative sometimes, how do I solve this?

How negative? It is completely normal that every constraint, also a constraint of the form `x>=0`, is satisfied only up to some precision. https://docs.mosek.com/latest/faq/faq.html#why-does-the-solution-slightly-violate-constraints https://docs.mosek.com/modeling-cookbook/practical.html#the-quality-of-a-solution

If the value of Sk has elements which are slightly negative, such as -1e-8, but you really need `Sk` to be nonnegative, you can either

`Sk = max(Sk,0);`
after `cvx _end`

or use

``````variable Sk(K,M)
S >= small_positive_number
``````

where small_positive_number is perhaps 1e-5 or 1e-6. If this constraint is 'violated" by an amount up io the solver feasibility tolerance, the value of `Sk` will b still be nonnegative.

Thanks a lot, Mark! I use the method one because even the positive Sk is less than 1e-9

Are you saying that the optimal S = zeros(K,M) ?

Is there some part of your program which you did not include in your post? You don’t show where `Ttotal` is computed. If `Ttotal` is a MATLAB variable set to some numerical value prior to the CVX program, then CVX would consider it to be input data; so the objective function would be minimize a constant. That is the same as a feasibility problem. That means the solver and CVX can return any value of `Sk` they “want to”, presuming it satisfies the constraints to within solver feasibility tolerance. If this is not the case, perhaps we can provide more assistance if you show u s the code as to how `Tttotal` is computed, and how it relates to the CVX (optimization) variables. If `Ttotal` is an expression, that expression must be provided before the objective function; because if it is provided after the objective function, the expression will have the default value of `zero` for use in the objective function, which will make it a feasibility problem, contrary to what you wanted.

I use the method 1, which means I add the statement
Sk = max(Sk,0);
after cvx _end
as you say.

There is actually some part of program which i did not include in my post? As for Ttotal, this is an expression containing the variable Sk and some constants that I declared after cvx_begin as “expression Ttotal(K,M) ;”. And I provid it before the objective function as
for k=1:K
for m=1:M
Ttotal(k,m)=gamac*(1-Sk(k,m))LkCkf_gitf_git+P1Sk(k,m)Lkinv_pos(Blog(1+P1Hlb(k,m)inv_pos(N0))inv_pos(log(2)))+gamacSk(k,m)LkCkf_uavf_uav;
end
end

Hello mark, I have another problem. I use the sedumi to solve two convex optimization problems by alternately. I first minimized Ttotal by optimizing Sk. And then substituted the optimized Sk as a constant into another convex optimization problem. And also try to minimize Ttotal by optimizing the variable Q(2,M). But it shows like this

## Cones | Errors | Mov/Act | Centering Exp cone Poly cone | Status --------±--------------------------------±-------- 0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Failed 0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Failed 0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Failed

Status: Failed
Optimal value (cvx_optval): NaN

I don’t konw why? Is it because my constraints are too tight?

Do both of the following:

1. We don’t know what your input data is. You should rescale the data (variables) if not all non-zero input data are within a small number of orders of magnitude of one.

2. If Mosek is available to you, use it as solver. Otherwise follow the advice at CVXQUAD: How to use CVXQUAD's Pade Approximant instead of CVX's unreliable Successive Approximation for GP mode, log, exp, entr, rel_entr, kl_div, log_det, det_rootn, exponential cone. CVXQUAD's Quantum (Matrix) Entropy & Matrix Log related functions

Thank you, Mark! I’ll try it.