Problem: Illegal operation: {real affine} - {invalid}

Hello, a error occured when I run my code, my code is as follows, please help me. Thanks!
This is my matlab codes:

clear all
clc
tic
global h_mB h_mE g_nB g_nE
W = 8;
g_nB = [1.44924338701434e-06*(1+1i),3.63188309794729e-07*(1+1i),9.07472859811576e-08*(1+1i),2.08958242236184e-07*(1+1i),0.000543522514688916*(1+1i),1.77911904616958e-06*(1+1i),1.53372715576804e-07*(1+1i),1.97159803748322e-07*(1+1i),3.46390370939759e-06*(1+1i)];
g_nE = [5.67255098422262e-05*(1+1i),1.25912635166875e-05*(1+1i),4.78015765032432e-05*(1+1i),8.91546016462140e-05*(1+1i),1.40389165890170e-05*(1+1i),4.98983183289721e-05*(1+1i),1.10754244910520e-04*(1+1i),2.84635902374235e-03*(1+1i),8.50214371168785e-02*(1+1i)];
h_mB = [4.34404855030804e-06,2.26142258059391e-07,7.25067001767426e-06,1.20084212562690e-05,0.000391180435143247,4.89525724968232e-07];
h_mE = [2.33534605202823e-07,5.54513400422210e-08,7.26470059779064e-07,2.18580357625511e-06,5.15089617626485e-08,3.73847113626707e-07];
n_B = 1e-10;
n_E = 1e-10;
delta = 1e-08;
cn_req = 10;
cm_req = 5;
h_mE_max = h_mE +delta;
h_mE_min = h_mE -delta;
g_nE_min = g_nE -delta;
P = 1;
M = size(h_mB,2);
N = size(g_nB,2);
q = [1,1,1,1,1,1];
pv_m_max = 1;
result = [];
e = 1;
converged = false;

for n=1:1:N
    T_K(n) = 0;
    R_l_K(n) = 0;
end

F = [];
max_iterations = 1000;

for l=1:1:max_iterations

for m=1:1:M
    M1(m) = q(m).*h_mB(m)+(sum(q(1:m-1).*h_mB(1:m-1)+n_B));
end
cvx_begin

variables t_k r_l_k p_V(1,N) x_k y_l
expressions result M2(m) M3(m) M3(m) M4(m) t
G_mE_min  =  zeros(1, N);

for n = 1:N
    G_mE_min(:, n) = g_nE_min(:,n)*conj(g_nE_min(:,n));
end
%     p_V(1,N) = p_v(1,N)'*p_v(1,N);
for m=1:1:M
    for n=1:1:N
        M2(m) = sum(q(1:m-1).* h_mE_min(1:m-1))+sum((p_V(1:n).* G_mE_min(1:n))) +n_E;
    end
end
for m=1:1:M
    M3 = sum(q(1:m-1).*h_mB(1:m-1))+n_B;%log2
end
for n=1:1:N
    for m=1:1:M
        M4(m) = ((sum(q(1:m-1).* h_mE_min(1:m-1))+sum(q(m+1:M).* h_mE_min(m+1:M))+...
            sum(p_V(1:n-1).* G_mE_min(1:n-1))+sum(p_V(n+1:N).* G_mE_min(n+1:N))+n_E)+q(m)*h_mB(m));
    end
end



maximize t
subject to:

t >= cm_req;

p_V >= 0;

exp(x_k+y_l-t_k-r_l_k)>=2^(t/W);

M1 >= exp(x_k);

M2(m) >= exp(y_l);

for m=1:1:M
    for n = 1:1:N
        10*M3 <= 10*exp(T_K(n)) * (t_k - T_K(n) + 1);
        10*M4(m) <= 10*exp(R_l_K(n)) * (r_l_k - R_l_K(n) + 1);
    end

end
for m=1:1:M
    sum((p_V(1:m)).^2) <= P;
end

cvx_end

T_K(n) = t_k;
R_l_K(n) = r_l_k;

result = [result, cvx_optval];
if length(result) > l && abs(result(end) - result(end - 1)) < 0.01
    break;
    
end

end
opt_v = p_V;
sol = result(end);

