Ask for help:Why does the error occur in the third iteration?

Error using *
Disciplined convex programming error:
Invalid numeric values (NaNs) may not be used in CVX expressions.

Error in main (line 127)
object = object + 2real(w_hat_j0(:,j)’ * hr_reg * hr_reg’ * w_hat_j(:,j)) - …
my CVX code is here:
while iter<=Nmax
iter
object=0;
cvx_begin quiet
variable w_hat_j(M,K) complex
variable w_hat_theta(M,1) complex
variable t1(1,K)
variable t2(1,K)
variable t3(1,K)
variable t4(1,K)
variable t5
for j=1:K
object = object + 2
real(w_hat_j0(:,j)’ * hr_reg * hr_reg’ * w_hat_j(:,j)) - …
real(w_hat_j0(:,j)’ * hr_reg* hr_reg’ * w_hat_j0(:,j));
end
M1=object+2*real(w_hat_theta0’hr_reghr_reg’*w_hat_theta)-real(w_hat_theta0’hr_reghr_reg’w_hat_theta0);
maximize M1
% 约束条件
subject to
% 添加约束(2)
for n=1:K
for i=1:K-1
2
real(w_hat_j0(:,i+1)‘*h_hat_j(:,n)*h_hat_j(:,n)’*w_hat_j(:,i+1))-…
real(w_hat_j0(:,i+1)‘*h_hat_j(:,n)*h_hat_j(:,n)’*w_hat_j0(:,i+1)) >= …
square_abs(h_hat_j(:,n)‘w_hat_j(:,i));
2
real(w_hat_theta0’*h_hat_j(:,n)*h_hat_j(:,n)‘*w_hat_theta)-…
real(w_hat_theta0’*h_hat_j(:,n)*h_hat_j(:,n)‘*w_hat_theta0)>=square_abs(h_hat_j(:,n)‘w_hat_j(:,K));
end
end
%添加约束(3)
for n=1:K
right=0;
for j=1:n-1
right=right+2
real(w_hat_j0(:,j)’*h_hat_j(:,n)*h_hat_j(:,n)’*w_hat_j(:,j))-…
real(w_hat_j0(:,j)‘*h_hat_j(:,n)*h_hat_j(:,n)’*w_hat_j0(:,j));
end
e_i=0;
for i=1:n
e_i=e_i+(norm(Hru(:,i)‘*phi0).^2)deta_v+deta;
2
real(w_hat_j0(:,n)’*h_hat_j(:,i)*h_hat_j(:,i)‘*w_hat_j(:,i))-…
real(w_hat_j0(:,n)’*h_hat_j(:,i)*h_hat_j(:,i)‘w_hat_j0(:,n))>=r_th(right+e_i);
end
end
%添加约束(4)
for n=1:K
right=0;
e_k=0;
for j=1:K
e_k=e_k+(norm(Hru(:,i)’*phi0).^2)deta_v+deta;
right=right+2
real(w_hat_j0(:,j)‘*h_hat_j(:,n)*h_hat_j(:,n)’*w_hat_j(:,j))-…
real(w_hat_j0(:,j)‘*h_hat_j(:,n)*h_hat_j(:,n)‘w_hat_j0(:,j));
end
2
real(w_hat_theta0’*h_hat_j(:,n)*h_hat_j(:,n)’*w_hat_theta)-…
real(w_hat_theta0’*h_hat_j(:,n)*h_hat_j(:,n)'w_hat_theta0)>=r_th_sita(right+e_k);
end
%
%添加约束(5)
t_total_1=0;
t_total_2=0;
for n=2:K
t_total_1=t_total_1+t1(:,n)-t2(:,n);
end
for n=1:K
t_total_2=t_total_2+t3(:,n)-t4(:,n);
end
t_total_1 - t_total_2 + t5 >= rol_1;

%%约束(6)
    left=[];
    x=zeros(1,K);
    y=zeros(1,K);
    for i=1:K
        left=[2*he*w_hat_j(:,i),left];
    end
    for i=1:K
        aux_2z=0;
        x(i) = exp(t30(:, i));
         aux_2z=t3(:,i) + 1 - t30(:,i) ;
         norm([2 * sqrt(x(i)), aux_2z, y(i)]') <= aux_2z + y(i);
        norm([left,2*he*w_hat_theta,2*deta,y(i)-1]')<=...
        y(i) + 1;
    end

% 添加约束(8)
for i=2:K
left=0;
for j=1:i
left=left+2*real(w_hat_j0(:,j)‘*h_hat_j(:,i)*h_hat_j(:,i)’*w_hat_j(:,j))-…
real(w_hat_j0(:,j)‘*h_hat_j(:,i)*h_hat_j(:,i)‘w_hat_j0(:,j));
end
left+deta>=exp(t1(:,i));
end
%%%约束(7)
z = zeros(1, K); % 定义 z(i)
w = zeros(1, K); % 定义 w(i)
for i = 2:K
% 定义 left
left = [];
for j = 1:i-1
left = [2 * h_hat_j(:, i)’ * w_hat_j(:, j), left];
end
% 定义 z(i)
aux_y =0;
z(i) = exp(t20(:, i));
z(1)=1;
% 第一部分:定义 w(i) 的锥约束
aux_y = t2(:, i) + 1 - t20(:, i); % 定义辅助变量 aux_y
norm([2 * sqrt(z(i)), aux_y, w(i)]‘) <= aux_y + w(i);
% 第二部分:重新构造的主约束
norm([left, 2 * deta, w(i) - 1]’) <= w(i) + 1;
end
%添加约束(9)
for i=1:K
left=0;
for j=1:K
left=left+2
real(w_hat_j0(:,j)’*he’hew_hat_j(:,j))-…
real(w_hat_j0(:,j)‘he’hew_hat_j0(:,j));
end
left=left-(2
real(w_hat_j0(:,i)’*he’hew_hat_j(:,i))-…
real(w_hat_j0(:,i)‘he’hew_hat_j0(:,i)));
left+2
real(w_hat_theta0’*he’hew_hat_theta)-…
real(w_hat_theta0’he’hew_hat_theta0)+deta>=exp(t4(:,i));
end
%添加约束(10)
2
real(w_hat_j0(:,1)’*he’hew_hat_j(:,1))-…
real(w_hat_j0(:,1)'he’hew_hat_j0(:,1))>=exp(t5);
%添加约束(11)
sum=0;
for i=1:K
sum = sum + square_pos(norm(w_hat_j(:,i)));
end
sum=sum+square_pos(norm(w_hat_theta));
sum<=Ps;
cvx_end
object_history(iter) = M1;
alpha = 0.8/iter; % 动态调整步长系数
w_hat_j0 = alpha
w_hat_j+(1-alpha)w_hat_j0;
w_hat_theta0 = alpha
w_hat_theta+(1-alpha)*w_hat_theta0;
t20=alpha *t2+(1 - alpha) *t20;
t20(:,1)=0;
t30=alpha *t3+(1 - alpha) *t30;
iter=iter+1;
end

The error indicates that you input NaNs in the problem data. If, as you say, you input NaNs in the 3rd iteration, then probably you should check what happens in the 2nd iteration, what results you get and then adjust your data accordingly. Removing quiet will help, checking the status of the solve will also help.

after removing the quiet,the output of the code is as follows. Does this indicate that the CVX solve status was unsuccessful from the beginning, suggesting that there is an error in my optimization problem?
sim =

 1

iter =

 1

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: 225 variables, 96 equality constraints
6 exponentials add 48 variables, 30 equality constraints

Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status
--------±--------------------------------±--------
6/ 6 | 8.000e+00 1.138e+01 0.000e+00 | Unbounded
6/ 6 | 8.000e+00s 4.853e+00 0.000e+00 | Unbounded
0/ 0 | 0.000e+00 0.000e+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

Status: Failed
Optimal value (cvx_optval): NaN

iter =

 2

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: 225 variables, 96 equality constraints
6 exponentials add 48 variables, 30 equality constraints

Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status
--------±--------------------------------±--------
6/ 6 | 8.000e+00 1.106e+01 0.000e+00 | Unbounded
6/ 6 | 8.000e+00s 3.841e+00 0.000e+00 | Unbounded
0/ 0 | 0.000e+00 0.000e+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

Status: Failed
Optimal value (cvx_optval): NaN

iter =

 3

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: 225 variables, 96 equality constraints
6 exponentials add 48 variables, 30 equality constraints

Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status
--------±--------------------------------±--------
6/ 6 | 8.000e+00 7.879e+00 0.000e+00 | Unbounded
6/ 6 | 1.204e+00 8.820e-02 0.000e+00 | Unbounded
6/ 6 | 2.154e-01 2.864e-03 0.000e+00 | Unbounded
0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Unbounded

Status: Infeasible
Optimal value (cvx_optval): -Inf

iter =

 4

Error using *
Disciplined convex programming error:
Invalid numeric values (NaNs) may not be used in CVX expressions.

Error in main (line 127)
object = object + 2*real(w_hat_j0(:,j)’ * hr_reg * hr_reg’ * w_hat_j(:,j)) - …

See my comments in your previous thread Disciplined convex programming error: Invalid numeric values (NaNs) may not be used in CVX expressions. . They didn’t magically become invalid because you started a new thread on the same topic.

One other thing you can try is to use Mosek as solver, if available to you. Otherwise, follow the advice at 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 .

But perhaps your SCA implementation is just is not up to the task, as I suggested previously.

When switching to the MOSEK solver, the result still indicates that the solution is infeasible. Interior-point solution summary
Problem status : DUAL_INFEASIBLE
Solution status : DUAL_INFEASIBLE_CER
Primal. obj: -1.1089791276e-06 nrm: 4e+02 Viol. con: 4e-15 var: 0e+00 cones: 0e+00
Optimizer summary
Optimizer - time: 0.02
Interior-point - iterations : 18 time: 0.02
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: Infeasible
Optimal value (cvx_optval): -Inf
And when I remove the optimization variables and constraints related to t, the code runs successfully and shows that the solution can be found.The running result is as follows.
Interior-point solution summary
Problem status : PRIMAL_AND_DUAL_FEASIBLE
Solution status : OPTIMAL
Primal. obj: -1.9699019074e-03 nrm: 1e+03 Viol. con: 3e-06 var: 3e-10 cones: 0e+00
Dual. obj: -1.9698899754e-03 nrm: 4e+02 Viol. con: 0e+00 var: 5e-10 cones: 4e-20
Optimizer summary
Optimizer - time: 0.00
Interior-point - iterations : 14 time: 0.00
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: Solved
Optimal value (cvx_optval): +0.000998504
Does this mean that the optimization problem I formulated is infeasible?

There is nothing preventing a solution from one iteration resulting in the problem in the next iteration being infeasible. You have no safeguards to prevent that. There is a reason high quality non-convex optimization solvers are more than 10 lines of code long. it is out of scope of this forum for someone to write a non-convex solver for you, or to fix up your current implementation.

Depending on the problem input data and starting values used, you may or may not get lucky and have the SCA converge to something. And if it does converge to something, that something may or may not be a local or global optimum of the original problem.

if you don’t get lucky, I suggest you use an existing non-convex solver, which could be under YALMIP, but not under CVX.