# How do we solve the expression log(1/(1+x))?

Hi,all.
I want to write the expression log(1/(1+x)),but there is a error: ‘Disciplined convex programming error:Illegal operation: rel_entr( {convex}, {convex} ).’

My code is shown as follows,
function [a,Theta,theta]= opt_Theta(w,W,lambda,Pmax,Rmin,P1)
ite=100;
sigma_e = db2pow(-200);%噪声功率
sigma_u = db2pow(-200);
N1=1/sigma_u;
N2=1/sigma_e;

``````      cvx_begin quiet
%variable Theta(N,N) complex
variable theta(1,N)
for t0=1:ite
Hd=pd*Hd_w(:,:,t0);
G=channel_G(AP_angle,IRS_angle,G_sig(:,:,t0),eb1,eb2,N,M);
Hr=ps*channel_Hr(User_angle,Hr_sig(:,:,t0),eb1,eb2,K,N);
Theta = diag(exp(1j*theta));
H=Hd+Hr*Theta*G;
Rateu=0;
for k0=1:K
P(k0)=norm(H(k0,:)*w);
sinr(k0)=norm(H(k0,:)*w)*N1;
y=sinr(k0);
Rateu=Rateu+rel_entr(1+y,y)+rel_entr(y,1+y)-rel_entr(1,y);
end

end

for t0=1:ite
Hbe=pde*Hbe_w(:,:,t0);
G=channel_G(AP_angle,IRS_angle,G_sig(:,:,t0),eb1,eb2,N,M);
Hie=pse*channel_Hie(Eve_angle,Hie_sig(:,:,t0),eb1,eb2,1,N);
Theta = diag(exp(1j*theta));
H_e=Hbe+Hie*Theta*G;
for k0=1:1
P=norm(H_e(k0,:)*w);
sinr(k0)=P*N2;
x=sinr(k0);
Ratee=rel_entr(1+x,x)+rel_entr(x,1+x)-rel_entr(1,x);

end
end

minimize (-(Rateu-Ratee-lambda*(P1+(w'*w))))
subject to
Rateu-Ratee>=Rmin;
for n=1:1:N
0<=theta(:,n)<2*pi;
end
cvx_end
Theta = diag(exp(1j*theta));
``````

end
Who can explain the problem?Thank you.

Reformulate `log(1/(1+x))` as `-log(1+x)`, which is convex. So you need to use it is a convex way.

The error you are seeing is related to the use of the `rel_entr` function in your optimization problem. The `rel_entr` function computes the relative entropy of two vectors, which is only defined when both vectors are positive and their entries sum up to one. In your case, it seems that this assumption is not satisfied, which leads to the error you are seeing.

Based on your code, it seems that the `rel_entr` function is used to compute the rate of a communication system. If this is the case, you may want to consider using a different expression for the rate that does not involve the `rel_entr` function. One possibility is to use the Shannon capacity formula, which is a well-known expression for the maximum rate at which information can be transmitted over a communication channel. Alternatively, you could try to reformulate your problem so that the `rel_entr` function is not needed, or use a different optimization solver that can handle this function.

@ToneyWulff got placed in the moderator queue and was apparently written before my post above.

I am now a little confused as to what @Lenka wants to do. One or more of these formulas hopefully covers what you want to do:

`log(1/(1+x)) = -log(1+x) = rel_entr(1,1+x)`

`log(1+1/x) = rel_entr(x,x+1) + rel_entr(x+1,x)`