Failed Status and optimal value NAN?

When I run my code, cvx showed the status is failed (other cvx is solved),but i can got the result when the whole code ended
my code is as following :
clc
clear all

M = 4 ; %number of element RIS
K = 1:M;

theta_r_0 = diag(K); %constant first phase
theta_t_0 = diag(K);

NR = 4; % recive antenna
NT = 4; % transmit antenna

ro1 = 2;
ro2 = 2;
N = 4;
w = 10 ;
Pe_vdb = 0:2:8; %dB
Pe_v = 10.^(Pe_vdb./10); %watt
Ne = 1;
Nd = 1;
Ps = 10.^(20./10);

itration = 6;

theta_r_h_0 = diag(theta_r_0)‘;
theta_t_h_0 = diag(theta_t_0)’;
%
theta_r_bar_0 = [theta_r_h_0 1];
theta_t_bar_0 = [theta_t_h_0 1];

Qr_0= (theta_r_bar_0)'(theta_r_bar_0)
Qt_0 = (theta_t_bar_0)'
(theta_t_bar_0)

norm_2_Qt_0 = norm(Qt_0);
norm_2_Qr_0 = norm(Qr_0);

normnuc_Qt = norm_nuc(Qt_0);
normnuc_Qr = norm_nuc(Qr_0);

Ex = zeros(1,length(Pe_vdb));
maxro_t = 1.0000e-06;
maxro_r = 1.0000e-06;

for ii = 1:length(Pe_vdb)

ii
Q_E = Pe_v(ii);
c  = 0;    
j  = 0; 


for i = 1:itration;
    a  = theta_r_0;
b  = theta_t_0;
         
  h_RD=(1/sqrt(2))*(randn(1,M)+sqrt(-1)*randn(1,M));

  h_SR=(1/sqrt(2))*(randn(M,1)+sqrt(-1)*randn(M,1));

  h_SD=(1/sqrt(2))*(randn(1,1)+sqrt(-1)*randn(1,1));

  H_ER=(1/sqrt(2))*(randn(M,NT)+sqrt(-1)*randn(M,NT));

  H_RE=(sqrt(.1)/sqrt(2))*(randn(NR,M)+sqrt(-1)*randn(NR,M));

  H_EE=(1/sqrt(2))*(randn(NR,NT)+sqrt(-1)*randn(NR,NT));

while maxro_t> 1.0000e-07 && maxro_r> 1.0000e-07;

     for n = 1:N ;
       u = H_EE + H_RE*a*H_ER ;  

y_max = 1 + (Q_E/Nd)( ( norm( h_RDb*H_ER) ).^2 );

