# Why can maximize (0) find a solution that satisfies the constraint, but when I write my objective function, it keeps failed

function [W,q] =W_opt(B,Lamda,qr)
Hc=zeros(M,M,K);
Hre1=zeros(M,M,K);
Wr=zeros(M,M,K);

``````for k=1:K
Wr(:,:,k)=W(:,k)*W(:,k)';
end
Tr1=zeros(1,K);
Tr1_1=zeros(1,K);
Tr1_2=zeros(1,K);
Tr2=zeros(1,K);
Tr3=zeros(1,K);
Tr3_1=zeros(1,K);
Tr2_1=zeros(1,K);
for k=1:K
Hc(:,:,k)=h_c(:,k)*h_c(:,k)';% Hkc
Hre1(:,:,k)=h_r(:,(k-1)*M+1:k*M)'*diag(theta1(:,k))'*h_re(:,k)*h_re(:,k)'*diag(theta1(:,k))*h_r(:,(k-1)*M+1:k*M);%Hkre
Tr1_1(1,k)=trace(Hre1(:,:,k)*Wr(:,:,k));%tr(Hre1*Wr)
Tr1(1,k)=log(Tr1_1(1,k))-1;%(1.38)常数项

Tr1_2(1,k)=trace(Hc(:,:,k)*Wr(:,:,k));%tr(Hc*Wr)
for i=1:K
Tr3(1,k)=Tr3(1,k)+pw*trace(Hc(:,:,k)*Wr(:,:,i));%
Tr3_1(1,k)=Tr3_1(1,k)+pw*trace(Hre1(:,:,k)*Wr(:,:,i));%
end
Tr2(1,k)=log(Tr3(1,k)-(1-a(1,k))*pw*Tr1_2(1,k)+noise)-...
(Tr3(1,k)-(1-a(1,k))*pw*Tr1_2(1,k))/(Tr3(1,k)-(1-a(1,k))*pw*Tr1_2(1,k)+noise/P(1,k));
Tr2_1(1,k)=Tr3(1,k)-(1-a(1,k))*pw*Tr1_2(1,k)+noise/P(1,k);%(1.40)分母
end
H2=zeros(1,K);
for k=1:K
H2(1,k)=norm(h_cu(:,k)'+h_re(:,k)'*diag(theta2(:,k))*h_cr(:,k),'fro')^2;%第二阶段级联信道
end
``````

