# Although the status shows field but it can solve for the correct value and there is a slight drop in the output value when convergence is near, what are the reasons for these problems and how can they be solved?

close all;clc;clear all;
f = 2.5E9; c = 3E8; lambda = c/f;
C0 = db2pow(-30); d0=1;
M=6; Mc=3;Mr=3;%3根通信天线，3根感知天线
A = 3;B = 3;%RIS行和列
N=A*B;
Pmax= db2pow(70);

[BS_Pos, BS_y] = BS_Generation(lambda, M);%RIS和BS坐标建的三维，实际二维
[RIS_Pos, RIS_y] = RIS_Generation(lambda,A,B);
User_Pos1 = [0,0]; User_y1 = 3; %用户1坐标
User_Pos2 = [0,0]; User_y2 = 4; %用户2坐标
User_Pos3 = [0,0]; User_y3 = 2; %用户3坐标
User_Pos4 = [1,0]; User_y4 = 3; %用户4坐标
User_Pos5 = [-1,0]; User_y5 = 3; %用户5坐标
Eve_Pos = [0,0]; Eve_y =15 ; %Eve坐标

%%求各个信道路损
%Gc路损
beta_gc=C0*(sqrt(50)/d0)^(-3.5);
%Gr路损
beta_gr=C0*(sqrt(50)/d0)^(-3.5);
%Hk路损
for i=1:1:5
Lhk = [29,26,34,20,40];
beta_hk(i)=C0*(sqrt(Lhk(i))/d0)^(-3.5);
end
%He路损
beta_he=C0*(sqrt(125)/d0)^(-3.5);
%Dck路损
for i=1:1:5
Lck = [109,116,104,90,130];
beta_dck(i) = C0*(sqrt(Lck(i))/d0)^(-3.5);
end
%Dce路损
beta_dce=C0*(sqrt(325)/d0)^(-3.5);ac_BS_Eve=0.1;
%Drk路损
for i = 1:1:5;
Lrk = [109,116,104,90,130];
beta_drk(i) = C0*(sqrt(Lrk(i))/d0)^(-3.5);
end
%Dre路损
beta_dre=C0*(sqrt(325)/d0)^(-3.5);
%
ac_BS_RIS = 0.1;ar_BS_RIS = 0.1;ak_RIS_UE = 0.1;ae_RIS_Eve = 0.1;ack_BS_UE = 0.1;ark_BS_UE = 0.1;ar_BS_UE=0.1;

