# The expression in assignment statements in cvx tool can not ensure equality

Hi everyone, I met a trouble when i used the CVX tools. If you can give me some suggestion, i would be very pleasured. when i used CVX tool, i found that L_sumo can not be equal to the term tauo.*log(1+rho.*a_up_new) in the following codes. I can not figure out what happened in the process.
I can hardly express my gratitude to you for your help.

``````cvx_begin
variables u_x_new(N) u_y_new(N) L_tilde R_upper_k(K,N_t) z(K,N_t) lcomp(K,N_t-1) a_up_new(K,N_t)
expressions a_d(K,N_t) S_klnew(K,N_t) L_sumo(K,N_t) %L_off(K,N_k-1)
% expression L_sum_new(K,N)
maximize (L_tilde)
subject to

for n=1:1:N_t
(u_x_new(n+1)-u_x_new(n)).^2+(u_y_new(n+1)-u_y_new(n)).^2 <= S_max.^2;%%% speed constraint
end
u_x_new(1)==intial_x;
u_y_new(1)==intial_y;
u_x_new(N)==final_x;
u_y_new(N)==final_y;
for n=1:1:N_t-1
for k=1:1:K
lcomp(k,n)<=fC_k(k);
lcomp(k,n)>=tot;
end
end

for n=1:1:N_t
for k=1:1:K
z(k,n)>=0;
z(k,n)==(c_k(k,n)+2*S_kl(k,n)alpha(omega_x(k,n).*u_x_new(n+1)+omega_y(k,n).*u_y_new(n+1)));
R_upper_k(k,n)>=0;

2^(-R_upper_k(k,n))+rho*2^((-log(z(k,n)))/log(2)-R_upper_k(k,n))<=1;
S_klnew(k,n)= ((u_x_new(n+1)-x_k(k)).^2+(u_y_new(n+1)-y_k(k)).^2+H.^2);
((u_x_new(n+1)-x_k(k)).^2+(u_y_new(n+1)-y_k(k)).^2+H.^2) <=pow_p(a_up(k,n),-1)-(a_up_new(k,n)-a_up(k,n)).*pow_p(a_up(k,n),-2);%pow_pos(S_klnew(k,n),alpha)
a_up_new(k,n)>=0;
end
end
L_tilde>=0;
L_sumo=tauo.*log(1+rho.*a_up_new);
L_sumd=taud.*log(1+rho.*a_up_new);
lcomp(:,1)==0;
sum(sum(tauo.*log(1+rho.a_up_new)))>= L_tildelog(2); %tauo.*log(1+rho.*a_up_new)
sum(sum(taud.log(1+rho.a_up_new)))>=gammaL_tildelog(2);
a_d=taud.R_upper_k;
a_d(:,1)=0;
a_d(:,2)=0;
for n=1:1:N_k-1
for k=1:1:K
sum(lcomp(k,2:n+1))<=sum(L_sumo(k,1:n))/log(2);
end
end
sum(sum( lcomp))>= L_tilde;
for n=2:1:N_k
for k=1:1:K
sum(a_d(k,3:n+1))<=gammasum(lcomp(k,2:n));
end
end

cvx_end``````

Your model is nonconvex if you have a nonlinear equality. In that case cvx is the wrong tool.

Thanks for your reply. But in my model, there are convex equalities. i assign an intermediate variable “L_sumo” hut it can not be equal to the ideal value.

Please post a complete reproducible example, with all input data. Also show the CVX output or error messages. If CVX claims to have solved the problem and you think the solution is incorrect or violates any constraints by more than solver tolerance, then show the calculations you performed to reach that conclusion.

`L_sumo=tauo.*log(1+rho.*a_up_new);`
is an expression assignment, not an equality constraint.

If `tau0` is nonnegative, then `L_sumo` is a concave expression; therefore
`sum(lcomp(k,2:n+1))<=sum(L_sumo(k,1:n))/log(2);`
should be a convex constraint which CVX should accept.

What exactly is the difficulty you are encountering? What do you mean by

`L_sumo` hut it can not be equal to the ideal value.

Please note that after CVX completes, there is no guarantee that an expression, such as `L_sumo` will have the value corresponding to the optimal solution. CXV variables and cvx_optval will have their optimal values, CVX expressions do not necessarily have their optimal values, even though the optimal values were correctly used inside CVX. You need to compute l`L_sumo` using the optimal values of CVX variables. That is what CVX is doing internally. It just is not populating `L_sumo` with the final value used in the optimization. If CVX has reported that the problem is solved, if you calculate the value of `L_sum`o using the optimal values of the CVX variables, you should see that the inequality constraint involving `L_sumo` is satisfied (within solver tolerance).