Cvx运行过程中出现报错nan

cvx_solver Mosek
cvx_save_prefs
cvx_begin
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_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_jurr)+a0)+log(t_ur)+1)+...
            log_det(real(T_burr+(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_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_jutt)+a0)+log(t_ut)+1)+...
            log_det(real(T_butt+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_ie_r(:,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_ie_r(:,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_ie_t(:,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_ie_t(:,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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Calling Mosek 9.1.9: 558 variables, 111 equality constraints
For improved efficiency, Mosek is solving the dual problem.

MOSEK Version 9.1.9 (Build date: 2019-11-21 11:34:40)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: Windows/64-X86

MOSEK warning 960: E[13,13] = -3.0e+13 is large in absolute size.
MOSEK warning 960: E[6,6] = -3.0e+13 is large in absolute size.
MOSEK warning 960: E[6,6] = -1.2e+13 is large in absolute size.
MOSEK warning 960: E[13,13] = -1.2e+13 is large in absolute size.
MOSEK warning 960: E[13,13] = -4.2e+13 is large in absolute size.
MOSEK warning 960: E[6,6] = -4.2e+13 is large in absolute size.
MOSEK warning 960: E[6,6] = 2.4e+13 is large in absolute size.
MOSEK warning 960: E[13,13] = 2.4e+13 is large in absolute size.
MOSEK warning 960: E[13,13] = -3.0e+13 is large in absolute size.
MOSEK warning 960: E[6,6] = -3.0e+13 is large in absolute size.
Warning number 960 is disabled.
MOSEK warning 62: The A matrix contains a large value of -1.0e+10 in constraint ‘’ (40) at variable ‘’ (50).
MOSEK warning 62: The A matrix contains a large value of 1.0e+10 in constraint ‘’ (40) at variable ‘’ (55).
MOSEK warning 62: The A matrix contains a large value of -1.3e+10 in constraint ‘’ (35) at variable ‘’ (75).
MOSEK warning 62: The A matrix contains a large value of 1.3e+10 in constraint ‘’ (35) at variable ‘’ (79).
MOSEK warning 710: #3 (nearly) zero elements are specified in sparse col ‘’ (107) of matrix ‘A’.
MOSEK warning 710: #1 (nearly) zero elements are specified in sparse col ‘’ (110) of matrix ‘A’.
MOSEK warning 710: #3 (nearly) zero elements are specified in sparse col ‘’ (113) of matrix ‘A’.
MOSEK warning 710: #4 (nearly) zero elements are specified in sparse col ‘’ (116) of matrix ‘A’.
Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 111
Cones : 6
Scalar variables : 118
Matrix variables : 11
Integer variables : 0

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 4
Eliminator terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries : 2 time : 0.00
Lin. dep. - tries : 1 time : 0.00
Lin. dep. - number : 0
Presolve terminated. Time: 0.00
Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 111
Cones : 6
Scalar variables : 118
Matrix variables : 11
Integer variables : 0

Optimizer - threads : 4
Optimizer - solved problem : the primal
Optimizer - Constraints : 103
Optimizer - Cones : 7
Optimizer - Scalar variables : 74 conic : 62
Optimizer - Semi-definite variables: 11 scalarized : 948
Factor - setup time : 0.00 dense det. time : 0.00
Factor - ML order time : 0.00 GP order time : 0.00
Factor - nonzeros before factor : 4291 after factor : 4355
Factor - dense dim. : 0 flops : 1.44e+06
ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME
0 2.4e+01 2.8e+09 8.8e+01 0.00e+00 -8.969345880e+01 -1.161516665e+00 1.0e+00 0.00
1 1.2e+01 1.4e+09 6.3e+01 -1.00e+00 -9.383315842e+01 -5.003492681e+00 4.9e-01 0.00
2 1.9e+00 2.2e+08 2.7e+01 -1.00e+00 -1.568855229e+02 -4.598546914e+01 7.3e-02 0.02
3 5.1e-02 5.9e+06 4.4e+00 -1.00e+00 -2.234563068e+03 -1.670601933e+03 2.0e-03 0.02
4 1.4e-03 1.6e+05 7.1e-01 -1.00e+00 -8.076676464e+04 -6.298051588e+04 5.3e-05 0.02
5 1.8e-04 2.1e+04 2.6e-01 -1.00e+00 -5.817065864e+05 -4.481371132e+05 7.0e-06 0.02
6 8.8e-05 1.0e+04 1.8e-01 -9.99e-01 -1.179916336e+06 -9.091592687e+05 3.4e-06 0.02
7 8.4e-05 9.7e+03 1.8e-01 -9.98e-01 -1.243073113e+06 -9.578682379e+05 3.2e-06 0.02
8 8.4e-05 9.7e+03 1.8e-01 -9.97e-01 -1.243073113e+06 -9.578682379e+05 3.2e-06 0.02
9 8.4e-05 9.7e+03 1.8e-01 -9.98e-01 -1.243073113e+06 -9.578682379e+05 3.2e-06 0.02
Optimizer terminated. Time: 0.03

Interior-point solution summary
Problem status : ILL_POSED
Solution status : PRIMAL_ILLPOSED_CER
Dual. obj: -3.3391424711e+00 nrm: 2e+00 Viol. con: 0e+00 var: 3e-06 barvar: 3e-06 cones: 0e+00
Optimizer summary
Optimizer - time: 0.03
Interior-point - iterations : 10 time: 0.03
Basis identification - time: 0.00
Primal - iterations : 0 time: 0.00
Dual - iterations : 0 time: 0.00
Clean primal - iterations : 0 time: 0.00
Clean dual - iterations : 0 time: 0.00
Simplex - time: 0.00
Primal simplex - iterations : 0 time: 0.00
Dual simplex - iterations : 0 time: 0.00
Mixed integer - relaxations: 0 time: 0.00


Status: Failed
Optimal value (cvx_optval): NaN

ans =

NaN

First:
You should pay attention to the Mosek warnings about large and small magnitude input data. The first thing you need to do is r-scale the data, for instance by changing the units used, so that non-zero input data is within s small number of orders of magnitude of one. If some of the near zero data should be exactly zero, and is only non-zero due to roundoff error in the preparation of the input data, you should replace those small on-zeros by exactly zero.

Second: ;
Also, it’s possible the latest version of Mosek will do better.
Download the latest stable Mosek version, currently 10.1.13, from the Mosek werbsite. You can use that instead of Mosek 9.1.9, which is bundled with CVX 2.2…

To make sure you don’t wind up using Mosek 9.1.9 which is bundled with CVX 2.2:

Download the latest Mosek from the Mosek werbsite and install it under MATLAB. Make sure mosekdiag succeeds. Then reinstall CVX so it will find the new solver.

Either delete or rename the mosek directory under CVX (before reinstalling CVX)
or
cvx_solver shows all the versions of all the solvers available to CVX. Choose the Mosek 10.x version, which might be called something like Mosek_2, then use cvx_solver Mosek_2 to get that version, and you can save_prefs.

In any event, cvx_solver will show all the versions available to CVX.

Third:
Re-run the problem, and make sure Mosek does not issue any warnings. Then see what happens.

已经安装了最新版本10.1.13
Saving prefs…done.

Calling Mosek_5 10.1.13: 549 variables, 108 equality constraints
For improved efficiency, Mosek_5 is solving the dual problem.

MOSEK Version 10.1.13 (Build date: 2023-10-4 13:28:55)
Copyright (c) MOSEK ApS, Denmark WWW: mosek.com
Platform: Windows/64-X86

MOSEK warning 960 (MSK_RES_WRN_SYM_MAT_LARGE): E[6,6] = -2e+13 is large in absolute size.
MOSEK warning 960 (MSK_RES_WRN_SYM_MAT_LARGE): E[13,13] = -2e+13 is large in absolute size.
MOSEK warning 960 (MSK_RES_WRN_SYM_MAT_LARGE): E[6,6] = -3e+13 is large in absolute size.
MOSEK warning 960 (MSK_RES_WRN_SYM_MAT_LARGE): E[13,13] = -3e+13 is large in absolute size.
MOSEK warning 960 (MSK_RES_WRN_SYM_MAT_LARGE): E[6,6] = -3e+13 is large in absolute size.
MOSEK warning 960 (MSK_RES_WRN_SYM_MAT_LARGE): E[13,13] = -3e+13 is large in absolute size.
MOSEK warning 960 (MSK_RES_WRN_SYM_MAT_LARGE): E[6,3] = -1e+10 is large in absolute size.
MOSEK warning 960 (MSK_RES_WRN_SYM_MAT_LARGE): E[6,6] = 2e+13 is large in absolute size.
MOSEK warning 960 (MSK_RES_WRN_SYM_MAT_LARGE): E[13,10] = -1e+10 is large in absolute size.
MOSEK warning 960 (MSK_RES_WRN_SYM_MAT_LARGE): E[13,13] = 2e+13 is large in absolute size.
MOSEK warning 62 (MSK_RES_WRN_LARGE_AIJ): The A matrix contains a large value of 1e+10 in constraint ‘’ (6) at variable ‘’ (4).
MOSEK warning 62 (MSK_RES_WRN_LARGE_AIJ): The A matrix contains a large value of 1e+10 in constraint ‘’ (6) at variable ‘’ (9).
MOSEK warning 62 (MSK_RES_WRN_LARGE_AIJ): The A matrix contains a large value of 1e+10 in constraint ‘’ (34) at variable ‘’ (17).
MOSEK warning 62 (MSK_RES_WRN_LARGE_AIJ): The A matrix contains a large value of -1e+10 in constraint ‘’ (34) at variable ‘’ (24).
MOSEK warning 62 (MSK_RES_WRN_LARGE_AIJ): The A matrix contains a large value of -1e+10 in constraint ‘’ (9) at variable ‘’ (26).
MOSEK warning 62 (MSK_RES_WRN_LARGE_AIJ): The A matrix contains a large value of 1e+10 in constraint ‘’ (9) at variable ‘’ (32).
MOSEK warning 710 (MSK_RES_WRN_ZEROS_IN_SPARSE_COL): #3 (nearly) zero elements are specified in sparse col ‘’ (98) of matrix ‘A’.
MOSEK warning 710 (MSK_RES_WRN_ZEROS_IN_SPARSE_COL): #4 (nearly) zero elements are specified in sparse col ‘’ (101) of matrix ‘A’.
MOSEK warning 710 (MSK_RES_WRN_ZEROS_IN_SPARSE_COL): #1 (nearly) zero elements are specified in sparse col ‘’ (104) of matrix ‘A’.
MOSEK warning 710 (MSK_RES_WRN_ZEROS_IN_SPARSE_COL): #1 (nearly) zero elements are specified in sparse col ‘’ (107) of matrix ‘A’.
Problem
Name :
Objective sense : minimize
Type : CONIC (conic optimization problem)
Constraints : 108
Affine conic cons. : 0
Disjunctive cons. : 0
Cones : 6
Scalar variables : 109
Matrix variables : 11 (scalarized: 948)
Integer variables : 0

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries : 2 time : 0.00
Lin. dep. - tries : 1 time : 0.00
Lin. dep. - primal attempts : 1 successes : 1
Lin. dep. - dual attempts : 0 successes : 0
Lin. dep. - primal deps. : 0 dual deps. : 0
Presolve terminated. Time: 0.01
Optimizer - threads : 4
Optimizer - solved problem : the primal
Optimizer - Constraints : 104
Optimizer - Cones : 7
Optimizer - Scalar variables : 72 conic : 58
Optimizer - Semi-definite variables: 11 scalarized : 948
Factor - setup time : 0.00
Factor - dense det. time : 0.00 GP order time : 0.00
Factor - nonzeros before factor : 4370 after factor : 4431
Factor - dense dim. : 0 flops : 1.45e+06
ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME
0 2.4e+01 5.6e+09 8.4e+01 0.00e+00 -8.646520123e+01 -1.161516665e+00 1.0e+00 0.01
1 1.9e+01 4.4e+09 7.5e+01 -1.00e+00 -8.789391273e+01 -2.317442852e+00 8.6e-01 0.03
2 3.3e+00 7.6e+08 3.6e+01 -1.00e+00 -1.325579618e+02 -2.692216482e+01 1.5e-01 0.03
3 9.8e-02 2.3e+07 5.8e+00 -1.00e+00 -1.197110351e+03 -8.579512069e+02 4.3e-03 0.03
4 1.2e-02 2.7e+06 2.0e+00 -1.00e+00 -8.555047641e+03 -6.422634438e+03 5.2e-04 0.03
5 1.2e-03 2.7e+05 6.4e-01 -1.00e+00 -8.654159856e+04 -6.563533982e+04 5.1e-05 0.05
6 5.2e-04 1.2e+05 4.3e-01 -1.00e+00 -1.914939295e+05 -1.446260024e+05 2.2e-05 0.05
7 4.9e-04 1.1e+05 4.2e-01 -9.99e-01 -2.024323783e+05 -1.530245069e+05 2.1e-05 0.05
8 4.9e-04 1.1e+05 4.2e-01 -9.99e-01 -2.024323783e+05 -1.530245069e+05 2.1e-05 0.05
9 4.9e-04 1.1e+05 4.2e-01 -9.99e-01 -2.024323783e+05 -1.530245069e+05 2.1e-05 0.05
Optimizer terminated. Time: 0.06

Interior-point solution summary
Problem status : ILL_POSED
Solution status : PRIMAL_ILLPOSED_CER
Dual. obj: -3.1345365479e+00 nrm: 2e+00 Viol. con: 0e+00 var: 3e-05 barvar: 2e+53 cones: 0e+00
Optimizer summary
Optimizer - time: 0.06
Interior-point - iterations : 10 time: 0.06
Basis identification - time: 0.00
Primal - iterations : 0 time: 0.00
Dual - iterations : 0 time: 0.00
Clean primal - iterations : 0 time: 0.00
Clean dual - iterations : 0 time: 0.00
Simplex - time: 0.00
Primal simplex - iterations : 0 time: 0.00
Dual simplex - iterations : 0 time: 0.00
Mixed integer - relaxations: 0 time: 0.00


Status: Failed
Optimal value (cvx_optval): NaN

ans =

NaN

You need to follow the advice in my previous post under “First