This is the output
Successive approximation method to be employed.
For improved efficiency, SDPT3 is solving the dual problem.
SDPT3 will be called several times to refine the solution.
Original size: 197 variables, 34 equality constraints
1 exponentials add 8 variables, 5 equality constraints

Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status
--------±--------------------------------±--------
1/ 1 | 5.081e+00 1.588e+00 0.000e+00 | Failed
0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Failed
0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Failed
1/ 1 | 1.804e+00 1.648e-01 0.000e+00 | Failed
0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Failed

Status: Failed
Optimal value (cvx_optval): NaN
Successive approximation method to be employed.
For improved efficiency, SDPT3 is solving the dual problem.
SDPT3 will be called several times to refine the solution.
Original size: 197 variables, 34 equality constraints
1 exponentials add 8 variables, 5 equality constraints

Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status
--------±--------------------------------±--------
1/ 1 | 8.000e+00 2.259e+01 0.000e+00 | Unbounded
1/ 1 | 8.000e+00s 1.425e+01 0.000e+00 | Unbounded
1/ 1 | 8.000e+00s 5.418e+00 0.000e+00 | Unbounded
1/ 1 | 1.295e+00 5.412e-02 0.000e+00 | Unbounded
0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Unbounded

Status: Infeasible
Optimal value (cvx_optval): -Inf

错误使用 + (第 83 行)
Disciplined convex programming
error:
Illegal operation: {real
affine} - {invalid}

出错 - (第 21 行)
z = plus( x, y, true, cheat );

出错 beamforming (第 85 行)
10M3 <=
10
exp(T_K(n)) * (t_k
- T_K(n) + 1);

Also, use Mosek as solver if you have access to it, otherwise see CVXQUAD: How to use CVXQUAD's Pade Approximant instead of CVX's unreliable Successive Approximation for GP mode, log, exp, entr, rel_entr, kl_div, log_det, det_rootn, exponential cone. CVXQUAD's Quantum (Matrix) Entropy & Matrix Log related functions .

Also, improve the numerical scaling of the problem so that non-zero input data is within a small number of orders of magnitude of one.

Thank you very much. I solved the problem by changing the scaling. But I found the new problem [Optimal value (cvx_optval): NaN]. What should I
Successive approximation method to be employed.
For improved efficiency, SDPT3 is solving the dual problem.
SDPT3 will be called several times to refine the solution.
Original size: 128 variables, 13 equality constraints
1 exponentials add 8 variables, 5 equality constraints

Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status
--------±--------------------------------±--------
1/ 1 | 6.418e+00 3.352e+00 0.000e+00 | Failed
1/ 1 | 7.785e+00s 7.529e-01 0.000e+00 | Failed
1/ 1 | 2.534e+00 1.484e-01 0.000e+00 | Failed
0/ 0 | 2.770e+00 0.000e+00 0.000e+00 | Failed
1/ 1 | 2.644e+00 2.502e-01 0.000e+00 | Failed
0/ 0 | 2.749e+00 0.000e+00 0.000e+00 | Failed

Status: Failed
Optimal value (cvx_optval): NaN

Successive approximation method to be employed.
For improved efficiency, SDPT3 is solving the dual problem.
SDPT3 will be called several times to refine the solution.
Original size: 128 variables, 13 equality constraints
1 exponentials add 8 variables, 5 equality constraints

Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status
--------±--------------------------------±--------
1/ 1 | 5.684e+00 4.751e+00 0.000e+00 | Failed
1/ 1 | 3.366e+00 6.589e-02 0.000e+00 | Failed
0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Failed
0/ 0 | 9.915e-01 0.000e+00 0.000e+00 | Failed
0/ 0 | 1.264e+00 0.000e+00 0.000e+00 | Failed

Status: Failed
Optimal value (cvx_optval): NaN

As I wrote above,

Also, use Mosek as solver if you have access to it, otherwise see CVXQUAD: How to use CVXQUAD’s Pade Approximant instead of CVX’s unreliable Successive Approximation for GP mode, log, exp, entr, rel_entr, kl_div, log_det, det_rootn, exponential cone. CVXQUAD’s Quantum (Matrix) Entropy & Matrix Log related functions .

