“The second argument must be positive or negative semidefinite”

I have no idea why the error happened? Here’s the error.

Here’s my input data.

%% Parameters Initialization %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ‘1’ stands for source-relays; ‘2’ stands for relays-destination
N = 6; % array number of BS 缁村害蹇呴』涓?5锛屽洜涓?5鏉℃洸绾?
Nr = 5;
M = 10; % array number of STAR-RIS 10-50
M1=M/2;
Kr = 4; % number of users
Kt = 3;
K = Kt+Kr;
SNR_dB = 10; % dBW
cof_L = 0.5.ones(K,1); %coefficient of loop interference
cof_S = 0.5.ones(K-1,1); %coefficient of self interference
cof =[cof_S;1];%select coeffient 2
1dimension
%%%%% noise
N0=10^((-174-30) / 10); %-174dBm
B=10^7; %10MHz
down_maxpower_all=20;
up_maxpower_all = 20;
% noise_maxpower_original = N0
B; % % W
noise_maxpower_original = 10^((-80-30) / 10);%-80dBm
power_max_dBm=10;
%% Simulation loop %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num_loop =100;
num_iterative = 10;
load(‘H_UI_ALL’);
load(‘H_IU_ALL’);%鍒濆鍖栦俊閬?
load(‘H_IE_ALL’);
load(‘H_IB_ALL’);
load(‘H_BI_ALL’);
load(‘H_BB_ALL’);
load(‘H_UU_ALL’);

load(‘H_UIr_ALL.mat’);
load(‘H_UIt_ALL.mat’);
load(‘H_IUr_ALL.mat’);
load(‘H_IUt_ALL.mat’);
load(‘H_UUr_ALL.mat’);
load(‘H_UUt_ALL.mat’);
%Rate=zeros(K,length(rate_min_dB),100);%鍒濆鍖栭?熺巼鐭╅樀鐢ㄤ簬淇濆瓨鍙傛暟銆?
SumRate1=zeros(num_loop,num_iterative,length(down_maxpower_all));

for loop = 1 : num_loop %浠?1寮?濮嬪惊鐜?
outerflag=1;
T1=cputime;
noise_maxpower=1;%鍣0鍔熺巼褰掍竴鍖?
%%% For different 鑷彉閲? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf(’ loop | N | iteration \n’);
for i_p = 1 : length(down_maxpower_all)%涓嶅悓N,M鎴栦笉鍚屽彂灏勫姛鐜?
t0=cputime;
down_maxpower=down_maxpower_all;
up_maxpower=up_maxpower_all;

%%%%%  Initialize Fi for different mode(ES,MS and TS )  %%%%%%%%%%%%%%%
H_IB=H_IB_ALL(1:Nr,1:M,loop)/sqrt(noise_maxpower_original);%淇¢亾褰掍竴鍖?

H_BI=H_BI_ALL(1:M,1:N,loop)/sqrt(noise_maxpower_original);

H_IU=H_IU_ALL(1:M,1:K,loop)/sqrt(noise_maxpower_original);

H_IUr=H_IUr_ALL(1:M,1:Kr,loop)/sqrt(noise_maxpower_original);
H_IUt=H_IU_ALL(1:M,1:Kt,loop)/sqrt(noise_maxpower_original);

H_UI=H_UI_ALL(1:K,1:M,loop)/sqrt(noise_maxpower_original);

H_UIr=H_UIr_ALL(1:Kr,1:M,loop)/sqrt(noise_maxpower_original);
H_UIt=H_UIt_ALL(1:Kt,1:M,loop)/sqrt(noise_maxpower_original);

H_IE=H_IE_ALL(1:M,1:2,loop)/sqrt(noise_maxpower_original);

H_BB=H_BB_ALL(1:N,1:Nr,loop)/sqrt(noise_maxpower_original);

H_UU=H_UU_ALL(1,1:K,loop)/sqrt(noise_maxpower_original);

H_UUr=H_UUr_ALL(1,1:Kr,loop)/sqrt(noise_maxpower_original);

H_UUt=H_UUt_ALL(1,1:Kt,loop)/sqrt(noise_maxpower_original);

