# Mosek求解器，cvx索引超出数组范围。

cvx_solver Mosek
cvx_save_prefs
cvx_begin quiet
variable W_r(N,N) hermitian semidefinite
variable W_t(N,N) hermitian semidefinite
variable F_f(J,J) hermitian semidefinite
variables lamda_br chi_br(L1)
variables lamda_jr chi_jr(L1)
variables lamda_bt chi_bt(L2)
variables lamda_jt chi_jt(L2)
variables x1 x2
expressions T_burr T_bu_rr T_jurr …
T_butt T_bu_tt T_jutt …
A_br(M+1,M+1,L1) A_bt(M+1,M+1,L2)…
A_jr(M+1,M+1,L1) A_jt(M+1,M+1,L2)…
B1t(M,M,L2) B2t(M,1,L2) B3t(1,M,L2) B4t(1,L2)…
J1t(M,M,L2) J2t(M,1,L2) J3t(1,M,L2) J4t(1,L2)…
B1r(M,M,L1) B2r(M,1,L1) B3r(1,M,L1) B4r(1,L1)…
J1r(M,M,L1) J2r(M,1,L1) J3r(1,M,L1) J4r(1,L1)…
Pha1_r Pha2_r Pha1_t Pha2_t
%%%%r区
T_bur=(trace(HH_bu_rWr));%%%%%SDR开始
T_bu_r=(trace(HH_bu_r
Wt));
T_jur=trace(GG_ju_r*Ff);
t_ur=1/((T_bu_r+T_jur)+a0);

``````        T_burr=trace(HH_bu_r*W_r);
T_bu_rr=trace(HH_bu_r*W_t);
T_jurr=trace(GG_ju_r*F_f);

Pha1_r=real(-t_ur*((T_bu_rr+T_jurr)+a0)+log(t_ur)+1)+...
log_det(real(T_burr+(T_bu_rr+T_jurr)+a0));
%%%%t区
T_but=trace(HH_bu_t*Wt);%%%%%SDR开始
T_bu_t=trace(HH_bu_t*Wr);
T_jut=trace(GG_ju_t*Ff);
t_ut=1/((T_bu_t+T_jut)+a0);%%%%%引用引理

T_butt=trace(HH_bu_t*W_t);%%%%%SDR开始
T_bu_tt=trace(HH_bu_t*W_r);
T_jutt=trace(GG_ju_t*F_f);

Pha1_t=real(-t_ut*((T_bu_tt+T_jutt)+a0)+log(t_ut)+1)+...
log_det(real(T_butt+T_bu_tt+T_jutt+a0));

for l1=1:L1
B1r(:,:,l1)=lamda_br*eye(M)-h_be_r*W_r*h_be_r';
B2r(:,:,l1)=-h_be_r*W_r*h_be_r'*H_ie_r(:,l1);
B3r(:,:,l1)=-H_ie_r(:,l1)'*h_be_r*W_r*h_be_r';
B4r(:,l1)=-lamda_br*S_be^(2)-...
H_ie_r(:,l1)'*h_be_r*W_r*h_be_r'*H_ie_r(:,l1)+chi_br(l1) ;
A_br(:,:,l1)=[B1r(:,:,l1),B2r(:,:,l1);B3r(:,:,l1),B4r(:,l1)];

