Thank you, sir. After I replace it, I no longer show that error, but there is a new problem. These days is really troubling you, but I really have no other way.
warning: A non-empty cvx problem already exists in this scope.
It is being overwritten.
In cvxprob (line 28)
In cvx_begin (line 41)
In ceshi2 (line 29)
The following error occurred during conversion from CVX to double:
Cannot convert from CVX to double.
出错 ceshi2 (line 38) m1(j)=m1(j)+m(j,x);
To make it clear, I’ve posted the code。
syms V;%非负控制参数
syms t;%时隙
syms p;%发射功率
syms m;%基站之间传递能量
n=0.9;%基站间传输能量的损耗率
G= 18;%
r=1000000;%用户设备传输速率,bit,1Mb/s
c=0.2;%冷却时间的约束,最多占时隙的百分比
d=200;%m,%基站到用户设备的距离,假定同一基站距离用户对的距离是相同的。
q= 100;%噪声功率电平10DB的平方
for V=0:20:100
for t=0:1:5000
L=normrnd(0,5.8);%生成一个正态分布随机数
L=(6.14+20log10(200)+L)18;%路径损耗基站天线增益18DB用户天线增益0DB
if t==0 %冷却时间和能量队列的初始值
F=[0,0,0,0,0,0];
E=[0,0,0,0,0,0];
B=[0,0,0,0,0,0];
end
%重复以下步骤,利用cvx解决优化问题来获得P和m
a= unifrnd(0,20,1,1);%dBm
b=unifrnd(20,40,1,1);%dBm
e =unifrnd (a,b,1,6);%dBm,基站收集的能量均匀分布,生成一个随机数向量
cvx_begin
variable p(6) nonnegative;%非负
variable m(6,6) nonnegative;%非负
Objective = 0;
m1=[0,0,0,0,0,0];
m2=[0,0,0,0,0,0];
for j=1:6
for x=1:6
if x~=j
m1(j)=m1(j)+m(j,x);
end
end
for x=1:6
if x~=j
m2(j)=m2(j)+m(x,j);
end
end
F=F(j);
E=E(j);
B=B(j);
e=e(j);
Objective = Objective + ding(p,m1,m2);%自定义函数ding
end
minimize(Objective)
subject to
for j=1:1:6
for x=1:6
if x~=j
m1(j)=m1(j)+m(j,x);
end
end
for x=1:6
if x~=j
m2(j)=m2(j)+m(x,j);
end
end
P(j) <= E(j)+nm2(j)-m1(j);
end
cvx_end
%更新冷却时间队列长度,更新能量队列长度,更新用户设备数据存储
E1=0;
E2=0;
F1=0;
F2=0;
for j=1:6
for x=1:6
if x~=j
m1=m1+m(j,x);
end
end
for x=1:6
if x~=j
m2(j)=m2(j)+m(x,j);
end
end
F(j)=F(j)+1-log2(3q+p(j)L)/3r-B(j)/r-log2(3q)/3r-c;
E(j)=E(j)-P(j)+e(j)-m1(j)+nm2(j) ;
B(j)=B(j)-r(log2(3q+p(j)L)/3r+B(j)/r+log2(3q)/(3r))+log2(1+p(j)L/q)/3;
E1=E1+E(j);%6个基站的电池电量相加
F1=F1+3F(j);%6个基站分别对应三个视频设备,等待时间相加
end
end
figure(1);
plot(t,E1);
figure(2);
plot(t,F1);
figure(3);
plot(t,M1);
end
function result1 = ding( p,m1,m2 )
result1=(F+V)(c/r)(3r-(log(1+(pL)/300)/log(2))+3B)+(E+V)p+Ee+(V(1-n)-E)m1+nE*m2;
end