# Something wrong in log function in cvx constraints

As you can see, it seems that the results are not correct. can you help me?

`````` cvx_begin
variable q1(2,N)
variable gamma_k(N,K) nonnegative
variable rho(N,1) nonnegative
variable S(N,K) nonnegative
variable v(N,1) nonnegative
variable e(N,1) nonnegative
variable f(N,1) nonnegative
variable T_j(N,J) nonnegative
variable g(N,1) nonnegative
expression Gj_lb(J,N)
expression rate(K,N)
expression rate_temp(N,K)
% expression d_uk(2,1)
% expression d_tj(2,J)
% expression d_e(2,1)

for n=1:N
%     Hk=(H_irs_users_hat(:,:,n)'*diag(Phi0(:,n))*H_bs_irs_hat(:,:,n))';
%     he=(h_irs_eve_hat(:,n)'*diag(Phi0(:,n))*H_bs_irs_hat(:,:,n))';
for k=1:K
rate(k,n) =  Alpha_k(k,n)*(log(1+gamma_k(n,k))-log(1+rho0(n))-(rho(n)-rho0(n))/(1+rho0(n)));
end
end

maximize (sum(sum(rate))/N/log(2))
subject to

%trajectory
q1(:,1)==q_s
q1(:,N)==q_f

for n=2:N
norm(q1(:,n)-q1(:,n-1))<=vmax*delta_T;
%     norm([2*(q1(:,n)-q1(:,n-1));1-(vmax*delta_T)^2])<=1+(vmax*delta_T)^2;
norm([2*(q1(:,n)-q0(:,n));1-Delta])<=1+Delta;%trajectory approximation constraint
end

% time slot iteration
for n=1:N
% rho slack
he_n=[h_bs_eve_hat(:,n)'*W0(:,n);h_irs_eve'*diag(Phi0(:,n))*H_bs_irs_hat(:,:,n)*W0(:,n)];
% He_n=([h_bs_eve_hat(:,n)'*W0(:,n);h_irs_eve'*diag(Phi0(:,n))*H_bs_irs_hat(:,:,n)*W0(:,n)]*[h_bs_eve_hat(:,n)'*W0(:,n);h_irs_eve'*diag(Phi0(:,n))*H_bs_irs_hat(:,:,n)*W0(:,n)]');
% real([e(n),f(n)]*He_n*[e(n),f(n)]')<=rho(n);
norm([2*[e(n),f(n)]*he_n,1-rho(n)])<=1+rho(n);
%gamma_k slack
Hk=(H_irs_users'*diag(Phi0(:,n))*H_bs_irs_hat(:,:,n))';
for k=1:K
Huk_n=([H_bs_users_hat(:,k,n)'*W0(:,n);Hk(:,k)'*W0(:,n)]*[H_bs_users_hat(:,k,n)'*W0(:,n);Hk(:,k)'*W0(:,n)]');
d_uk0=[S0(n,k),v0(n)]';
real(d_uk0'*Huk_n*d_uk0+2*d_uk0'*Huk_n*([S(n,k),v(n)]'-d_uk0))>=gamma_k(n,k);
%     gamma_k(n,k)>=0;
end

%  target detection power constraint
Ht=(H_irs_targets'*diag(Phi0(:,n))*H_bs_irs_hat(:,:,n))';
for j=1:J
d_tj0=[T_j0(n,j),g0(n)]';
Htj_n=([H_bs_targets_hat(:,j,n)'*W0(:,n);Ht(:,j)'*W0(:,n)]*[H_bs_targets_hat(:,j,n)'*W0(:,n);Ht(:,j)'*W0(:,n)]');
% Gj_lb(j,n)= real(d_tj0'*Htj_n*d_tj0+2*d_tj0'*Htj_n*([T_j(n,j),g(n)]'-d_tj0));
Gj_lb(j,n)= real(2*d_tj0'*Htj_n*[T_j(n,j),g(n)]'-d_tj0'*Htj_n*d_tj0);
Beta_j(j,n)*(Gj_lb(j,n)-1)>=0;

end

% distance SCA constraint
for k=1:K
% Snk
square_pos(norm(q1(:,n)-P_u(:,k)))+H_u^2-eta^(4/alpha)*((4/alpha+1)*S0(n,k)^(-4/alpha)-4/alpha*S0(n,k)^(-4/alpha-1)*S(n,k))<=0;
S(n,k)>=eta*(2*norm(q_s-q_f)^2+2*H_u^2)^(-alpha/2);
end
% v
square_pos(norm(q1(:,n)-p_irs))+(H_u-H_i)^2-eta^(4/kappa)*((4/kappa+1)*v0(n)^(-4/kappa)-4/kappa*v0(n)^(-4/kappa-1)*v(n))<=0;
v(n)>=eta*(2*norm(q_s-q_f)^2+2*H_u^2)^(-kappa/2);
% g
square_pos(norm(q1(:,n)-p_irs))+(H_u-H_i)^2-theta^(4/kappa)*((4/kappa+1)*g0(n)^(-4/kappa)-4/kappa*g0(n)^(-4/kappa-1)*g(n))<=0;
g(n)>=theta*(2*norm(q_s-q_f)^2+2*H_u^2)^(-kappa/2);
% e
eta^(4/alpha)*pow_p(e(n),-4/alpha)-(norm(q0(:,n)-p_e)^2+H_u^2+2*(q0(:,n)-p_e)'*(q1(:,n)-q0(:,n)))<=0;
e(n)<=eta*H_u^(-2/alpha);
%f
eta^(4/kappa)*pow_p(f(n),-4/kappa)-(norm(q0(:,n))^2+(H_u-H_i)^2+2*q0(:,n)'*(q1(:,n)-q0(:,n)))<=0;
f(n)<=eta*(H_u-H_i)^(-2/kappa);
% tj

for j=1:J
square_pos(norm(q1(:,n)-P_t(:,j)))+H_u^2-theta^(4/alpha)*((4/alpha+1)*T_j0(n,j)^(-4/alpha)-4/alpha*T_j0(n,j)^(-4/alpha-1)*T_j(n,j))<=0;
T_j(n,j)>=theta*(2*norm(q_s-q_f)^2+2*H_u^2)^(-alpha/2);
end
end

% QoS constraint
for k=1:K
for n=1:N
rate_temp(n,k)=log(1+gamma_k(n,k))/log(2);
end
sum(Alpha_k(k,:).*rate_temp(:,k)')>=r_th*N;
end
cvx_end``````

How can I see that the results are not correct? I have no idea what you are trying to do, or why you think the results are not correct.

rate_temp(i,j)=log2(1+gamma_k(i,j)),
In my problem, gamma_k>=0, so, rate_temp is positive.
However, some results are negative.

Those are very small magnitude negative numbers, within solver feasibility tolerance. Either apply (max(rate_temp,0) after cvx_end, or include a small positive number, such as 1e-6, as a buffer to prevent negative numebrs.

ok， thank you, but when gamma_k=2.0745e3, rate_temp=log2(1+gamma_k)=-1.1, i think this result is wrong!

After CVX completes, expressions and expression holders do not necessarily have their “optimal” (final) values. if you want to know the optimal (values) of expressions, you need to compute them starting from CVX variables, which will be at their optimal values.