# 输入矩阵必须为双精度矩阵或逻辑矩阵。

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

L1 =2;
L2 =2;

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

pa_max=-15:5:30;%dbm
pj_max=15;
PA_max=10.^(pa_max./10)/1000;%W
PJ_max=10.^(pj_max./10)/1000;

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

tolerance=0.1;%信道误差容忍度
nr=0.5;%%%%%权重因子
nt=0.5;
%贝塔的初值设置1
step=0.5;

% Simulation loop %%%%%%%%%%%%%%%%
num_loop=1;
finnal_RR=zeros(num_loop,length(PA_max));
finnal_R=zeros(1,length(PA_max));
for loop=1:num_loop

``````h_b=H_b_ALL(1:M,1:N,loop);
h_j=H_j_ALL(1:M,1:N,loop);
h_iu_r=H_IU_ALL_r(1:M,1:1,loop);
h_iu_t=H_IU_ALL_r(1:M,1:1,loop);

h_ie_r=H_IE_ALL_r(1:M,1:L1,loop);
h_ie_t=H_IE_ALL_t(1:M,1:L2,loop);
a0=P_noise;
for  ll = 1:length(pa_max)
wr=ones(N,1)*sqrt(PA_max(ll)/(2*N));
wt=ones(N,1)*sqrt(PA_max(ll)/(2*N));
f=ones(J,1)*sqrt(PJ_max/J);
Wr=wr*wr';
Wt=wt*wt';
Ff=f*f';
alpha_r_vec=sqrt(1/2)*ones(M,1);
theta_r_vec=2*pi*randn(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);
Vr=vr*vr';
Vt=vt*vt';
hiu_r=h_iu_r'*(vr*vr')*h_b;
hiu_t=h_iu_t'*(vt*vt')*h_b;
giu_r=h_iu_r'*(vr*vr')*h_j;
giu_t=h_iu_t'*(vt*vt')*h_j;
Hab_r=h_iu_r'*(Vr)*h_b;
Hab_t=h_iu_t'*(Vt)*h_b;
Gab_r=h_iu_r'*(Vr)*h_j;
Gab_t=h_iu_t'*(Vt)*h_j;

max=1+a0^(-2)*PA_max(ll)*norm(Hab_r)^2;
R0=0;
kk=0;
for b=1:step:3
b
Hab_r=h_iu_r'*(Vr)*h_b;
Hab_t=h_iu_t'*(Vt)*h_b;
Gab_r=h_iu_r'*(Vr)*h_j;
Gab_t=h_iu_t'*(Vt)*h_j;
cvx_solver Mosek
cvx_save_prefs
%%%优化发射波束%%%%
cvx_begin quiet
variable Q_r(N,N)    hermitian  semidefinite
variable Q_t(N,N)  hermitian  semidefinite
variable Z_j(J,J)  hermitian  semidefinite
variable x1(L1)
variable x2(L2)
variable e
expressions   Lr Lt Ir Tt  ...
Ar At Br Bt Cr Ct Dr Dt...
AAr(M+1,M+1,L1)  AAt(M+1,M+1,L2)
Lr=Vr*h_b*((b-1)*Q_t-Q_r)*h_b'*Vr'  ;    Lt= Vt*h_b*((b-1)*Q_r-Q_t)*h_b'*Vt';
Ir=Vr*h_j*((b-1)*Z_j)*h_j'*Vr'      ;    It=Vt*h_j*((b-1)*Z_j)*h_j'*Vt' ;
``````

% for l1=1:L1
% Ar(1,l1)=h_ie_r(:,l1)'*(Lr+Ir)h_ie_r(:,l1)+(b-1)a0e-x1(l1) ;
% Br(1,1:M,l1)=h_ie_r(:,l1)'
(Lr+Ir);
% Cr(1:M,1,l1)=(Lr+Ir)*h_ie_r(:,l1);
% Dr(1:M,1:M,l1)=(Lr+Ir)+(x1(l1)./a0)eye(M,M);
% AAr(1:M+1,1:M+1,l1)=[Ar(1,l1),Br(1,1:M,l1);Cr(1:M,1,l1),Dr(1:M,1:M,l1)];
% end
% for l2=1:L2
% At(1,l2)=h_ie_t(:,l2)'
(Lt+It)h_ie_t(:,l2)+(b-1)a0e-x2(l2) ;
% Bt(1,1:M,l2)=h_ie_t(:,l2)'
(Lt+It);
% Ct(1:M,1,l2)=(Lt+It)*h_ie_t(:,l2);
% Dt(1:M,1:M,l2)=(Lt+It)+(x2(l2)./a0)*eye(M,M);
% AAt(1:M+1,1:M+1,l2)=[At(1,l2),Bt(1,1:M,l2);Ct(1:M,1,l2),Dt(1:M,1:M,l2)];
% end

``````        Rw_ur=real(a0+Hab_r*(Q_t+Q_r)*Hab_r'+ Gab_r*Z_j*Gab_r');
Rw_ut=real(a0+Hab_t*(Q_r+Q_t)*Hab_t'+ Gab_t*Z_j*Gab_t');
for l1=1:L1
Hae_r=h_ie_r(:,l1)'*Vr*h_b;
Gae_r=h_ie_r(:,l1)'*Vr*h_j;
Rw_er=e*a0+Hae_r*(Q_t+Q_r)*Hae_r'+ Gae_r*Z_j*Gae_r';
end
for l2=1:L2
Hae_t=h_ie_t(:,l2)'*Vt*h_b;
Gae_t=h_ie_t(:,l2)'*Vt*h_j;
Rw_et=e*a0+Hae_t*(Q_r+Q_t)*Hae_t'+ Gae_t*Z_j*Gae_t';
end
maximize nr*Rw_ur+nt*Rw_ut
subject to
e*a0+Hab_r*(Q_t)*Hab_r'+ Gab_r*Z_j*Gab_r' == b^(-1);
e*a0+Hab_t*(Q_r)*Hab_t'+ Gab_t*Z_j*Gab_t' == b^(-1);
``````

% real(trace(Q_r+Q_t))<=ePA_max(ll);
% real(trace(Z_j))<=e
PJ_max;
% for l1=1:L1
% x1(l1)>=0;
% AAr(1:M+1,1:M+1,l1) == hermitian_semidefinite(M+1);
% end
% for l2=1:L2
% x2(l2)>=0;
% AAt(1:M+1,1:M+1,l2)== hermitian_semidefinite(M+1);
% end
% e>0;
cvx end

%%%%%%%%%%%%%%%报错

Perhaps you xan tell us exactly where the error occurs. If it occurs at a statement, look at the types, values, and dimensions of all items involved in the statement.

v = class( struct( ‘size_’, size( s ), ‘basis_’, sparse( s(:).’ ), ‘dual_’, ‘’, ‘dof_’, [], ‘slow_’, nnz( isinf( s ) | isnan( s ) ) ~= 0 ), ‘cvx’, cvxobj );

cvx end

Are you using CVX 2.2? Do not use CVX 3.0beta.

If you are using CVX 2.2, try a new MATLAB session, try a different solver, try reinstalling CVX.