[Gc,Gc_00,Gc_01,Gc_10,Gc_11] = channel_Gc(Mc,A,B,ac_BS_RIS,beta_gc);%BS的Mc到RIS
[Gr,Gr_00,Gr_10] = channel_Gr(Mr,A,B,ar_BS_RIS,beta_gr);%BS的Mr到RIS
[Hk,hk_00,hk_01,hk_10,hk_11] = channel_Hk(A,B,ak_RIS_UE,beta_hk);%RIS到5个用户
[He,he_00,he_01,he_10,he_11] = channel_He(A,B,ae_RIS_Eve,beta_he);%RIS到Eve
[Dck,dck_00,dck_01,dck_10,dck_11] = channel_Dck(ack_BS_UE, beta_dck, Mc);%BS的Mc到UE
[Dce,dce_00,dce_01,dce_10,dce_11] = channel_Dce(ac_BS_Eve, beta_dce, Mc);%BS的Mc到Eve
[Drk,drk_00,drk_01,drk_10,drk_11] = channel_Drk(ark_BS_UE, beta_drk, Mr);%BS的Mr到UE
[Dre,dre_00,dre_01,dre_10,dre_11] = channel_Dre(ar_BS_UE, beta_dre, Mr);%BS的Mr到Eve
[Ck_00,Ck_01,Ck_10,Ck_11,Ce_00,Ce_11,Re_0,Re_1,Rk_0,Rk_1]=CK_CE_Re_Rk(dce_00,dce_11,dck_00,dck_01,dck_10,dck_11,dre_00,dre_10,drk_00,drk_10,Gc_00,Gc_01,Gc_10,Gc_11,Gr_00,Gr_10,he_00,he_01,he_10,he_11,hk_00,hk_01,hk_10,hk_11);
%初始化
S00 =normrnd(0, 0.0001, 3, 3);
S01 =normrnd(0, 0.0001, 3, 3);
A = 0.5*ULA_aM(0,3)ULA_aM(0,3)';
gamma00 = [1,1,1,1,1];
gamma10 = [1,1,1,1,1];
gammae00 = [1,1,1,1,1];
gammae10 = [1,1,1,1,1];
a0 = [1,1,1,1,1];
c0 = [1,1,1,1,1];
nk0 = [1,1,1,1,1];
nk1 = [1,1,1,1,1];
for j = 1:20%更新
if j~= 1
for i=1:1:5
if aa==1
gamma00(i) = gamma0(i);
gamma10(i) = gamma1(i);
gammae00(i) = gammae0(i);
gammae10(i) = gammae1(i);
a0(i) = a(i);
c0(i) = c(i);
nk0(i) = sqrt( real(trace(Ck_01(:,:,i)Wk_1(:,:,i))+trace(Rk_0(:,:,i)'Rq)+1)inv_pos(gamma0(i)));
nk1(i) = sqrt( real(trace(Ck_10(:,:,i)Wk_0(:,:,i))+trace(Rk_1(:,:,i)‘Rq)+1)inv_pos(gamma1(i)));
end
end
end
cvx_begin
variable alpha0 %用户速率
variable beta0 %窃听速率
variable Wk_0(3,3,5) complex semidefinite
variable Wk_1(3,3,5) complex semidefinite
variable Rq(3,3) complex semidefinite
variable gamma0(5)
variable gamma1(5)
variable gammae0(5)
variable gammae1(5)
variable a(5) nonnegative
variable b(5) nonnegative
variable c(5) nonnegative
variable d(5) nonnegative
maximize (alpha0-beta0)%目标函数
subject to
%c1
tr = 0;
for i = 1:1:5
tr = tr + real(trace(Wk_0(:,:,i)) + trace(Wk_1(:,:,i)));
end
tr + trace(Rq)<= Pmax;
%c3’
for i = 1:1:5
real(trace(A
Rq
A’)) >= 0.5
real(trace(S00
Wk_0(:,:,i)S00’ + S01Wk_1(:,:,i)S01’ + eye(Mr,Mr)));
end
%c4
trr = 0;
for i = 1:1:5
trr = trr + log(1+gamma0(i))/1 + log(1+gamma1(i))/1;
end
alpha0 <= real(trr);
%c5’
trrr=0;
for i=1:1:5
trrr = trrr + log(1+gammae00(i))/1+(gammae0(i)-gammae00(i))/(1+gammae00(i))+log(1+gammae10(i))/1+(gammae1(i)-gammae10(i))/(1+gammae10(i));
end
beta0 >= real(trrr);
%c6’
v = 0;
for i = 1:1:5
v = v + real(trace(Ck_01(:,:,i)Wk_1(:,:,i)));
end
for i = 1:1:5
real(trace(Ck_00(:,:,i)Wk_0(:,:,i))) >= 0.5(nk0(i)gamma0(i))^2 + 0.5(real(v + trace(Rk_0(:,:,i)'Rq)+1)/(nk0(i)))^2;
end
%c7
x = 0;
for i = 1:1:5
x = x + real(trace(Ck_10(:,:,i)Wk_0(:,:,i)));
end
for i = 1:1:5
real(trace(Ck_11(:,:,i)Wk_1(:,:,i))) >= 0.5(nk1(i)gamma1(i))^2 + 0.5(real(x + trace(Rk_1(:,:,i)'Rq) + 1)/(nk1(i)))^2;
end
%c12’
for i = 1:1:5
(gammae0(i)+b(i))/2 >= norm([(gammae0(i)-b(i))/2,a(i)]‘,‘fro’);
end
%c13’
for i = 1:1:5
a0(i)^2+2
a0(i)
(a(i)-a0(i)) >= real(trace(Ce_00
Wk_0(:,:,i)));
end
%c14
for i = 1:1:5
real(trace(Re_0
Rq))+1 >= b(i);
end
%c15
for i=1:1:5
(gammae1(i)+d(i))/2 >= norm([(gammae1(i)-d(i))/2,c(i)]',‘fro’);
end
%c16
for i=1:1:5
c0(i)^2+2
c0(i)
(c(i)-c0(i)) >= real(trace(Ce_11
Wk_1(:,:,i)));
end
%c17
for i = 1:1:5
real(trace(Re_1
Rq))+1 >= d(i);
end
cvx_end

m(j) = alpha0-beta0
alpha00(j) = alpha0
beta00(j) = beta0
if j==1
aa=1;
continue
end
aa=1;
if m(j) < m(j-1)
m(j) = m(j-1);
aa=0;
continue
end
if m(j) - m(j-1) <= 0.05
break
end
end
plot(1:1:j-1,m(1:j-1),‘-or’,‘LineWidth’,2)

In the output section, whenever there is a drop I make the previous value overwrite the

I doubt anyone has a clue what this is about.

As with @Erling , I’m not sure what you are talking about.

But I will make a guess that you are calling CVX in an iterative manner, such as SCA, and do not find the overall SCA algorithm to be performing as you would like. For instance, the optimal objective value (per SCA iteration) is not monotonically increasing (i.e., improving, given that you are performing maximization) . If so, see