%clear Phi_1 Phi_2 Phi_i3 Phi_4 Phi_6 W_1 W_3
%%%%%  Initialize Fi for different mode(ES,MS and TS )  %%%%%%%%%%%%%%%
%%%%%  ES妯″紡鍙傛暟鍒濆鍖?  %%%%%%%%%%%%%%%
Phi_temp=randn(2,M) + sqrt(-1)*randn(2,M);
Phi_tamp=rand(1,M);
Phi_ramp=1-Phi_tamp;
Angle=rad2deg(angle(Phi_temp));
Angle(Angle<0)=Angle(Angle<0)+360;
Ang=deg2rad(Angle);
Phi_amp=[sqrt(Phi_tamp) ;sqrt(Phi_ramp)];%骞呭害鍒濆鍖?
Phi_ini_ES=Phi_amp.*exp(1j*Ang);%/sqrt(trans_maxpower/(M*K));%骞呭害鍒濆鍖栵紝鍧囧寑鍒嗗竷
Phi_ini_eES=sqrt(0.5).*exp(1j*Ang);%骞呭害鍚勪负0.5,_equal_ES.
Phi1(:,:,1)=full(Phi_ini_ES);%ESmode涓嬬殑Fi杩唬鍊?
%Phi4(:,:,1)=full(Phi_ini_eES);%equalESmode涓婩i鐨勮凯浠e??
%%%%%  MS妯″紡鍙傛暟鍒濆鍖?  %%%%%%%%%%%%%%%
Phi_Mtemp=randn(2,M1) + sqrt(-1)*randn(2,M1);
 Phi_Mtamp=rand(1,M1);
 Phi_Mramp=1-Phi_Mtamp;
 Phi_Mamp=[sqrt(Phi_Mtamp) ;sqrt(Phi_Mramp)];
Angle2=rad2deg(angle(Phi_Mtemp));
Angle2(Angle2<0)=Angle2(Angle2<0)+360;
Ang2=deg2rad(Angle2);
Phi_ini_MS=Phi_Mamp.*exp(1j*Ang2);
Phi2(:,:,1)=full(Phi_ini_MS);
%%%%%  TS妯″紡鍙傛暟鍒濆鍖?  %%%%%%%%%%%%%%%
Phi_ini_TS=exp(1j*Ang);
Phi3(:,:,1)=full(Phi_ini_TS);
%%%%%  conventional RIS鍙傛暟鍒濆鍖?  %%%%%%%%%%%%%%%
%Phi_ini_cRIS=exp(1j*angle(Phi_Mtemp));
%Phi6(:,:,1)=full(Phi_ini_cRIS);

%%%%%  Initialize W   %%%%%%%%%%%%%%%
W_ini=randn(N,K)*sqrt(down_maxpower/(N*K));
W1(:,:,1)=full(W_ini);
W3(:,:,1)=full(W_ini);
%%%%%  Initialize F   %%%%%%%%%%%%%%%
F_ini=randn(K,Nr)*sqrt(up_maxpower/(K*Nr))+1i*randn(K,Nr)*sqrt(up_maxpower/(K*Nr));
F1(:,:,1)=full(F_ini);
F3(:,:,1)=full(F_ini);
%%%%%  Initialize a   %%%%%%%%%%%%%%%
a_ini=randn(1,K)*sqrt(down_maxpower/(1*K));
a(:,1)=full(a_ini);
%%%%%  Initialize uplink MMSE variable   %%%%%%%%%%%%%%%    
u_up(:,1)=ones(1,K);
%%%%%  Initialize downlink MMSE variable   %%%%%%%%%%%%%%%    
u_dwn(:,1)=ones(1,K); 

And this is my code.
function [W_opt,flag] = Generate_ESMS_trans_beamforming(cof,cof_L, N,Nr, M, K,Kr,Kt, H_IB, …
H_BI,H_BB,H_UU,H_IU, H_UI,H_IE,H_UIr,H_UIt,H_IUr,H_IUt,H_UUr,H_UUt, …
W_ini, F_ini, Phi_ini,u_up_ini,u_dwn_ini, …
noise_maxpower, down_maxpower,up_maxpower)