for z = 1:5;
y = 1 + (y_max./5).*(z-1);

   %............. Optimization Problem ..............
      
      cvx_begin  sdp quiet
      variable Z(NT,NT) hermitian;
      variable s;
      variable f_y;
         
      dual variables p1 p2 p3 p4 p5 

      minimize f_y; 
      
      subject to
      
      p1: s == hermitian_semidefinite(1);
      p2: trace(Z) == s;
      p3: s + (Q_E/Ne)*trace(Z*( u'  )*(  u ) ) == 1
      p4: (Q_E/Ne)*trace(Z*H_ER'*b'*h_RD'*h_RD*b*H_ER) == s .* (y-1)
      p5: Z == hermitian_semidefinite(NT)
          f_y -  (Q_E/Ne)*trace(Z*(u'*H_RE*b*h_SR*h_SR'*b'*H_RE'*u))== hermitian_semidefinite(1)
      cvx_end

 if( strcmp( cvx_status, 'Infeasible' ) == 1 );
         
         Exy(z) = 0;
     else
         Exy(z) = f_y + ( ((Ne/Nd).*(abs(h_SD + h_RD*a*h_SR)^2))./y) ; 
     end       

end

E_xy = nonzeros(Exy);
[l,e] = min(E_xy) ;

       if mean(Exy) ~= 0
           
           j = find(Exy==l);
       end
       
      y = 1 + (y_max-1)/5*(j-1);

cvx_begin sdp quiet
variable Z(NT,NT) hermitian;
variable s;
variable v;

      dual variables p1 p2 p3 p4 p5 

      minimize v ; 
      
      subject to
      
      p1: s == hermitian_semidefinite(1);
      p2: trace(Z) == s;
      p3: s + (Q_E/Ne)*trace(Z*( u'  )*(  u ) ) == 1
      p4: (Q_E/Ne)*trace(Z*H_ER'*b'*h_RD'*h_RD*b*H_ER) == s .* (y-1)
      p5: Z == hermitian_semidefinite(NT)
          v -  (Q_E/Ne)*trace(Z*(u'*H_RE*b*h_SR*h_SR'*b'*H_RE'*u))== hermitian_semidefinite(1)
      cvx_end
      %% .......................... W and w_t .............................
     if length(cvx_status)==6 && sum(cvx_status == 'Solved')==6;
         W     = Z/s ;
         h_t   = real(cvx_optval);
         [V D] = eigs(W);
         d     = real(diag(D));
         [d I] = sort(d,'descend');
         w_opt = V(:,I(1));
         W_opt = W;
     else
         w_opt = zeros(NT,1);
         W_opt = zeros(NT);
         h_t   = 0;
     end
       
      
     
     
     A = Q_E*( H_EE*w_opt + H_RE*a*H_ER*w_opt )*( (H_EE*w_opt + H_RE*a*H_ER*w_opt)')+Ne;
       
     Wr = inv(A)*H_RE*b*h_SR/norm(inv(A)*H_RE*b*h_SR);
       

      ak1 = ( diag(h_RD) )*h_SR;
      ak1_bar = [ak1',h_SD']' ;
      Ak1 = ak1_bar*(ak1_bar');

      
      ak2 = ( diag(h_RD) )*H_ER*w_opt ;
      ak2_bar = [ak2',0]';
      Ak2 =  ak2_bar*(ak2_bar') ;


      ak3 = ( diag(Wr'*H_RE) )*h_SR;
      ak3_bar = [ak3',0]';
      Ak3 = ak3_bar*(ak3_bar');

      
      ak4 = ( diag(Wr'*H_RE) )*H_ER*w_opt;
      g = Wr'*H_EE*w_opt;
      ak4_bar = [ak4',g]';
      Ak4 = ak4_bar*(ak4_bar');  
         
         
         
      %............. Optimization Problem ..............            

           cvx_begin sdp;

           variables x y T ;
           variable Qt(M+1,M+1) ; 
           variable Qr(M+1,M+1) ;     
           expression  Qt_bar_n;
           expression  Qr_bar_n;
           expression t2;
           expression t6;


           [Utt Rtt] = eigs(Qt_0,1,'LM');
           Ut = abs(Utt)

          [Urr Rrr] = eigs(Qr_0,1,'LM');
          Ur = abs(Urr)


          Qt_bar_n = norm_2_Qt_0+trace(Utt*Utt'*(Qt-Qt_0));

          Qr_bar_n = norm_2_Qr_0+trace( Urr*Urr'*(Qr-Qr_0));

% t1= square( trace(Ak3Qt)-trace(Ak2Qt) );
t2 = real( (-2).*( trace(Ak3.*Qt_0)+trace(Ak2.Qt_0) )( trace(Ak3.*Qt)+trace(Ak2.*Qt) ) ) ;
t3 = real((trace(Ak3.*Qt_0)+trace(Ak2.*Qt_0)).^2) ;

          t6 = real((-2).*( trace(Ak4.*Qr_0)-trace(Ak1.*Qr_0) )*( trace(Ak4.*Qr)-trace(Ak1.*Qr) ));
          t7 = real(( trace(Ak4*Qr_0)-trace(Ak1*Qr_0) ).^2);
          
          
          T == [x y];

          minimize ( prod_inv(T)+ro1*( norm_nuc(Qt)- Qt_bar_n )+ro2*( norm_nuc(Qr)-Qr_bar_n) );

          subject to ;

          4*inv_pos(x)+square( trace(Ak3*Qt)-trace(Ak2*Qt) )+t2+t3 < 0;

          square( trace(Ak4*Qr)+trace(Ak1*Qr) )+t6+t7-4*y < 0;

%
Qt>0;
Qr>0;

          cvx_end;
          
          
           Qt_n = Qt;
           Qr_n = Qr;
           
            th_bar_r = sqrt(diag(Qr_n))';
            th_tilr = th_bar_r(:,1:end-1);
            theta_r = diag(th_tilr');

            th_bar_t = sqrt(diag(Qt_n))';
            th_tilt = th_bar_t(:,1:end-1);
            theta_t = diag(th_tilt');

          
          a = theta_r;
          b = theta_t;

theta_r_hn_0 = diag(theta_r)‘;
theta_t_hn_0 = diag(theta_t)’;
%
theta_r_barn_0 = [theta_r_hn_0 1];
theta_t_barn_0 = [theta_t_hn_0 1];

Qr_0= (theta_r_barn_0)'(theta_r_barn_0);
Qt_0 = (theta_t_barn_0)'
(theta_t_barn_0);

norm_2_Qt_0 = norm(Qt_0);
norm_2_Qr_0 = norm(Qr_0);

normnuc_Qt = norm_nuc(Qt_0);
normnuc_Qr = norm_nuc(Qr_0);
end

         ro1 = w*ro1;
         ro2 = w*ro2;
         
         
         Qt_n = Qt;
         Qr_n = Qr;
         
         maxro_t = max( norm_nuc(Qt_n) - norm(Qt_n) ); 
         maxro_r = max( norm_nuc(Qr_n) - norm(Qr_n) ); 
     
     
     end
     
     SINR_d = Ps*(abs(h_SD + h_RD*a*h_SR)^2)/(Q_E*(abs( h_RD*b*H_ER*w_opt)^2) + Nd);
       SINR_e = Ps*(abs(Wr'*H_RE*b*h_SR)^2)/(Q_E*(abs(Wr'*H_EE*w_opt + Wr'*H_RE*a*H_ER*w_opt )^2) + Ne);

       
       
         if SINR_e >= SINR_d;
        
        c = c + 1;
    end
     
end

Ex(ii) = c./itration; 

end

figure(1)
plot(Pe_vdb,Ex)
hold on

grid on
box on

Please show us all the CVX and solver output.

I don’t understand what you mean by “cvx showed the status is failed (other cvx is solved),but i can got the result when the whole code ended”. Please make clear what results and CVX and solver output go with which code.

Status: Failed
Optimal value (cvx_optval): NaN

Calling SDPT3 4.0: 162 variables, 64 equality constraints

num. of constraints = 64
dim. of sdp var = 34, num. of sdp blk = 6
dim. of socp var = 12, num. of socp blk = 3
dim. of linear var = 4


SDPT3: Infeasible path-following algorithms


version predcorr gam expon scale_data
HKM 1 0.000 1 0
it pstep dstep pinfeas dinfeas gap prim-obj dual-obj cputime

0|0.000|0.000|1.8e+01|3.6e+03|4.0e+08| 2.572104e+04 0.000000e+00| 0:0:00| chol 1 1
1|0.942|0.774|1.0e+00|8.1e+02|1.1e+08| 2.836782e+05 1.270944e+03| 0:0:00| chol 1 1
2|0.506|0.722|5.1e-01|2.3e+02|3.3e+07| 2.429174e+05 -2.619983e+02| 0:0:00| chol 1 1
3|0.585|0.629|2.1e-01|8.4e+01|1.4e+07| 1.911150e+05 -1.809234e+03| 0:0:00| chol 1 1
4|0.551|0.718|9.5e-02|2.4e+01|4.8e+06| 1.205132e+05 -3.401541e+03| 0:0:00| chol 1 1
5|0.637|0.517|3.4e-02|1.1e+01|2.8e+06| 7.052196e+04 -5.442858e+03| 0:0:00| chol 1 1
6|0.595|0.368|1.4e-02|7.3e+00|2.2e+06| 4.660884e+04 -7.622895e+03| 0:0:00| chol 1 1
7|0.874|0.245|1.8e-03|5.5e+00|2.0e+06| 2.366799e+04 -1.038757e+04| 0:0:00| chol 1 1
8|0.519|0.839|8.5e-04|8.8e-01|3.7e+05| 1.377038e+04 -1.006106e+04| 0:0:00| chol 1 1
9|1.000|0.955|3.0e-07|4.1e-02|2.9e+04| 1.097849e+03 -3.577164e+03| 0:0:00| chol 2 2
10|1.000|0.849|7.9e-07|6.7e-03|6.4e+03| 3.452689e+02 -7.046685e+02| 0:0:00| chol 2 2
11|1.000|0.973|3.7e-07|6.1e-04|1.7e+03| 2.447507e+02 -2.632495e+02| 0:0:00| chol 2 2
12|0.935|0.838|7.0e-09|3.0e-04|3.5e+02| 6.635062e+01 -4.377339e+01| 0:0:00| chol 1 2
13|1.000|1.000|1.2e-08|1.2e-04|1.2e+02| 4.284847e+01 -1.337338e+01| 0:0:00| chol 1 1
14|0.977|0.832|2.2e-09|7.1e-05|2.1e+01| 7.274614e+00 -2.463005e+00| 0:0:00| chol 1 1
15|1.000|1.000|2.2e-10|3.1e-05|7.0e+00| 3.695132e+00 -6.789379e-01| 0:0:00| chol 1 1
16|0.962|0.819|1.1e-10|1.8e-05|1.0e+00| 4.671651e-01 -1.316920e-01| 0:0:00| chol 1 1
17|1.000|1.000|6.7e-12|7.6e-06|3.2e-01| 2.121835e-01 -2.603232e-02| 0:0:00| chol 1 1
18|1.000|0.872|2.1e-12|4.3e-06|4.9e-02| 3.091569e-02 -8.494153e-04| 0:0:00| chol 1 1
19|1.000|0.921|2.8e-13|2.1e-06|1.6e-02| 1.338790e-02 4.390126e-03| 0:0:00| chol 1 1
20|0.717|0.663|9.8e-14|8.3e-07|7.8e-03| 6.409063e-03 2.286558e-03| 0:0:00| chol 1 1
21|0.663|0.568|2.8e-12|3.7e-07|4.8e-03| 3.922464e-03 1.187720e-03| 0:0:00| chol 1 1
22|0.541|0.572|1.8e-12|1.6e-07|3.4e-03| 2.888050e-03 5.974580e-04| 0:0:00| chol 1 1
23|0.447|0.617|8.8e-13|6.1e-08|2.5e-03| 2.217625e-03 2.855260e-04| 0:0:00| chol 1 1
24|0.395|0.575|2.5e-12|2.6e-08|1.9e-03| 1.715432e-03 1.336267e-04| 0:0:00| chol 1 1
25|0.362|0.577|3.3e-12|1.1e-08|1.5e-03| 1.341872e-03 4.590306e-05| 0:0:00| chol 1 1
26|0.381|0.571|3.8e-12|4.7e-09|1.1e-03| 1.025885e-03 -2.256734e-06| 0:0:00| chol 1 1
27|0.395|0.606|2.1e-11|1.9e-09|8.7e-04| 7.703999e-04 -2.608695e-05| 0:0:00| chol 1 1
28|0.440|0.621|4.7e-11|7.1e-10|6.3e-04| 5.516631e-04 -3.319707e-05| 0:0:00| chol 1 1
29|0.490|0.666|1.6e-10|2.4e-10|4.3e-04| 3.721220e-04 -2.994614e-05| 0:0:00| chol 1 1
30|0.578|0.658|1.7e-11|8.5e-11|2.7e-04| 2.258921e-04 -2.354616e-05| 0:0:01| chol 1 1
31|0.831|0.590|1.9e-09|3.8e-11|1.3e-04| 9.514717e-05 -1.647904e-05| 0:0:01| chol 1 1
32|1.000|0.547|1.3e-08|2.3e-11|5.6e-05| 3.237842e-05 -1.020425e-05| 0:0:01| chol 1 1
33|1.000|0.493|3.1e-09|1.5e-11|2.8e-05| 1.182189e-05 -4.941781e-06| 0:0:01| chol 1 1
34|1.000|0.505|1.7e-08|9.0e-12|1.9e-05| 8.128893e-06 -2.186335e-06| 0:0:01| chol 1 1
35|1.000|0.512|9.0e-09|5.3e-12|1.3e-05| 5.703536e-06 -7.611862e-07| 0:0:01| chol 1 1
36|1.000|0.520|2.6e-08|3.1e-12|9.1e-06| 4.041115e-06 -6.515281e-08| 0:0:01| chol 1 1
37|1.000|0.527|2.4e-08|1.7e-12|6.2e-06| 2.866817e-06 2.425972e-07| 0:0:01| chol 1 1
38|1.000|0.534|3.4e-09|9.5e-13|4.2e-06| 2.036569e-06 3.488185e-07| 0:0:01| chol 1 1
39|1.000|0.541|4.8e-08|5.1e-13|2.8e-06| 1.448933e-06 3.555634e-07| 0:0:01| chol 1 1
40|1.000|0.546|7.0e-08|2.7e-13|1.9e-06| 1.032611e-06 3.178771e-07| 0:0:01| chol 1 1
41|1.000|0.552|1.8e-08|1.4e-13|1.3e-06| 7.372429e-07 2.647256e-07| 0:0:01| chol 1 1
42|1.000|0.557|3.4e-09|7.3e-14|8.9e-07| 5.273596e-07 2.106207e-07| 0:0:01| chol 1 2
43|1.000|0.562|5.6e-08|3.7e-14|6.1e-07| 3.779870e-07 1.621456e-07| 0:0:01| chol 1 2
44|1.000|0.568|1.1e-07|1.9e-14|4.2e-07| 2.715175e-07 1.216422e-07| 0:0:01| chol 1 3
stop: primal infeas has deteriorated too much, 8.2e-07
45|1.000|0.572|1.1e-07|1.9e-14|4.2e-07| 2.715175e-07 1.216422e-07| 0:0:01|

number of iterations = 45
primal objective value = 2.71517499e-07
dual objective value = 1.21642225e-07
gap := trace(XZ) = 4.19e-07
relative gap = 4.19e-07
actual relative gap = 1.50e-07
rel. primal infeas (scaled problem) = 1.09e-07
rel. dual " " " = 1.87e-14
rel. primal infeas (unscaled problem) = 0.00e+00
rel. dual " " " = 0.00e+00
norm(X), norm(y), norm(Z) = 3.1e+07, 1.6e-04, 1.0e+00
norm(A), norm(b), norm(C) = 2.3e+03, 1.3e+04, 2.0e+00
Total CPU time (secs) = 0.67
CPU time per iteration = 0.01
termination code = -7
DIMACS: 1.1e-07 0.0e+00 1.9e-14 0.0e+00 1.5e-07 4.2e-07

Try specifying Mosek as solver if available to you. It is a more robust solver than SDPT3. You can also try SeDuMi.

Hi. I have a problem with CVX


. How to write the expression in the picture as a condition of the optimization problem in MATLAB?
Qr and Qt are two symmetrical matrixs with N dimention.

Does
diag(Qr)+diag(Qt) == 1
do what you want?

That is also the same as
diag(Qr)+diag(Qt) == ones(N,1)

That code seems rather simple, so perhaps I am misunderstanding your question?

Of course, for CVX to accept this, diag(Qr)+diag(Qt) must be affine (which includes the special case of Qr and Qt being CVX variables).