Why NaN Appears

The problem has been proved to be convex. why is NaN,thanks.


%--------------------------------------------参数设置----------------------------------------------------------------

W=[350,245;175,90;100,120;160,130;395,290;45,50;240,200;110,200];%地面用户位置
yita=[0.96,0.72,0.94,1,0,0,0,0];%各用户卸载率
D=[37*1000,49.69*1000,37.88*1000,34.64*1000,0,0,0,0];%任务量(单位为bit)
V=[270,60;130,240];%窃听UAV位置 
y=[205,160];%合法UAV位置
Hu=120;He=[110,130];%UAV高度
X=10;%位置估计误差
T=0.16;%时延限制
beta1=10^(-5);beta2=10^(-4);%信道功率增益 
o2=10^(-14);%噪声功率
k=10^(-27);%功率消耗因子
r=10^(-11);%自干扰效率 
F=1000;%每bitCPU转数
B=10^6;%传输带宽
fuavmax=2*10^(9);f0=2*10^(8);%合法UAV/用户本地计算能力
fiu=fuavmax/4;%UAV分配给卸载用户的计算能力
Puavmax=1;Puemax=0.1;%UAV/用户功率限制
B=10^(6);%传输带宽
Pue=[0.08;0.08;0.08;0.08;0.028;0.024;0.011;0.015];%初始用户功率
Pjamm=0.005;%合法UAV发送的干扰功率
% rou=r*Pjam+o2;%噪声+干扰功率
%--------------------------------------------信道增益-----------------------------------------------------------------
hiu=zeros(1,8);
hiemax=zeros(2,8);
hkemin=zeros(2,8);
heumin=zeros(1,2);
l=zeros(1,4);
for i=1:4
     l(i)=D(i)*yita(i)/(B*(T-F*D(i)*yita(i)/fiu));%卸载传输的最低速率(时延限制下)
end
   for i=1:8
        for v=1:2
           hiu(i)=beta1/(Hu^2+norm(y-W(i,:))^2); 
           hiemax(v,i)=beta1/(He(v)^2+(norm(W(i,:)-V(v,:))-X)^2);
           hkemin(v,i)=beta1/(He(v)^2+(norm(W(i,:)-V(v,:))+X)^2);
           heumin(v)=beta2/((Hu-He(v))^2+(norm(y-V(v,:))+X)^2);
        end
   end
     h=[hkemin(1,:)*Pue,hkemin(2,:)*Pue];
%--------------------------------------------optimize----------------------------------------------------------------
cvx_begin

variables Pjam C0 r0

          g=hiu*Pue+r*Pjam+o2;
          q=hiu*Pue+r*Pjamm+o2;
        
maximize C0         
subject to
           
         
         r0>=0;
         for i=1:4
            for v=1:2
              1+(hiemax(v,i)*Pue(i)*10^(11)*inv_pos((hkemin(v,:)*Pue-hkemin(v,i)*Pue(i)+Pjam*heumin(v)+o2)*10^(11)))<=2^(r0);
             end
             log2(g)-(log2(q-hiu(i)*Pue(i))+r*(Pjam-Pjamm)*10^(11)/((q-Pue(i)*hiu(i))*log(2)*10^(11)))-r0>=C0>=0;
             log2(g)-(log2(q-hiu(i)*Pue(i))+r*(Pjam-Pjamm)*10^(11)/((q-Pue(i)*hiu(i))*log(2)*10^(11)))>=l(i);
             0<=Pjam<=Puavmax-k*fiu*fiu*fiu*4; 
         end
        
  
       
cvx_end
1 Like

You haven’t shown us the output. But apparently the problem has either been determined to be infeasible (perhaps not necessarily correctly so due to scaling as mentioned in my next paragraph) or the solution process has failed.

First of all, the input data is terribly scaled, which will make solution unreliable and difficult. So you need to improve the scaling of the input data, for instance by changing units used, so that numbers are closer in magnitude to 1. You don’t seem to have (successfully) followed that same advice I provided in your earlier question How to solve this situation in the picture .

