Invalid operation: {1e+06} / {positive convex}

(Shijianzhuyu445) #1
    clear all
clc
cvx_begin
expression s_p;%源节点的位置
s_p=[0 0 0];
expression d_p;%目的节点的位置
d_p=[2000 0 0];
% expression H;%无人机的飞行高度
% H=100;
expression N;%时隙数
N=100;
expression gamma_0;%参考距离处的信噪比
gamma_0=10^8;
expression u_p_0;%无人机的初始位置
u_p_0=[1000,500,100];
expression u_p_f;%无人机的最终位置
u_p_f=[1500,500,100];
expression u_p(N,3);%无人机在每个时隙中的坐标(初始轨迹)
expression v_max;%无人机的最大的飞行速度
v_max=50;
expression u_min;%无人机的最小飞行距离
u_min=500;
expression h_sr(N,1);%源节点到中继的自由空间路径损耗
expression h_rd(N,1);%中继到目的节点的自由空间路径损耗
expression d_sr(N,1);%源节点到中继的距离
expression d_rd(N,1);%中继到目的节点的距离
expression R_s(N,1);%源节点到中继的速率
expression R_r(N,1);%中继到目的节点的速率
expression p_s;%源节点的功率
p_s=0.01;
expression p_r;%中继功率
p_r=0.01;
%% 初始轨迹
for i=1:N
  u_p(i,1)=1000+5*(i-1);%无人机的初始轨迹
  u_p(i,2)=500;
  u_p(i,3)=100;
end
% for i=1:N
%    d_sr(i,1)= sqrt(sum((u_p(i,:)-s_p).^2)+H^2);%计算初始轨迹所对应的距离
%    d_rd(i,1)=sqrt(sum((d_p-u_p(i,:)).^2)+H^2);%
%    R_s(i,1)=log2(1+p_s*gamma_0/d_sr(i,1)) ;
%    R_r(i,1)=log2(1+p_r*gamma_0/d_rd(i,1)) ;%初始轨迹所对应的速率
% end
%% 优化参数
expression gamma_s;%无人机功率比上噪声功率
gamma_s=1.99*10^11;
expression gamma_r;%中继功率比上噪声功率
gamma_r=1.99*10^11;
expression a_s(N,1) ;%
expression b_s(N,1) ;%
expression c_s(N,1) ;%因子
expression a_r(N,1) ;%
expression b_r(N,1) ;%
expression c_r(N,1) ;%因子
expression u_p_l(N,3);%无人机在每个时隙中的坐标
expression R_s_l1(N,1) ;%源节点到中继速率的下界
expression R_r_l1(N,1) ;%中继到目的节点的下界
%% CVX求解最优解
%cvx_begin
minimize(sum(R_r)-R_r(1,1))
subject to
variable delte(N);%x方向的运动增量
variable epsilon(N);%y方向的运动增量
u_p_l(:,1)=u_p(:,1)+delte(N);%
u_p_l(:,2)=u_p(:,2)+epsilon(N);%y轴运动坐标加运动增量
u_p_l(:,3)=u_p(:,3);%z轴不变
u_p_l(1,:)=u_p_0;%初始位置
u_p_l(N,:)=u_p_f;%最终位置
for i=1:N
   d_sr(i,1)= norm(u_p_l(i,:)-s_p);%计算初始轨迹所对应的距离(源节点到中继)
   d_rd(i,1)=norm(d_p-u_p_l(i,:));%计算初始轨迹所对应的距离(中继到目的节点)
   d_sr(i,1)
   R_s(i,1)=log2(1+p_s*gamma_0/d_sr(i,1)) ;
   R_r(i,1)=log2(1+p_r*gamma_0/d_rd(i,1)) ;%初始轨迹所对应的速率
   %
   a_s(i,1)=gamma_s*(exp(1))/(d_sr(i,1)^2*(gamma_s+d_sr(i,1)^2));
   b_s(i,1)=2*u_p_l(i,1)*a_s(i,1);
   c_s(i,1)=2*u_p_l(i,2)*a_s(i,1);
   %
   a_r(i,1)=gamma_r*log2(exp(1))/(d_rd(i,1)^2*(gamma_r+d_rd(i,1)^2));
   b_r(i,1)=-2*(d_p(1,1)-u_p_l(i,1))*a_r(i,1);
   c_r(i,1)=2*u_p_l(i,2)*a_r(i,1);
   R_s_l1(i,1)=R_s(i,1)-a_s(i,1)*(delte(i)^2+epsilon(i)^2)-b_s(i,1)*delte(i)-c_s(i,1)*epsilon(i);
   R_r_l1(i,1)=R_r(i,1)-a_r(i,1)*(delte(i)^2+epsilon(i)^2)-b_r(i,1)*delte(i)-c_s(i,1)*epsilon(i);%速率的下界
end
expression Sum_R_r(N-1,1);%速率的和矩阵
expression Sum_R_s_l1(N-1,1);%速率下界的和矩阵
for i=2:N
    for ii=2:i
        Sum_R_r(i-1,1)=Sum_R_r(i-1,1)+R_r(ii,1);
    end
end
for i=2:N
    for ii=1:i-1
        Sum_R_s_l1(i-1,1)=Sum_R_s_l1(i-1,1)+R_s_l1(ii,1);
    end
end
% minimize(sum(R_r)-R_r(1,1))
% subject to
for i=1:N-1
    Sum_R_r(i,1)<=Sum_R_s_l1(i,1);
end
for i=2:N
    R_r(i,1)<=R_r_l1(i,1);
end
for i=2:N
    norm(u_p_l(i,:)-u_p_l(i-1,:))<=expressionv_max^2;
end
cvx_end

I want to solve a simple convex problem that maximizes the rate of the devices. But, when I run the program it gives me this error,

Disciplined convex programming error:
Invalid operation: {1e+06} / {positive convex}
Error in / (line 74)

Looking forward to your reply, thank you!

(Mark L. Stone) #2

I’d say your problem as written is not very simple, and its convexity seems dubious. I will presume it is non-convex until proven otherwise.

It appears that you are trying to take the reciprocal of a norm, which is not an allowed operation under CVX’;s DCP rules, because it may not be convex or concave. And then sum these. I don’t know whether there is a reformulation possible in compliance with CVX’s rules, but I am very skeptical; and this is not possible if the problem is not convex.

You can not use log2(cvx_expression). Use log(cvx_expression)/log(2)

You should not be declaring expression', and then setting the symbol declared an expression equal to a numerical value vector). If you do, the numerical assignment overrides the earlier expression declaration, and the symbol has the numerical value (vector) assigned, the same as if you never declared that symbol as an expression.

(Shijianzhuyu445) #3

Thank you for your careful reply. Here is my optimization question. The R is the information rate of the UAV. This optimization problem comes from the paper that named “Throughput Maximization for UAV-Enabled Mobile Relaying Systems”. I just started learning cvx. Therefore, there are many things that I don’t understand. You mean the optimization problem is not convex, so it go wrong when running. I am very helpless about this. What other solutions are there for the optimization problem I have encountered? Do you have any good suggestions for me?
image

the link of paper is:https://ieeexplore.ieee.org/document/7572068

(Mark L. Stone) #4

I’ll take the authors at their word that this is a convex quadratic programming problem (QCQP), although I am not sure because I don;t know what all the notation means.

You have done a terrible job at trying to implement this. I recommend you read or re-read the CVX USers’ Guide http://cvxr.com/cvx/doc/.

(ren) #5

Have you solved this problem?
I have the same question with you、

错误使用 .* (line 173)
Disciplined convex programming error:
Cannot perform the operation: {positive constant} ./ {convex}