% %(1.49)
% Tr4=zeros(1,K);
% Tr4_1=zeros(1,K);
% Tr4_2=zeros(1,K);
% for k=1:K
% Tr4(1,k)=-log(-(1-a(1,k))pwTr1_1(1,k)noise+(2^Rc-1)(Tr3_1(1,k)-(1-a(1,k))pwTr1_1(1,k)+noise)*noise);%一阶泰勒的常数项
% Tr4_1(1,k)=-(1-a(1,k))pwTr1_1(1,k)noise+(2^Rc-1)(Tr3_1(1,k)-(1-a(1,k))pwTr1_1(1,k)+noise)noise;%一阶泰勒展开的分母
% Tr4_2(1,k)=-(-(1-a(1,k))pwTr1_1(1,k)noise+(2^Rc-1)(Tr3_1(1,k)-(1-a(1,k))pwTr1_1(1,k))noise);%(1.49)一阶泰勒展开分子
% end
%（1.49）
% Tr5=zeros(1,K);
% Tr5_1=zeros(1,K);
% omi=1/(1+exp(150
0.024)); %电路参数l=4,L=24mw,a=150,b=0.024或者0.014
% for k=1:K +2
Lamda(2,2)sqrt(B(2,2))sqrt(a(1,2)pwreal(trace(Hc(:,:,2)X2)))-Lamda(2,2)^2(a(1,2)pwreal(trace(Hc(:,:,2)X2))+pwreal(trace(Hc(:,:,2)X1))+noise+noise1/P(1,2))
% Tr5(1,k)=log((1-omi)xr(1,k)+40.024
omi);
% Tr5_1(1,k)=(1-omi)xr(1,k)+40.024
omi;
% end+2
Lamda(2,1)sqrt(B(2,1))sqrt(a(1,1)pwreal(trace(Hc(:,:,1)X1)))…
% -Lamda(2,1)^2
(a(1,1)pwreal(trace(Hc(:,:,1)X1))+pwreal(trace(Hc(:,:,1)X2))+noise+noise1/P(1,1))
cvx_begin sdp
variable X1(M,M) hermitian semidefinite ;
variable X2(M,M) hermitian semidefinite ;
variable x(1,K) ;%x=[x1,x2,xK]
variable y(1,K) ;%y=[y1,y2,yK]
variable Q(1,K) ;%Q=[q1,q2,qK]%Lamda(1,k)第k个簇的远端用户，Lamda(2,k)第k个簇的近端用户
% qr(1,1)^2+2
qr(1,1)
(Q(1,1)-qr(1,1))+noise
(real(trace(Hre1(:,:,1)*X1))+real(trace(Hre1(:,:,1)*X2))+noise)
% B(1,1))sqrt((a(1,1)pwreal(trace(Hre1(:,:,1)X1))+pwreal(trace(Hre1(:,:,1)X2))+noise)noise
% qr(1,2)^2+2
qr(1,2)
(Q(1,2)-qr(1,2))+noise
(real(trace(Hre1(:,:,2)*X1))+real(trace(Hre1(:,:,2)X2))+noise)
% B(1,2))sqrt((a(1,2)pwreal(trace(Hre1(:,:,2)X2))+pwreal(trace(Hre1(:,:,2)X1))+noise)noise
maximize(2
Lamda(1,1)sqrt(qr(1,1)^2+2qr(1,1)
(Q(1,1)-qr(1,1))+noise
(real(trace(Hre1(:,:,1)X1))+real(trace(Hre1(:,:,1)X2))+noise))…
-Lamda(1,1)^2
(B(1,1))
((a(1,1)pwreal(trace(Hre1(:,:,1)X1))+pwreal(trace(Hre1(:,:,1)X2))+noise)noise)…

+2
Lamda(1,2)sqrt(qr(1,2)^2+2qr(1,2)
(Q(1,2)-qr(1,2))+noise
(real(trace(Hre1(:,:,2)X1))+real(trace(Hre1(:,:,2)X2))+noise))…
-Lamda(1,2)^2
(B(1,2))
((a(1,2)pwreal(trace(Hre1(:,:,2)X2))+pwreal(trace(Hre1(:,:,2)*X1))+noise)*noise)…

)

``````subject to
trace(X1)==1 ;
trace(X2)==1 ;

real(Tr1(1,1))+real(trace(Hre1(:,:,1)*X1))/real(Tr1_1(1,1))-log(pw*real(trace(Hre1(:,:,1)*X2))+a(1,1)*pw*real(trace(Hre1(:,:,1)*X1))+noise)...
-log(real(trace(Hc(:,:,1)*X1)))+real(Tr2(1,1))+...
(pw*real(trace(Hc(:,:,1)*X2))+a(1,1)*pw*real(trace(Hc(:,:,1)*X1)))/real(Tr2_1(1,1))<=0;%(1.40)

a(1,1)*pw*real(trace(Hc(:,:,1)*X1))-(2^Rc-1)*(pw*real(trace(Hc(:,:,1)*X2))+noise/P(1,1))>=0;%(1.41)

y(1,1)-H2(1,1)*(a(1,1)*pw*real(trace(Hre1(:,:,1)*X1))+pw*real(trace(Hre1(:,:,1)*X2))+noise)<=0;%(1.44)
x(1,1)-0.7*(1-P(1,1))*(pw*real(trace(Hc(:,:,1)*X1))+pw*real(trace(Hc(:,:,1)*X2))+noise)<=0;

[x(1,1),Q(1,1);Q(1,1),y(1,1)]>=0;%(1.46)

qr(1,1)^2+2*qr(1,1)*(Q(1,1)-qr(1,1))+(1-a(1,1))*pw*real(trace(Hre1(:,:,1)*X1))*noise-(2^Re-1)*(a(1,1)*pw*real(trace(Hre1(:,:,1)*X1))+...
pw*real(trace(Hre1(:,:,1)*X2))+noise)*noise>=0;%(1.48)
``````

% 150/4*((1-P(1,1))(pwreal(trace(Hc(:,:,1)X1))+pwreal(trace(Hc(:,:,1)X2))+noise)-0.024)+log(40.024-(1-omi)x(1,1)-40.024omi)…
% -Tr5(1,1)-(1-omi)
(x(1,1)-xr(1,1))/Tr5_1(1,1)>=0;%(1.49)

``````%第二个簇
real(Tr1(1,2))+real(trace(Hre1(:,:,2)*X2))/real(Tr1_1(1,2))-log(pw*(real(trace(Hre1(:,:,2)*X1))+a(1,2)*real(trace(Hre1(:,:,2)*X2)))+noise)...
-log(real(trace(Hc(:,:,2)*X2)))+real(Tr2(1,2))+...
pw*(real(trace(Hc(:,:,2)*X1))+a(1,2)*real(trace(Hc(:,:,2)*X2)))/real(Tr2_1(1,2))<=0;%(1.40)
``````

a(1,2)pwreal(trace(Hc(:,:,2)X2))-(2^Rc-1)(pw*real(trace(Hc(:,:,2)*X1))+noise/P(1,2))>=0;%(1.41)

``````y(1,2)-H2(1,2)*(a(1,2)*pw*real(trace(Hre1(:,:,2)*X2))+pw*real(trace(Hre1(:,:,2)*X1))+noise)<=0;%(1.44)
x(1,2)-0.7*(1-P(1,2))*(pw*real(trace(Hc(:,:,2)*X1))+pw*real(trace(Hc(:,:,2)*X2))+noise)<=0;

[x(1,2),Q(1,2);Q(1,2),y(1,2)]>=0;%(1.46)

qr(1,2)^2+2*qr(1,2)*(Q(1,2)-qr(1,2))+(1-a(1,2))*pw*real(trace(Hre1(:,:,2)*X2))*noise-(2^Re-1)*(a(1,2)*pw*real(trace(Hre1(:,:,2)*X2))+...
pw*real(trace(Hre1(:,:,2)*X1))+noise)*noise>=0;%(1.48)
``````

% 150/4*((1-P(1,2))(pwreal(trace(Hc(:,:,2)X1))+pwreal(trace(Hc(:,:,2)X2))-noise)-0.024)+log(40.024-(1-omi)x(1,2)-40.024omi)…
% -Tr5(1,2)-(1-omi)
(x(1,2)-xr(1,2))/Tr5_1(1,2)>=0;%(1.49)

``````X1==semidefinite(M);
X2==semidefinite(M);

cvx_end
cvx_optval
``````

Please show the solver and CVX output for the failed case. Without seeing the solver output, i don’t know whether the solver encountered numerical difficulties, or assessed the problem to be unbounded or infeasible.

All but section 1 of Debugging infeasible models - YALMIP also applies to CVX. For unbounded, see Debugging unbounded models - YALMIP .

If the problem has bad numerical scaling (non-zero input data not within s small number of orders of magnitude of one), that could lead to any of the failure modes I listed, and should be fixed before proceeding further. Bad numerical scaling in the objective function can couple into erroneous feasibility decisions, which is one way a feasible solution might be found when the objective is zero, but be declared infeasible when there is a non-constant objective function.