As a second step to further improve the reliability of the solution process, also as suggested by me in your earlier question, you can follow the advice in 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

I am very sorry, the output is as follow:

I replaced all logs and a (cvx _ ex) with -rel_entra and exp(log(a)*(cvx_ex)), and the result was still NaN

subject to

     r0>=0;
     for i=1:4
         for v=1:2
          1+(hiemax(v,i)*Pue(i)*10^(11)*inv_pos((hkemin(v,:)*Pue-hkemin(v,i)*Pue(i)+Pjam*heumin(v)+o2)*10^(11)))<=exp(log(2)*r0);           
         end
         -rel_entr(1,g)/(-rel_entr(1,2))-(-rel_entr(1,q-hiu(i)*Pue(i))/(-rel_entr(1,2))+r*(Pjam-Pjamm)*10^(11)/((q-Pue(i)*hiu(i))*(-rel_entr(1,2))*10^(11)))-r0>=C0>=0;
         -rel_entr(1,g)/(-rel_entr(1,2))-(-rel_entr(1,q-hiu(i)*Pue(i))/(-rel_entr(1,2))+r*(Pjam-Pjamm)*10^(11)/((q-Pue(i)*hiu(i))*(-rel_entr(1,2))*10^(11)))>=l(i);
         0<=Pjam<=Puavmax-k*fiu*fiu*fiu*4; 
     end

Because of log(cvx_expression) being in your program, CVX’s Successive Approximation method was used. As I discussed in the CVXQUAD link in my post above, that method is unreliable. In this case, it failed - that is why you got NaN in this case.

I suggest you follow the advice in my previous post about scaling and CVXQUAD. I suggest you start by improving scaling, and then re-run. After that, you can try CVXQUAD per the link.

If scaling is not improved, NO solution method or solver will be reliable on the problem.

In order for CVXQUAD to actually be used, you need to install it, including its exponential.m replacement. If there are no Pade Approximation messages in the output, that means you have not done so (given rel_entr). Even if you have, if you still see the stuff with Cones, Errors, Status, that means that not all exponential cone item instances have been properly reformulated.

Also note that when you replace log2 with -rel_entr, you will need to divide by log(2) to account for switching from log base 2 to natural log, which it appears you neglected to do, even though it is used in an inequality with non-zero RHS in which .the log(2) factor matters. You may have plenty of other errors as well - I don’t know, I didn’t check.

Thank you very much for your careful explanation. I will revise it again.

I replace log(1+convex)<=r0(r0 is variable) with 1+convex<=2^r0, and use CVXQUAD(i have install CVXQUAD.): replace 2^r0 with exp(log(2)*r0),use z express exp(log(2)*r0),and
variable z % this line must be before z is used
{log(2)*r0,1,z} == exponential(1);
why apear Function’ cvx_check_dimlist’ corresponding to input parameter of type’ double’ is not defined.

or can you teach me how to express log(1+a/(b+variable1))<=variable 2(a and b is constants),this qusetion confused me long time ,please.

-rel_entr_quad(1,g)/log(2)-((-rel_entr(1,q-hiu(i)Pue(i)))/log(2)+r(Pjam-Pjamm)/(q-Pue(i)*hiu(i))*log(2))-r0>=C0>=0;

I added E:\cvxquad-master to the MATLAB path (the diagram of the above question), and then replaced exponential.m in the original CVX sets with exponential.m in cvxquad-master. is this my initialization step wrong?thank you very much.

Why do you have rel_entr_quad? Use rel_entr

What is your log(1+convex) Have you shown that is convex? You can’t have that exp on the RHS of <=… Your constraint must be convex to begin with. Do you actually want the constraint in the other direction?

I want to write the constraint 37©

In r(ub)ie,the function (log )second derivative greater than zero

You can use my solution at How to write:log(1+1/x)<=y (divide the denominator in 1 + numerator/denominator, by the numerator, which puts it in the form log(1+1/x)) and divide the whole thing by log(2) to account for different base log.

同学你好,我最近也在复现这篇论文的代码和你出现了同样的问题目前进展不太好,请问能留个联系方式交流一下吗?