cvx_begin %quiet
%cvx_solver mosek
variable  W(N,K) complex

%expressions  ;

for k=1:1:K
   for kr=1:1:Kr
      for kt=1:1:Kt
          %%%%%up MMSE %%%%%%
          up_users_t(kt,:)=diag(H_UI(kt,:))*Phi_ini(1,:)';
          up_users_r(kr,:)=diag(H_UI(Kt+kr,:))*Phi_ini(2,:)';
          
          %%%%%%down MMSE%%%%%%%
          dwn_users_t(kt,:)=Phi_ini(1,:)*diag(H_IU(:,kt))*H_BI(:,:);
          dwn_users_r(kr,:)=Phi_ini(2,:)*diag(H_IU(:,Kt+kr))*H_BI(:,:);

          up_SI_t(kt)=Phi_ini(1,:)*diag(H_IU(:,kt))*H_UI(kt,:)';%co-channel interference of MMSE
          up_SI_r(kr)=Phi_ini(2,:)*diag(H_IU(:,Kt+kr))*H_UI(Kt+kr,:)';
      end
   end
       if(k<=Kt)
           Phi_init(k,:)=Phi_ini(1,:);
           H_eve(:,k)=H_IE(:,1);
          
           P=Kt;
           I=0;
       elseif((k>Kt)&&(k<=K))
           Phi_init(k,:)=Phi_ini(2,:);
           H_eve(:,k)=H_IE(:,2);
           
           P=Kr;
           I=Kt;
       end
                %%%%%%%%generate downlink MMSE expression%%%%%%%%%%%
                dwn_all_users=sum(dwn_users_t)+sum(dwn_users_r);%K*N dims

                dwnlk_ch(k,:)=u_dwn_ini(k)*dwn_all_users;%downlink term of downlink MMSE
                dwnlk_poly(:,:)=dwnlk_ch(k,:)'*dwnlk_ch(k,:);
                %dwnlk(k)=sum(W(:,L)'*dwnlk_poly(k)*W(:,L));
                dwnlk_ini(k)=sum(W_ini,2)'*dwnlk_poly(:,:)*sum(W_ini,2);

                real_ch(k,:)=u_dwn_ini(k)*Phi_init(k,:)*diag(H_IU(:,k))*H_BI(:,:);
                %dwn_real_part(k)=2*real(real_ch(k,:)*W(:,k));
                dwn_real_part_ini(k)=2*real(real_ch(k,:)*W_ini(:,k));
                            %%%%constant in downlink MMSE %%%%%%%%
                LI_ch(k)=noise_maxpower+cof_L(k)*up_maxpower*H_UU(k)*H_UU(k)';
                LI(k)=LI_ch(k)*u_dwn_ini(k)*u_dwn_ini(k)';%loop interference
                
                up_SI_sum=sum(up_SI_t)+sum(up_SI_r);

                dwnSI_ch(k)=u_dwn_ini(k)'*up_SI_sum;%co-channel interference of MMSE, constance with respect to W
                dwnSI_poly(k)=cof(k)*up_maxpower*sum(dwnSI_ch(k)*dwnSI_ch(k)');
                dwnSI_ini(k)=sum(W_ini,2)'*dwnSI_poly(k)*sum(W_ini,2);
                %dwnSI(k)=u_dwn_ini(k)'*dwnSI_poly(k)*u_dwn_ini(k);
                           %%%%function in downlink MMSE %%%%%%%%
                %dwn_e(k)=dwnlk(k)+dwn_real_part(k)+real(LI(k)+dwnSI(k))+1;%error:complex+complex constant
                %dwn_cons(k)=real(LI(k)+dwnSI(k))+1;
                dwn_aux_var(k)=1/(dwnlk_ini(k)-dwn_real_part_ini(k)+LI(k)+dwnSI_ini(k)+1);
                
                dwn_quad_matrix(:,:)=dwnlk_poly(:,:);
                dwnlk(:,:)=dwn_aux_var(k).*dwn_quad_matrix(:,:);

                dwn_real(k,:)=-dwn_aux_var(k)*real_ch(k,:);
                %dwn_r(k)=log(abs(dwn_aux_var(k)))-real(dwn_aux_var(k))*dwn_e(k)+1;%error:complex*complex constant

                %%%%%%%%%%end%%%%%%%%%%%%%%%%%%%%%
                
                %%%%%%%%%generate uplink MMSE expression%%%%%%%%%%%%%
                up_all_users=sum((up_users_r),1)+sum((up_users_t),1);

                upLI_ch(:,k)=u_up_ini(k)*H_BB(:,:)*F_ini(k,:)';
                upLI_poly(:,:)=upLI_ch(:,k)*upLI_ch(:,k)';
                %upLI(k)=sum(W(:,L)'*upLI_poly(k)*W(:,L));
                upLI_ini(k)=sum(W_ini,2)'*upLI_poly(:,:)*sum(W_ini,2);

                upSI_ch(:,k)=u_up_ini(k)*H_BI(:,:)'*H_IB(:,:)'*F_ini(k,:)';
                upSI_poly(:,:)=upSI_ch(:,k)*upSI_ch(:,k)';
                %upSI(k)=sum(W(:,L)'*upSI_poly(k)*W(:,L));
                upSI_ini(k)=sum(W_ini,2)'*upSI_poly(:,:)*sum(W_ini,2);
             
                        %%%%constant in uplink MMSE %%%%%%%%
                upBS_ch(k,:)=u_up_ini(k)*up_all_users;%%%BS recieved users signal
                upBS_poly(k)=up_maxpower*upBS_ch(k,:)*upBS_ch(k,:)';

                up_real_part(k)=sqrt(up_maxpower)*u_up_ini(k)*F_ini(k,:)*H_IB(:,:)*diag(H_UI(k,:))*Phi_init(k,:)';
                up_real(k)= 2*real(up_real_part(k));

                nis(k)=noise_maxpower*u_up_ini(k)*u_up_ini(k)*F_ini(k,:)*F_ini(k,:)';

                         %%%%function in downlink MMSE %%%%%%%%
                up_quad_matrix(:,:)=upLI_poly(:,:)+upSI_poly(:,:);
                %x(k)=(upLI_ini(k)+upSI_ini(k)+up_real(k)+upBS_poly(k)+nis(k));

                up_aux_var(k)=1/(upLI_ini(k)+upSI_ini(k)-up_real(k)+upBS_poly(k)+nis(k));

                uplk(:,:)=up_aux_var(k).*up_quad_matrix(:,:);


                %up_r(k)=log(abs(up_aux_var(k)))-real(up_aux_var(k))*up_e(k)+1;%error:invalid-convex. solve:delete constant
                %updwn_cons(k)=log(abs(dwn_aux_var(k)))+log(abs(up_aux_var(k)))+2;
                
                
                %%%%%%%%%end%%%%%%%%%%%%%%%%%%%%%


                %%%%%%%%%%generate quadrtic transform of dwn eve %%%%%%%%%%%%% 
                for p=1:1:P
                      
                        W_init=W_ini;
                        W_init(:,k)=[];
                        W_selt=W;
                        W_selt(:,k)=[];
                        H_selt=H_UI;
                        H_selt(k,:)=[];

                dwn_evenum_ch(k,:)=Phi_init(k,:)*diag(H_eve(:,k))*H_BI(:,:);%nomonator of up eve rate
                dwn_evenum_poly(:,:)=dwn_evenum_ch(k,:)*dwn_evenum_ch(k,:)';

                dwn_evenum_ini(p+I)= W_ini(:,p+I)'*dwn_evenum_poly(:,:)*W_ini(:,p+I);
                %eve(k)=sum(W(:,L)'*eve_poly(k)*W(:,L));
  
                        dwn_evedom1_ini(k)= sum(W_init,2)'*dwn_evenum_poly(:,:)*sum(W_init,2);
                                                   
                        dwn_evedom2_ch=sum(Phi_init(k,:)*diag(H_eve(:,k))*H_UI(k,:)');
                        dwn_evedom2_ini=up_maxpower*dwn_evedom2_ch*dwn_evedom2_ch;

                        dwn_evedom_ini(k)=dwn_evedom1_ini(k)+dwn_evedom2_ini+noise_maxpower;

                        coef_dwneve(k)=dwn_evedom_ini(k)/(dwn_evedom_ini(k)+dwn_evenum_ini(p+I));

                        y_dwneve(k)=-sqrt(dwn_evenum_ini(p+I))/dwn_evedom_ini(k);

                     dwneve_matrix(:,:)=((1/3)*y_dwneve(k)*y_dwneve(k)*coef_dwneve(k)).*dwn_evenum_poly(:,:);

                     dwneve_real(k,:)=((1/3)*y_dwneve(k)*coef_dwneve(k)).*dwn_evenum_ch(k,:);
                %%%%%%%%%end%%%%%%%%%%%%

                %%%%%%%generate quadrtic transform of up eve%%%%%%%%%%%%%
                up_evenum_ch(k)=Phi_init(k,:)*diag(H_eve(:,k))*H_UI(k,:)';
                
                up_evenum_poly(k)=up_maxpower*up_evenum_ch(k)*up_evenum_ch(k);

                up_evedom1_ch(k,:)=Phi_init(k,:)*diag(H_eve(:,k))*H_BI(:,:);
                up_evedom1_poly(:,:)=up_evedom1_ch(k,:)'*up_evedom1_ch(k,:);
                up_evedom1_ini(k)=sum(W_ini,2)'*up_evedom1_poly(:,:)*sum(W_ini,2);

                up_evedom2_ch(k)=Phi_init(k,:)*diag(H_eve(:,k))*sum(H_selt,1)';
                up_evedom2_poly(k)=up_maxpower*up_evedom2_ch(k)*up_evedom2_ch(k);

                up_evedom_ini(k)=up_evedom1_ini(k)+up_evedom2_poly(k)+noise_maxpower;

                coef_upeve(k)=up_evedom_ini(k)/(up_evenum_poly(k)+up_evedom_ini(k));
                y_upeve(k)=-sqrt(up_evenum_poly(k))/up_evedom_ini(k);
                
                upeve_matrix(:,:)=((1/3)*y_upeve(k)*y_upeve(k)*coef_upeve(k)).*up_evedom1_poly(:,:);

                
                %%%%%%%%%%end%%%%%%%%%%%%%
                W_init=W_ini;
                W_selt=W;
                H_selt=H_UI;      
                end
                
                final_matrix(:,:)=dwnlk(:,:)+uplk(:,:);
                A_matrix(:,:)=0.5.*(final_matrix(:,:)+final_matrix(:,:)')
                B_matrix(:,:)=0.5.*(dwneve_matrix(:,:)+dwneve_matrix(:,:)');
                C_matrix(:,:)=0.5.*(upeve_matrix(:,:)+upeve_matrix(:,:)');
                B_real(k,:)=dwn_real(k,:)+dwneve_real(k,:);
                D_matrix(:,:)=A_matrix(:,:)+B_matrix(:,:)+C_matrix(:,:)
                %%%%%final objective function%%%%
                poly1(k)=W(:,k)'*A_matrix(:,:)*W(:,k);%%%%噪声功率太小就会导致
                poly2(k)=sum(W_selt,2)'*B_matrix(:,:)*sum(W_selt,2);
                poly3(k)=sum(W,2)'*C_matrix(:,:)*sum(W,2);
                %poly_all(k)=(poly1(k)+poly2(k)+poly3(k))%如何把这三个多项式写成一个
                poly(k)=-poly1(k)-2*real(B_real(k,:)*W(:,k));%%%窃听用户的负号记得加上

end

maximize sum(poly)

subject to

    pow_pos(norm(W,'fro'),2)<=down_maxpower;

cvx_end

if cvx_status(1)==‘S’ || cvx_status(3)==‘a’
flag=1;
W_opt=W;
else
flag=0;
W_opt=ones(N,K);
end
end

But when I let the input parameter noise_maxpower_original up to 10^((-40-30) / 10). It can magically solved. Please help me to figure it out. Gratefully thanks.

Maybe bad numerical scaling (input numbers too extreme) causing something to be not be numerically evaluated with the semidefiniteness it would have had the calculations been made in infinite precision.