Gamma_wr=trace(Wrx*(H_ie_r(:,l1)*H_ie_r(:,l1)'+S_be^(2)*eye(M)+...
2*S_be*sqrt(eye(M)*(H_ie_r(:,l1)'*Wrx*H_true_br(:,l1))/trace(Wrx))));

J1r(:,:,l1)=lamda_jr*eye(M)+h_je_r*F_f*h_je_r';
J2r(:,:,l1)=h_je_r*F_f*h_je_r'*H_ie_r(:,l1);
J3r(:,:,l1)=H_ie_r(:,l1)'*h_je_r*F_f*h_je_r';
J4r(:,l1)=-lamda_jr*S_je^(2)+...
H_ie_r(:,l1)'*h_je_r*F_f*h_je_r'*H_ie_r(:,l1)-chi_jr(l1) ;
A_jr(:,:,l1)=[J1r(:,:,l1),J2r(:,:,l1);J3r(:,:,l1),J4r(:,l1)];

Gamma_fr=trace(Frx*(H_ie_r(:,l1)*H_ie_r(:,l1)'+S_je^(2)*eye(M)-...
2*S_je*sqrt(eye(M)*(H_ie_r(:,l1)'*Frx*H_true_jr(:,l1))/trace(Frx))));
t1=(Gamma_wr+Gamma_fr+a0)^(-1);
Pha2_r(:,l1)=real(t1*(chi_br(l1)+chi_jr(l1)+a0)-log(t1)-1)-log_det(real(chi_br(l1)+a0));
end

for l2=1:L2
B1t(:,:,l2)=lamda_bt*eye(M)-h_be_t*W_t*h_be_t';
B2t(:,:,l2)=-h_be_t*W_t*h_be_t'*H_ie_t(:,l2);
B3t(:,:,l2)=-H_ie_t(:,l2)'*h_be_t*W_t*h_be_t';
B4t(:,l2)=-lamda_bt*S_be^(2)-...
H_ie_t(:,l2)'*h_be_t*W_t*h_be_t'*H_ie_t(:,l2)+chi_bt(l2) ;
A_bt(:,:,l2)=[B1t(:,:,l2),B2t(:,:,l2);B3t(:,:,l2),B4t(:,l2)];
Gamma_wt=trace(Wtx*(H_ie_t(:,l2)*H_ie_t(:,l2)'+S_be^(2)*eye(M)+...
2*S_be*sqrt(eye(M)*(H_ie_t(:,l2)'*Wtx*H_true_bt(:,l2))/trace(Wtx))));

J1t(:,:,l2)=lamda_jt*eye(M)+h_je_t*F_f*h_je_t';
J2t(:,:,l2)=h_je_t*F_f*h_je_t'*H_ie_t(:,l2);
J3t(:,:,l2)=H_ie_t(:,l2)'*h_je_t*F_f*h_je_t';
J4t(:,l2)=-lamda_jt*S_je^(2)+...
H_ie_t(:,l2)'*h_je_t*F_f*h_je_t'*H_ie_t(:,l2)-chi_jt(l2) ;
A_jt(:,:,l2)=[J1t(:,:,l2),J2t(:,:,l2);J3t(:,:,l2),J4t(:,l2)];
Gamma_ft=trace(Ftx*(H_ie_t(:,l2)*H_ie_t(:,l2)'+S_je^(2)*eye(M)-...
2*S_je*sqrt(eye(M)*(H_ie_t(:,l2)'*Ftx*H_true_jt(:,l2))/trace(Ftx))));

t2=(Gamma_wt+Gamma_ft+a0)^(-1);
Pha2_t(:,l2)=real(t2*(chi_bt(l2)+chi_jt(l2)+a0)-log(t2)-1)-log_det(real(chi_bt(l2)+a0));
end

maximize B/log(2)*(nr*(Pha1_r-x1))+...
B/log(2)*(nt*(Pha1_t-x2))
subject to
x1>=0;
x2>=0;
real(trace(W_r+W_t))<=P1_max(ll);
real(trace(F_f))<=Pn;
for  l1=1:L1
Pha2_r(:,l1)<=x1;
A_br(:,:,l1) == hermitian_semidefinite(M+1);
A_jr(:,:,l1) == hermitian_semidefinite(M+1);
end
for  l2=1:L2
Pha2_t(:,l2)<=x2;
A_bt(:,:,l2) == hermitian_semidefinite(M+1);
A_jt(:,:,l2) == hermitian_semidefinite(M+1);
end
cvx_end
``````

P = P( :, colX ) + P( :, cols ) * temp;

[ At, cones, sgn, Q, P, dualized ] = eliminate( prob, true, shim.dualize );

solve( prob );

cvx_end
%%%%%%%%%%%%%

It will make matters less confusing if you stick with one user name, and put all posts on the same topic in the same topic.

As for this error message, are you using CVX 3.0beta? if so, don’t; use CVX 2.2. instead. if you are already using CVX 2.2, try a new MATLAB session. If that doesn’t work, try a different solver, try reinstalling CVX in a new MATLAB session, or try rebooting. If none of those work, I don’t know what to do.

To see what version of CVX you are using, issue the command
`cvx_version`

1 Like

close all;
clear all;clc;
N=8;
J=8;
M=20;

L1 =2;
L2 =2;

P_noise=10^((-95-30)/10);%-80dBm

p1_max=5:5:5;%dbm
pn=15;
P1_max=10.^(p1_max./10)/1000;%W
Pn=10.^(pn./10)/1000;

B=1;
accuracy=1e-3;%%%精度
L0=200;%最大迭代次数,作用是如果不成立，不至于一直在循环里面，最多让他执行40次看结果

nr=0.5;%%%%%权重因子
nt=0.5;
S_je=10^-4;
S_be=10^-4;

num_loop=1;
finnal_Rondom=zeros(num_loop,length(p1_max));
finnal_R=zeros(1,length(p1_max));
C_w_er=zeros(1,L1); H_true_jr=zeros(M,L1); H_true_jt=zeros(M,L2);
R_w_et=zeros(1,L1); H_true_br=zeros(M,L1); H_true_bt=zeros(M,L2);
R_w_er=zeros(1,L2);
error=0.01;
for loop=1:num_loop

``````H_bu_r=HHH_bu_r(1:M,1:N,loop)/sqrt(P_noise);
H_bu_t=HHH_bu_t(1:M,1:N,loop)/sqrt(P_noise);
G_ju_t=GGG_ju_t(1:M,1:J,loop)/sqrt(P_noise);
G_ju_r=GGG_ju_r(1:M,1:J,loop)/sqrt(P_noise);

H_ie_r=H_IE_r(1:M,1:L1,loop)/sqrt(P_noise);
H_ie_t=H_IE_t(1:M,1:L2,loop)/sqrt(P_noise);
H=H_b_ALL(1:M,1:N,loop)/sqrt(P_noise);
G=H_j_ALL(1:M,1:J,loop)/sqrt(P_noise);
a0=1;

for l1=1:L1
Hjr(l1)=error*norm(H_ie_r(:,l1),2);
temp_jr=sqrt(1/2)*(randn(M,1) + sqrt(-1)*randn(M,1));
H_error_j_r(:,l1)=Hjr(l1)*temp_jr/(norm(temp_jr ,2)^2)*rand(1);
H_true_jr(:,l1)=H_error_j_r(:,l1)+H_ie_r(:,l1);

Hbr(l1)=error*norm(H_ie_r(:,l1),2);
temp_br=sqrt(1/2)*(randn(M,1) + sqrt(-1)*randn(M,1));
H_error_b_r(:,l1)=Hbr(l1)*temp_br/(norm(temp_br ,2)^2)*rand(1);
H_true_br(:,l1)=H_error_b_r(:,l1)+H_ie_r(:,l1);
end
for l2=1:L2
Hjt(l2)=error*norm(H_ie_t(:,l2),2);
temp_jt=sqrt(1/2)*(randn(M,1) + sqrt(-1)*randn(M,1));
H_error_j_t(:,l2)=Hjt(l2)*temp_jt/(norm(temp_jt ,2)^2)*rand(1);
H_true_jt(:,l2)=H_error_j_t(:,l2)+H_ie_t(:,l2);

Hbt(l2)=error*norm(H_ie_t(:,l2),2);
temp_bt=sqrt(1/2)*(randn(M,1) + sqrt(-1)*randn(M,1));
H_error_b_t(:,l2)=Hbt(l2)*temp_bt/(norm(temp_bt ,2)^2)*rand(1);
H_true_bt(:,l2)=H_error_b_t(:,l2)+H_ie_t(:,l2);
end

for  ll = 1:length(p1_max)
wr=ones(N,1)*sqrt(P1_max(ll)/(2*N));
wt=ones(N,1)*sqrt(P1_max(ll)/(2*N));
f=ones(J,1)*sqrt(Pn/J);
Wr=wr*wr';
Wt=wt*wt';
Ff=f*f';

alpha_r_vec=sqrt(1/2)*ones(M,1);
theta_r_vec=2*pi*rand(M,1);
vr=alpha_r_vec.*exp(1i*theta_r_vec);
alpha_t_vec=sqrt(1/2)*ones(M,1);
theta_t_vec=2*pi*rand(M,1);
vt=alpha_t_vec.*exp(1i*theta_t_vec);

R0=0;
kk=0;
``````

% while(1)

``````        da_vr=diag(vr);
da_vt=diag(vt);
%%%%%%%%%%%%%%%r区
%y用户
h_bu_r=vr'*H_bu_r;%%基站
HH_bu_r=h_bu_r'*h_bu_r;

g_ju_r=vr'*G_ju_r;%%jammer
GG_ju_r=g_ju_r'*g_ju_r;

%Eve
h_be_r=da_vr*H;
h_je_r=da_vr*G;
Wrx=h_be_r*Wr*h_be_r';
Frx=h_je_r*Ff*h_je_r';

%         for l1=1:L1
%             h_be_r=da_vr*H;
%             HH_be_r(:,:,l1)=H_ie_r(:,l1)'*h_be_r;
%
%             g_je_r=da_vr*G;
%             GG_je_r(:,:,l1)=H_ie_r(:,l1)'*g_je_r;
%         end

%%%%%%%%%%%%%%%t区
%y用户
h_bu_t=vt'*H_bu_t;%%基站
HH_bu_t=h_bu_t'*h_bu_t;

g_ju_t=vt'*G_ju_t;%%jammer
GG_ju_t=g_ju_t'*g_ju_t;

%Eve
h_be_t=da_vt*H;
h_je_t=da_vt*G;
Wtx=h_be_t*Wt*h_be_t';
Ftx=h_je_t*Ff*h_je_t';
%         for l2=1:L2
%             h_be_t=da_vt*H;
%             HH_be_t(:,:,l2)=H_ie_t(:,l2)'*h_be_t;
%
%             g_je_t=da_vr*G;
%             GG_je_t(:,:,l2)=H_ie_r(:,l2)'*g_je_t;
%         end

cvx_solver Mosek
cvx_save_prefs
cvx_begin quiet
variable W_r(N,N) hermitian  semidefinite
variable W_t(N,N) hermitian  semidefinite
variable F_f(J,J)  hermitian  semidefinite
variables lamda_br chi_br(L1)
variables lamda_jr chi_jr(L1)
variables lamda_bt chi_bt(L2)
variables lamda_jt chi_jt(L2)
variables x1 x2
expressions  T_burr T_bu_rr T_jurr ...
T_butt T_bu_tt T_jutt ...
A_br(M+1,M+1,L1) A_bt(M+1,M+1,L2)...
A_jr(M+1,M+1,L1) A_jt(M+1,M+1,L2)...
B1t(M,M,L2) B2t(M,1,L2) B3t(1,M,L2) B4t(1,L2)...
J1t(M,M,L2) J2t(M,1,L2) J3t(1,M,L2) J4t(1,L2)...
B1r(M,M,L1) B2r(M,1,L1) B3r(1,M,L1) B4r(1,L1)...
J1r(M,M,L1) J2r(M,1,L1) J3r(1,M,L1) J4r(1,L1)...
Pha1_r Pha2_r Pha1_t Pha2_t
%%%%r区
T_bur=(trace(HH_bu_r*Wr));%%%%%SDR开始
T_bu_r=(trace(HH_bu_r*Wt));
T_jur=trace(GG_ju_r*Ff);
t_ur=1/((T_bu_r+T_jur)+a0);

T_burr=trace(HH_bu_r*W_r);
T_bu_rr=trace(HH_bu_r*W_t);
T_jurr=trace(GG_ju_r*F_f);

Pha1_r=real(-t_ur*((T_bu_rr+T_jurr)+a0)+log(t_ur)+1)+...
log_det(real(T_burr+(T_bu_rr+T_jurr)+a0));
%%%%t区
T_but=trace(HH_bu_t*Wt);%%%%%SDR开始
T_bu_t=trace(HH_bu_t*Wr);
T_jut=trace(GG_ju_t*Ff);
t_ut=1/((T_bu_t+T_jut)+a0);%%%%%引用引理

T_butt=trace(HH_bu_t*W_t);%%%%%SDR开始
T_bu_tt=trace(HH_bu_t*W_r);
T_jutt=trace(GG_ju_t*F_f);

Pha1_t=real(-t_ut*((T_bu_tt+T_jutt)+a0)+log(t_ut)+1)+...
log_det(real(T_butt+T_bu_tt+T_jutt+a0));

for l1=1:L1
B1r(:,:,l1)=lamda_br*eye(M)-h_be_r*W_r*h_be_r';
B2r(:,:,l1)=-h_be_r*W_r*h_be_r'*H_ie_r(:,l1);
B3r(:,:,l1)=-H_ie_r(:,l1)'*h_be_r*W_r*h_be_r';
B4r(:,l1)=-lamda_br*S_be^(2)-...
H_ie_r(:,l1)'*h_be_r*W_r*h_be_r'*H_ie_r(:,l1)+chi_br(l1) ;
A_br(:,:,l1)=[B1r(:,:,l1),B2r(:,:,l1);B3r(:,:,l1),B4r(:,l1)];

Gamma_wr=trace(Wrx*(H_ie_r(:,l1)*H_ie_r(:,l1)'+S_be^(2)*eye(M)+...
2*S_be*sqrt(eye(M)*(H_ie_r(:,l1)'*Wrx*H_true_br(:,l1))/trace(Wrx))));

J1r(:,:,l1)=lamda_jr*eye(M)+h_je_r*F_f*h_je_r';
J2r(:,:,l1)=h_je_r*F_f*h_je_r'*H_ie_r(:,l1);
J3r(:,:,l1)=H_ie_r(:,l1)'*h_je_r*F_f*h_je_r';
J4r(:,l1)=-lamda_jr*S_je^(2)+...
H_ie_r(:,l1)'*h_je_r*F_f*h_je_r'*H_ie_r(:,l1)-chi_jr(l1) ;
A_jr(:,:,l1)=[J1r(:,:,l1),J2r(:,:,l1);J3r(:,:,l1),J4r(:,l1)];

Gamma_fr=trace(Frx*(H_ie_r(:,l1)*H_ie_r(:,l1)'+S_je^(2)*eye(M)-...
2*S_je*sqrt(eye(M)*(H_ie_r(:,l1)'*Frx*H_true_jr(:,l1))/trace(Frx))));
t1=(Gamma_wr+Gamma_fr+a0)^(-1);
Pha2_r(:,l1)=real(t1*(chi_br(l1)+chi_jr(l1)+a0)-log(t1)-1)-log_det(real(chi_br(l1)+a0));
end

for l2=1:L2
B1t(:,:,l2)=lamda_bt*eye(M)-h_be_t*W_t*h_be_t';
B2t(:,:,l2)=-h_be_t*W_t*h_be_t'*H_ie_t(:,l2);
B3t(:,:,l2)=-H_ie_t(:,l2)'*h_be_t*W_t*h_be_t';
B4t(:,l2)=-lamda_bt*S_be^(2)-...
H_ie_t(:,l2)'*h_be_t*W_t*h_be_t'*H_ie_t(:,l2)+chi_bt(l2) ;
A_bt(:,:,l2)=[B1t(:,:,l2),B2t(:,:,l2);B3t(:,:,l2),B4t(:,l2)];
Gamma_wt=trace(Wtx*(H_ie_t(:,l2)*H_ie_t(:,l2)'+S_be^(2)*eye(M)+...
2*S_be*sqrt(eye(M)*(H_ie_t(:,l2)'*Wtx*H_true_bt(:,l2))/trace(Wtx))));

J1t(:,:,l2)=lamda_jt*eye(M)+h_je_t*F_f*h_je_t';
J2t(:,:,l2)=h_je_t*F_f*h_je_t'*H_ie_t(:,l2);
J3t(:,:,l2)=H_ie_t(:,l2)'*h_je_t*F_f*h_je_t';
J4t(:,l2)=-lamda_jt*S_je^(2)+...
H_ie_t(:,l2)'*h_je_t*F_f*h_je_t'*H_ie_t(:,l2)-chi_jt(l2) ;
A_jt(:,:,l2)=[J1t(:,:,l2),J2t(:,:,l2);J3t(:,:,l2),J4t(:,l2)];
Gamma_ft=trace(Ftx*(H_ie_t(:,l2)*H_ie_t(:,l2)'+S_je^(2)*eye(M)-...
2*S_je*sqrt(eye(M)*(H_ie_t(:,l2)'*Ftx*H_true_jt(:,l2))/trace(Ftx))));

t2=(Gamma_wt+Gamma_ft+a0)^(-1);
Pha2_t(:,l2)=real(t2*(chi_bt(l2)+chi_jt(l2)+a0)-log(t2)-1)-log_det(real(chi_bt(l2)+a0));
end

maximize B/log(2)*(nr*(Pha1_r-x1))+...
B/log(2)*(nt*(Pha1_t-x2))
subject to
x1>=0;
x2>=0;
real(trace(W_r+W_t))<=P1_max(ll);
real(trace(F_f))<=Pn;
for  l1=1:L1
Pha2_r(:,l1)<=x1;
A_br(:,:,l1) == hermitian_semidefinite(M+1);
A_jr(:,:,l1) == hermitian_semidefinite(M+1);
end
for  l2=1:L2
Pha2_t(:,l2)<=x2;
A_bt(:,:,l2) == hermitian_semidefinite(M+1);
A_jt(:,:,l2) == hermitian_semidefinite(M+1);
end
cvx_end
``````

You should look at the CVX and solver output to see why `NaN` occurs. You should also look at the output from Mosek to see if it issues warnings, such as near zero or very large input data. If things are not running perfectly, do NOT use `quiet`, that way you can see the CVX and solver (Mosek) output.

Unsafeguarded (no line search or trust region)Successive Convex Approximation (SCA) is unreliable. It might not descend (for minimization problem), i.e., iterates could get worse. It might not converge to anything; and if it does converge, it might not be to a local optimum of the original problem, let alone a global optimum. The solution of successive iterations, and therefore subproblem inputs, can become wilder and wilder, until at some point the solver fails, or makes erroneous determination of infeasibility or unboundedness.

``````Don’t apply crude, unsafeguarded (no Trust Region or Line Search) Successive Convex Approximation (SCA) to a new problem … unless your name happens to be Stephen Boyd.

There’s a reason high quality non-convex nonlinear optimization solvers are more than 10 lines long.
``````
1 Like

A_br、A_jr、A_bt、A_jt这四个约束都是一样的公式，为什么可以存在其中2个，但是4个都存在，就会报出索引错误，索引超出数组范围。

P = P( :, colX ) + P( :, cols ) * temp;

[ At, cones, sgn, Q, P, dualized ] = eliminate( prob, true, shim.dualize );

solve( prob );

cvx_end

Errors in cvxprob/eliminate or cvxprob/solve are indicative of a corrupted MATLAB session, corrupted CVX installation, or a bug. It is possible that the bug or consequences of corruption only manifest themselves in certain situations.

Saving prefs…done.

P = P( :, colX ) + P( :, cols ) * temp;

[ At, cones, sgn, Q, P, dualized ] = eliminate( prob, true, shim.dualize );

solve( prob );

cvx_end

close all;
clear all;clc;
N=8;
J=8;
M=20;

L1 =2;
L2 =2;

P_noise=10^((-95-30)/10);%-80dBm

p1_max=-5:5:15;%dbm
pn=15;
P1_max=10.^(p1_max./10)/1000;%W
Pn=10.^(pn./10)/1000;

B=1;
accuracy=1e-3;%%%精度
L0=200;%最大迭代次数,作用是如果不成立，不至于一直在循环里面，最多让他执行40次看结果

nr=0.5;%%%%%权重因子
nt=0.5;
S_je=10^-4;
S_be=10^-4;

num_loop=1;
finnal_Rondom=zeros(num_loop,length(p1_max));
finnal_R=zeros(1,length(p1_max));
C_w_er=zeros(1,L1); H_true_jr=zeros(M,L1); H_true_jt=zeros(M,L2);
R_w_et=zeros(1,L1); H_true_br=zeros(M,L1); H_true_bt=zeros(M,L2);
R_w_er=zeros(1,L2);
error=0.0001;
for loop=1:num_loop

``````H_bu_r=HHH_bu_r(1:M,1:N,loop)/sqrt(P_noise);
H_bu_t=HHH_bu_t(1:M,1:N,loop)/sqrt(P_noise);
G_ju_t=GGG_ju_t(1:M,1:J,loop)/sqrt(P_noise);
G_ju_r=GGG_ju_r(1:M,1:J,loop)/sqrt(P_noise);

H_ie_r=H_IE_r(1:M,1:L1,loop)/sqrt(P_noise);
H_ie_t=H_IE_t(1:M,1:L2,loop)/sqrt(P_noise);
H=H_b_ALL(1:M,1:N,loop)/sqrt(P_noise);
G=H_j_ALL(1:M,1:J,loop)/sqrt(P_noise);
a0=1;

for l1=1:L1
Hjr(l1)=error*norm(H_ie_r(:,l1),2);
temp_jr=sqrt(1/2)*(randn(M,1) + sqrt(-1)*randn(M,1));
H_error_j_r(:,l1)=Hjr(l1)*temp_jr/(norm(temp_jr ,2)^2)*rand(1);
H_true_jr(:,l1)=H_error_j_r(:,l1)+H_ie_r(:,l1);

Hbr(l1)=error*norm(H_ie_r(:,l1),2);
temp_br=sqrt(1/2)*(randn(M,1) + sqrt(-1)*randn(M,1));
H_error_b_r(:,l1)=Hbr(l1)*temp_br/(norm(temp_br ,2)^2)*rand(1);
H_true_br(:,l1)=H_error_b_r(:,l1)+H_ie_r(:,l1);
end
for l2=1:L2
Hjt(l2)=error*norm(H_ie_t(:,l2),2);
temp_jt=sqrt(1/2)*(randn(M,1) + sqrt(-1)*randn(M,1));
H_error_j_t(:,l2)=Hjt(l2)*temp_jt/(norm(temp_jt ,2)^2)*rand(1);
H_true_jt(:,l2)=H_error_j_t(:,l2)+H_ie_t(:,l2);

Hbt(l2)=error*norm(H_ie_t(:,l2),2);
temp_bt=sqrt(1/2)*(randn(M,1) + sqrt(-1)*randn(M,1));
H_error_b_t(:,l2)=Hbt(l2)*temp_bt/(norm(temp_bt ,2)^2)*rand(1);
H_true_bt(:,l2)=H_error_b_t(:,l2)+H_ie_t(:,l2);
end

for  ll = 1:length(p1_max)
wr=ones(N,1)*sqrt(P1_max(ll)/(2*N));
wt=ones(N,1)*sqrt(P1_max(ll)/(2*N));
f=ones(J,1)*sqrt(Pn/J);
Wr=wr*wr';
Wt=wt*wt';
Ff=f*f';

alpha_r_vec=sqrt(1/2)*ones(M,1);
theta_r_vec=2*pi*rand(M,1);
vr=alpha_r_vec.*exp(1i*theta_r_vec);
alpha_t_vec=sqrt(1/2)*ones(M,1);
theta_t_vec=2*pi*rand(M,1);
vt=alpha_t_vec.*exp(1i*theta_t_vec);

R0=0;
kk=0;
``````

% while(1)

``````        da_vr=diag(vr);
da_vt=diag(vt);
%%%%%%%%%%%%%%%r区
%y用户
h_bu_r=vr'*H_bu_r;%%基站
HH_bu_r=h_bu_r'*h_bu_r;

g_ju_r=vr'*G_ju_r;%%jammer
GG_ju_r=g_ju_r'*g_ju_r;

%Eve
h_be_r=da_vr*H;
h_je_r=da_vr*G;
Wrx=h_be_r*Wr*h_be_r';
Frx=h_je_r*Ff*h_je_r';

%         for l1=1:L1
%             h_be_r=da_vr*H;
%             HH_be_r(:,:,l1)=H_ie_r(:,l1)'*h_be_r;
%
%             g_je_r=da_vr*G;
%             GG_je_r(:,:,l1)=H_ie_r(:,l1)'*g_je_r;
%         end

%%%%%%%%%%%%%%%t区
%y用户
h_bu_t=vt'*H_bu_t;%%基站
HH_bu_t=h_bu_t'*h_bu_t;

g_ju_t=vt'*G_ju_t;%%jammer
GG_ju_t=g_ju_t'*g_ju_t;

%Eve
h_be_t=da_vt*H;
h_je_t=da_vt*G;
Wtx=h_be_t*Wt*h_be_t';
Ftx=h_je_t*Ff*h_je_t';
%         for l2=1:L2
%             h_be_t=da_vt*H;
%             HH_be_t(:,:,l2)=H_ie_t(:,l2)'*h_be_t;
%
%             g_je_t=da_vr*G;
%             GG_je_t(:,:,l2)=H_ie_r(:,l2)'*g_je_t;
%         end

cvx_solver Mosek
cvx_save_prefs
cvx_begin quiet
variable W_r(N,N) hermitian  semidefinite
variable W_t(N,N) hermitian  semidefinite
variable F_f(J,J)  hermitian  semidefinite
variables lamda_br chi_br(L1)
variables lamda_jr chi_jr(L1)
variables lamda_bt chi_bt(L2)
variables lamda_jt chi_jt(L2)
variables x1 x2
expressions  T_burr T_bu_rr T_jurr ...
T_butt T_bu_tt T_jutt ...
A_br(M+1,M+1,L1) A_bt(M+1,M+1,L2)...
A_jr(M+1,M+1,L1) A_jt(M+1,M+1,L2)...
B1t(M,M,L2) B2t(M,1,L2) B3t(1,M,L2) B4t(1,L2)...
J1t(M,M,L2) J2t(M,1,L2) J3t(1,M,L2) J4t(1,L2)...
B1r(M,M,L1) B2r(M,1,L1) B3r(1,M,L1) B4r(1,L1)...
J1r(M,M,L1) J2r(M,1,L1) J3r(1,M,L1) J4r(1,L1)...
Pha1_r Pha2_r Pha1_t Pha2_t
%%%%r区
T_bur=(trace(HH_bu_r*Wr));%%%%%SDR开始
T_bu_r=(trace(HH_bu_r*Wt));
T_jur=trace(GG_ju_r*Ff);
t_ur=1/((T_bu_r+T_jur)+a0);

T_burr=trace(HH_bu_r*W_r);
T_bu_rr=trace(HH_bu_r*W_t);
T_jurr=trace(GG_ju_r*F_f);

Pha1_r=real(-t_ur*((T_bu_rr+T_jurr)+a0)+log(t_ur)+1)+...
log_det(real(T_burr+(T_bu_rr+T_jurr)+a0));
%%%%t区
T_but=trace(HH_bu_t*Wt);%%%%%SDR开始
T_bu_t=trace(HH_bu_t*Wr);
T_jut=trace(GG_ju_t*Ff);
t_ut=1/((T_bu_t+T_jut)+a0);%%%%%引用引理

T_butt=trace(HH_bu_t*W_t);%%%%%SDR开始
T_bu_tt=trace(HH_bu_t*W_r);
T_jutt=trace(GG_ju_t*F_f);

Pha1_t=real(-t_ut*((T_bu_tt+T_jutt)+a0)+log(t_ut)+1)+...
log_det(real(T_butt+T_bu_tt+T_jutt+a0));

for l1=1:L1
B1r(:,:,l1)=lamda_br*eye(M)-h_be_r*W_r*h_be_r';
B2r(:,:,l1)=-h_be_r*W_r*h_be_r'*H_ie_r(:,l1);
B3r(:,:,l1)=-H_ie_r(:,l1)'*h_be_r*W_r*h_be_r';
B4r(:,l1)=-lamda_br*exp(log(error)*2)-...
H_ie_r(:,l1)'*h_be_r*W_r*h_be_r'*H_ie_r(:,l1)+chi_br(l1) ;
A_br(:,:,l1)=[B1r(:,:,l1),B2r(:,:,l1);B3r(:,:,l1),B4r(:,l1)];

Gamma_wr=trace(Wrx*(H_ie_r(:,l1)*H_ie_r(:,l1)'+exp(log(error)*2)*eye(M)+...
2*error*sqrt(eye(M)*(H_ie_r(:,l1)'*Wrx*H_true_br(:,l1))/trace(Wrx))));

J1r(:,:,l1)=lamda_jr*eye(M)+h_je_r*F_f*h_je_r';
J2r(:,:,l1)=h_je_r*F_f*h_je_r'*H_ie_r(:,l1);
J3r(:,:,l1)=H_ie_r(:,l1)'*h_je_r*F_f*h_je_r';
J4r(:,l1)=-lamda_jr*exp(log(error)*2)+...
H_ie_r(:,l1)'*h_je_r*F_f*h_je_r'*H_ie_r(:,l1)-chi_jr(l1) ;
A_jr(:,:,l1)=[J1r(:,:,l1),J2r(:,:,l1);J3r(:,:,l1),J4r(:,l1)];

Gamma_fr=trace(Frx*(H_ie_r(:,l1)*H_ie_r(:,l1)'+exp(log(error)*2)*eye(M)-...
2*error*sqrt(eye(M)*(H_ie_r(:,l1)'*Frx*H_true_jr(:,l1))/trace(Frx))));
t1=real((Gamma_wr+Gamma_fr+a0)^(-1));
Pha2_r(:,l1)=real(t1*(chi_br(l1)+chi_jr(l1)+a0)-log(t1)-1)-log_det(real(chi_br(l1)+a0));
end

for l2=1:L2
B1t(:,:,l2)=lamda_bt*eye(M)-h_be_t*W_t*h_be_t';
B2t(:,:,l2)=-h_be_t*W_t*h_be_t'*H_ie_t(:,l2);
B3t(:,:,l2)=-H_ie_t(:,l2)'*h_be_t*W_t*h_be_t';
B4t(:,l2)=-lamda_bt*exp(log(error)*2)-...
H_ie_t(:,l2)'*h_be_t*W_t*h_be_t'*H_ie_t(:,l2)+chi_bt(l2) ;
A_bt(:,:,l2)=[B1t(:,:,l2),B2t(:,:,l2);B3t(:,:,l2),B4t(:,l2)];
Gamma_wt=trace(Wtx*(H_ie_t(:,l2)*H_ie_t(:,l2)'+exp(log(error)*2)*eye(M)+...
2*error*sqrt(eye(M)*(H_ie_t(:,l2)'*Wtx*H_true_bt(:,l2))/trace(Wtx))));

J1t(:,:,l2)=lamda_jt*eye(M)+h_je_t*F_f*h_je_t';
J2t(:,:,l2)=h_je_t*F_f*h_je_t'*H_ie_t(:,l2);
J3t(:,:,l2)=H_ie_t(:,l2)'*h_je_t*F_f*h_je_t';
J4t(:,l2)=-lamda_jt*exp(log(error)*2)+...
H_ie_t(:,l2)'*h_je_t*F_f*h_je_t'*H_ie_t(:,l2)-chi_jt(l2) ;
A_jt(:,:,l2)=[J1t(:,:,l2),J2t(:,:,l2);J3t(:,:,l2),J4t(:,l2)];
Gamma_ft=trace(Ftx*(H_ie_t(:,l2)*H_ie_t(:,l2)'+exp(log(error)*2)*eye(M)-...
2*error*sqrt(eye(M)*(H_ie_t(:,l2)'*Ftx*H_true_jt(:,l2))/trace(Ftx))));

t2=real((Gamma_wt+Gamma_ft+a0)^(-1));
Pha2_t(:,l2)=real(t2*(chi_bt(l2)+chi_jt(l2)+a0)-log(t2)-1)-log_det(real(chi_bt(l2)+a0));
end

maximize B/log(2)*(nr*(Pha1_r-x1))+...
B/log(2)*(nt*(Pha1_t-x2))
subject to
x1>=0;
x2>=0;
real(trace(W_r+W_t))<=P1_max(ll);
real(trace(F_f))<=Pn;
for  l1=1:L1
Pha2_r(:,l1)<=x1;
A_br(:,:,l1) == hermitian_semidefinite(M+1);
A_jr(:,:,l1) == hermitian_semidefinite(M+1);
end
for  l2=1:L2
Pha2_t(:,l2)<=x2;
A_bt(:,:,l2) == hermitian_semidefinite(M+1);
A_jt(:,:,l2) == hermitian_semidefinite(M+1);
end
cvx_end
``````

My assessment has not changed from my preceding post.

Have yiu tried reinstalling CVX 2.2. in a new MATLAB session?

## 谢谢，我安装了很多次，出现是这样的结果，是安装失败了么 CVX: Software for Disciplined Convex Programming (c)2014 CVX Research Version 3.0beta, Build 1183 (dda2109) Sun Dec 17 18:58:10 2017

Setting CVX paths…done.
Saving update path…done.
Searching for solvers…7 shims found.
2 solvers initialized (* = default):

• SDPT3 4.0 {cvx}\sdpt3
SeDuMi 1.34 {cvx}\sedumi
ECOS
GLPK
SCS
4 solvers require a CVX Professional license:
Gurobi {cvx}\gurobi\w64
Mosek unknown {cvx}\mosek\w64
Mosek_2 unknown D:\software_study\MATLAB\bin\mosek\10.1\toolbox\r2017a
Mosek_3 unknown D:\software_study\MATLAB\bin\10.1\toolbox\r2017a
Saving updated preferences…done.
Testing with a simple model…done!

## WARNING: other CVX installations were found in your MATLAB path: D:\software_study\MATLAB\cvx They have been removed to prevent conflicts.

WARNING: An existing copy of “square.m” was found in your MATLAB path:
D:\software_study\MATLAB\toolbox\signal\signal\square.m
Models using SQUARE() in CVX expressions will not be affected; but outside
of CVX, this version will be used, and it likely has a different meaning.
To avoid any confusion, just use X.^2 instead of SQUARE(X) in CVX.

mosekdiag
Matlab version : 9.11.0.1769968 (R2021b)
Architecture : PCWIN64
mosekopt path : D:\software_study\MATLAB\bin\mosek\10.1\toolbox\r2017a\mosekopt.mexw64
MOSEK version : 10.1.12
Test linear solve: Success
mosekopt works OK. You can use MOSEK in MATLAB.

Remove all CVX directories from your MATLAB path. This is to make sure all remnants of CV 2.beta are removed from you MATLAB installation.

Then install CVX 2.2 in a new MATLAB session. Do NOT use CVX 3.0beta, which is what you installed, and is riddled with bugs. If you look at preceding posts, I’ve been telling you to make sure you are not using CVX 2.beta, and to install CVX 2.2.