Thanks for your comment. It’s my new output. The status is solved, but the result is wrong.
Successive approximation method to be employed.
For improved efficiency, SeDuMi is solving the dual problem.
SeDuMi will be called several times to refine the solution.
Original size: 136 variables, 6 equality constraints
7 exponentials add 56 variables, 35 equality constraints

Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status
--------±--------------------------------±--------
7/ 7 | 4.855e+00 9.589e-01 0.000e+00 | Unbounded
0/ 6 | 3.473e-01 9.582e+00 9.506e+00 | Solved

Status: Solved
Optimal value (cvx_optval): +0
and it’s my new code.
clear all
clc
tic
global h_mB h_mE g_nB g_nE
W = 2;

g_nB = [1,1,1,1,1,1,1,1,1];
g_nE = [1,1,1,1,1,1,1,1,1];
h_mB = [1,1,1,1,1,1];
h_mE = [1,1,1,1,1,1];
n_B = 1e-10;
n_E = 1e-10;
delta = 1e-08;
cn_req = 5;
cm_req = 0.1;%阈值
h_mE_max = h_mE +delta;
h_mE_min = h_mE -delta;
g_nE_min = g_nE -delta;
% P = 100;
M = size(h_mB,2);
N = size(g_nB,2);
q = [1,1,1,1,1,1];
q0 = [0,0,0,0,0,0];
pv_m_max = 1;
T = [];

for n=1:1:N
    T_K(n) = 0;
    R_l_K(n) = 0;
end

max_iterations = 1000;

for l=1:1:max_iterations

for m=1:1:M
    M1(m) = q(m).*h_mB(m)+(sum(q(1:m-1).*h_mB(1:m-1)+n_B));
end
cvx_begin

variables t_k r_l_k p_V(1,N) x_k y_l
expressions result M2(m) M3(m) M3(m) M4(m) t
G_mE_min  =  zeros(1, N);

for n = 1:N
    G_mE_min(:, n) = g_nE_min(:,n)*conj(g_nE_min(:,n));
end

for m=1:1:M
    for n=1:1:N
        M2(m) = sum(q(1:m-1).* h_mE_min(1:m-1))+sum(q(m+1:M).* h_mE_min(m+1:M))+sum((p_V(1:n).* abs(G_mE_min(1:n)))) +...
            sum((p_V(n+1:N).* abs(G_mE_min(n+1:N))))+n_E;
    end
end
for m=1:1:M
    M3 = sum(q(1:m-1).*h_mB(1:m-1))+n_B;%log2
end
for n=1:1:N
    for m=1:1:M
        M4(m) = ((sum(q(1:m-1).* h_mE_min(1:m-1))+sum(q(m+1:M).* h_mE_min(m+1:M))+...
            sum(p_V(1:n-1).* G_mE_min(1:n-1))+sum(p_V(n+1:N).* abs(G_mE_min(n+1:N)))+n_E)+q(m)*h_mB(m))+n_E;
    end
end
maximize t
subject to:

for m = 1 : M

W*( log((sum(q.*h_mB)+n_B)/n_B)/log(2) - sum((M2(m)))…
+ sum(log(M4(m))/log(2)))>= cm_req;%log2
end

  M1>=exp(x_k);

  M2(m)>=exp(y_l);

for m=1:1:M
    for n = 1:1:N
        0.01*sum(M3) <= 0.01*exp(T_K(n)) * (t_k - T_K(n) + 1);
        0.01*sum(M4(m)) <= 0.01*exp(R_l_K(n)) * (r_l_k - R_l_K(n) + 1);
    end
end

    2^(t/W) <= exp(x_k+y_l-t_k-r_l_k);
    
cvx_end

T_K(n) = t_k;
R_l_K(n) = r_l_k;

        
    for n = 1 : N
        if isnan(t)
            sol = -inf;
            return;
        end
    end

T = [T, t];
if length(T) > l && abs(T(end) - T(end - 1)) < 0.1
    break;
    
end

end
opt_v = p_V;
sol = result(end);

Follow my previously provided advice

Also, improve the numerical scaling of the problem so that non-zero input data is within a small number of orders of magnitude of one.

and then provide us with the evidence that the solution is “wrong”.