How to use CVX in wireless communication,especially in long and complex expressions?

I am a new learner in CVX. Recently, I have found some diffiulties in long and complex expressions.The code is as follows. I need to get the minimize number of xi_TR_D and the variable P is a matrix.

while diffR > threshold
    n = n+1;
    cvx_begin quiet
        variable p(3,3) complex;
        variable X_CD_C;
        [power_T,X_CD_C,X_CD_D,xi_D_D,xi_C,r_0,xi_CD_D,xi_CD_C] = get_xi_TR_D(p, X_CD_C,beta_0,rho,h_TC,h_C,h_D,eta,power_B,h_BT,sigma_T,sigma_C,sigma_D,r_0);
        minimize xi_TR_D;
        subject to
            X_CD_C+X_CD_D+1 >= xi_CD_D;
            X_CD_D+X_CD_C+1 >= xi_CD_C;
            sum_square_abs(p(:)) <= power_T;
            X_CD_C <= 0;
            X_CD_D <= 0;
    cvx_end
    optimal_solution = xi_TR_D; 
 
    fprintf('Optimal Solution (x): %f\n', optimal_solution);
    disp(n);
end

function [power_T,X_CD_C,X_CD_D,xi_D_D,xi_C,r_0,xi_CD_D,xi_CD_C] = get_xi_TR_D(p, X_CD_C,beta_0,rho,h_TC,h_C,h_D,eta,power_B,h_BT,sigma_T,sigma_C,sigma_D,r_0)
    power_T = beta_0*rho*eta*(power_B*abs(h_BT)+sigma_T^2)/(1-beta_0);    
    SINR_BT_C = (1-r_0)*power_B*det(h_BT)^2/sigma_T^2;
    SINR_CD_C = (det(transpose(h_TC) * p(:,1))^2 * power_T) / ((det(transpose(h_C) * p(:,2))^2 * power_T) + (det(transpose(h_C) * p(:,3))^2 * power_T) + sigma_C^2);%C_CD的信噪比
    SINR_CD_D = (det(transpose(h_TR) * p(:,1))^2 * power_T) / ((det(transpose(h_D) * p(:,2))^2 * power_T) + (det(transpose(h_D) * p(:,3))^2 * power_T) + sigma_D^2);%D_CD的信噪比
    SINR_C_C = (det(transpose(h_TC) * p(:,2))^2 * power_T) / ((det(transpose(h_TC) * p(:,3))^2 * power_T)+sigma_C^2);
    SINR_D_D = (det(transpose(h_TR) * p(:,3))^2 * power_T) / ((det(transpose(h_TR) * p(:,2))^2 * power_T)+sigma_D^2);
    R_BT_C = beta_0 * log2(1 + SINR_BT_C);%BS到DTU的速率
    R_CD_D = (1-beta_0) * log2(1+SINR_CD_C);%DTU发送给DRU的公共流速率
    R_CD_C = (1-beta_0) * log2(1+SINR_CD_D);%DTU发送给CU的公共流速率
    R_D_D = (1-beta_0) * log2(1+SINR_C_C);%DTU到DRU的私有流速率
    R_C_C = (1-beta_0) * log2(1+SINR_C_C);%DTU到CU的私有流速率
    R_TR_D = R_D_D + R_CD_D;%DTU到DRU的总速率
    R_TC_C = R_C_C + R_CD_C;%DTU到CU的总速率 
    R_CD = min(R_CD_C,R_CD_D);
    X_CD_D = -R_CD- X_CD_C;
    xi_CD_D = 1 - C_CD_D;
    xi_CD_C = 1 - C_CD_C;
    xi_C_C = 1 - R_C_C;
    xi_D_D = 1 - R_D_D;
    xi_TR_D = xi_CD_D + xi_D_D;
    xi_C = xi_CD_C + xi_C_C;    
end

Perhaps you can help people help you by telling us exactly where your difficulty is. Before you do so, please make sure you have proven that each times CVX is called, it is being presented a convex optimization problem, as discussed in Why isn't CVX accepting my model? READ THIS FIRST! .

You seem to be calling CVX in a while loop. But from the code you show (perhaps this is not all of your code), it is not apparent to me how the problem inputs change across while loop iterations. if you are doing some form of SCA, which is not apparent from your code, that can have its own issues, including not converging to anything, possibly with solutions and inputs becoming wilder and wilder until the solver fails for some reason, or converging to something which is not even a local optimum of the optimal problem, let alone a global optimum.

xi_D_D = 1 - (1-beta_0) * log2(1+((square_abs(transpose(h_TR) * P(:,3))^2 * power_T) / ((square_abs(transpose(h_TR) * P(:,2))^2 * power_T)+sigma_D^2)));
violates CVX rules. But then xi_D_D is never used, so why have that statement?

Please re-read the link, but more carefully this time.

Thanks a lot for your reply. I have no idea to change the expression to solve the problem, could you give me some links to learn?

I have no idea what problem you want to solve. Your program has a statement to set xi_D_D , but it is never used. There are a lot of CVX examples, including in Electrical Engineering, at Example library | CVX Research, Inc. .

Perhaps you didn’t understand the link. CVX can be used for convex optimization problems, not for non-convex optimization problems, and not even for all convex optimization problems.

Have you proven your optimization problem is convex? That is the first step. if it is not convex, then CVX is not the right tool for the problem. if you concoct a scheme to solve a series of convexified optimization problems, such as SCA, you’re on your own; and you should have no expectation that such a scheme will work, even though it might.