Questions about CVX intermediate variables

Why is it that the optimization variables obtained by the CVX solver are the same as the feasible solutions as input to CVX, but the intermediate variables are not the same as the constants found using a similar method?Normally, the values that have been optimized by the CVX solver should be better, but the values I get are weird. Is there a problem with the function I’m using? Or is there something in the internal optimization process of CVX that is different from what I thought? The specific procedures and outputs are as follows:
function [O_theta,O_value] = BAlgorithm(hAU,hSU,HAS,hAE,hSE,hDTIU,HDTS,hDTEU,hDTDR,hSDR,hADR,…
h_Bditheta = 1izeros(U_I,M);
g_kditheta = 1i
psi_tidi = zeros(U_I,1);
for i = 1:U_I
h_Bditheta(i,: ) = hAU(i,:)+thetat_*diag(hSU(i,:))*HAS;
g_kditheta(i,: ) = hDTIU(i,:)+thetat_*diag(hSU(i,:))*HDTS;

    wt_temp = wt;
    wt_temp(:,i) = [];
    psi_tidi(i) = sum(abs(h_Bditheta(i,:)*wt_temp).^2)+(abs(g_kditheta(i,:)).^2)*pt+sigmaK2;
hw = diag(h_Bditheta*wt);
h_Bdithetawdi = abs(hw).^2;
temp_di = h_Bdithetawdi./psi_tidi;
a_tauidi = log(1+temp_di);
b_tauidi = temp_di./(1+temp_di);

h_Bejtheta = 1i*zeros(U_E,M);
g_kejtheta = 1i*zeros(U_E,K);
for i = 1:U_E
    h_Bejtheta(i,:) = hAE(i,:)+thetat_*diag(hSE(i,:))*HAS;
    g_kejtheta(i,:) = hDTEU(i,:)+thetat_*diag(hSE(i,:))*HDTS;

g_lktheta = 1i*zeros(K,K);
g_Bktheta = 1i*zeros(K,M);
psi_tik = zeros(K,1);
psi_tek = zeros(K,1);
for i = 1:K
    g_lktheta(i,:) = hDTDR(i,:)+thetat_*diag(hSDR(i,:))*HDTS;
    g_Bktheta(i,:) = hADR(i,:)+thetat_*diag(hSDR(i,:))*HAS;

    g_temp = g_lktheta(i,:);
    g_temp(i) = [];
    p_temp = pt;
    p_temp(i) = [];
    psi_tik(i) = (abs(g_temp).^2)*p_temp+sum(abs(g_Bktheta(i,:)*wt).^2)+sigmaK2;
    psi_tek(i) = (abs(g_temp).^2)*p_temp+sum(abs(g_Bktheta(i,:)*vt).^2)+sigmaK2;
h_ktheta = diag(g_lktheta);
temp_tauik = ((abs(h_ktheta).^2).*pt)./psi_tik;
a_tauik = log(1+temp_tauik);
b_tauik = temp_tauik./(1+temp_tauik);
temp_tauek = ((abs(h_ktheta).^2).*pt)./psi_tek;
a_tauek = log(1+temp_tauek);
b_tauek = temp_tauek./(1+temp_tauek);

    variable theta(1,N) complex
    expression h_Bditheta_v(U_I,M);
    expression g_kditheta_v(U_I,K);
    expression psi_tidi_v(U_I,1);
    for i = 1:U_I
        h_Bditheta_v(i,:) = hAU(i,:)+theta*diag(hSU(i,:))*HAS;
        g_kditheta_v(i,:) = hDTIU(i,:)+theta*diag(hSU(i,:))*HDTS;
        wt_temp = wt;
        wt_temp(:,i) = [];
        psi_tidi_v(i) = sum(pow_abs(h_Bditheta_v(i,:)*wt_temp,2))+pow_abs(g_kditheta_v(i,:),2)*pt+sigmaK2;

    Rtauidi_v = a_tauidi+b_tauidi.*(2*ones(U_I,1)-h_Bdithetawdi.*inv_pos(2*real(diag(h_Bditheta_v*wt).*conj(hw))-...
    Omega_theta_v = 1/N-1*inv_pos(sum(2*real(conj(thetat_).*theta)-abs(thetat_).^2));

    subject to

        max(pow_abs(theta,2)) <= 1;

        expression h_Bejtheta_v(U_E,M);
        expression g_kejtheta_v(U_E,K);
        for i = 1:U_E
            h_Bejtheta_v(i,:) = hAE(i,:)+theta*diag(hSE(i,:))*HAS;
            g_kejtheta_v(i,:) = hDTEU(i,:)+theta*diag(hSE(i,:))*HDTS;
        Etaueej_v = sum(2*real((h_Bejtheta_v*vt).*conj(h_Bejtheta*vt))-abs(h_Bejtheta*vt).^2,2)+...
        min(Etaueej_v) >= ET*taut(2)/rho;

        expression g_lktheta_v(K,K);
        expression g_Bktheta_v(K,M);
        expression psi_tik_v(K,1);
        expression psi_tek_v(K,1);
        for i = 1:K
            g_lktheta_v(i,:) = hDTDR(i,:)+theta*diag(hSDR(i,:))*HDTS;
            g_Bktheta_v(i,:) = hADR(i,:)+theta*diag(hSDR(i,:))*HAS;
            g_temp_v = g_lktheta_v(i,:);
            g_temp_v(i) = [];
            p_temp = pt;
            p_temp(i) = [];
            psi_tik_v(i) = pow_abs(g_temp_v,2)*p_temp+sum(pow_abs(g_Bktheta_v(i,:)*wt,2))+sigmaK2;
            psi_tek_v(i) = pow_abs(g_temp_v,2)*p_temp+sum(pow_abs(g_Bktheta_v(i,:)*vt,2))+sigmaK2;
        h_ktheta_v = diag(g_lktheta_v);
        Rtauik_v = a_tauik+b_tauik.*(2*ones(K,1)-(abs(h_ktheta).^2).*inv_pos(2*real(h_ktheta_v.*conj(h_ktheta))-...
        Rtauek_v = a_tauek+b_tauek.*(2*ones(K,1)-(abs(h_ktheta).^2).*inv_pos(2*real(h_ktheta_v.*conj(h_ktheta))-...
        min((1/taut(1))*Rtauik_v+(1/taut(2))*Rtauek_v) >= RT;


O_theta = theta;
O_value = min((1/taut(1))*Rtauidi_v);



I’m not sure I understand your question. But perhaps this helps:

The only items you can rely on as being populated with their optimal value after cvx_end are CVX variables, in your case, only theta.

CVX variables are populated with their optimal values after cvx_end, but CVX expressions are not necessarily populated with their optimal values after cvx_end. So to get the optimal values of CVX expressions, you need to compute them after cvx_end, starting with the CVX optimal variable values.

The optimization is performed correctly even though the populated values for the expressions might not be correct. That reflects a CVX design decision. At the expense of some additional computation, CVX could have been written to automatically populate CVX expressions with their final optimal value, but was not designed that way. At minimum, the CVX Users’ Guide should have been clear and explicit about this (design decision), but is not.

Thank you very much for your reply

But why is the value of the objective function corresponding to the feasible solution of the input and the optimal solution given by CVX different?

You need to be clearer as to exactly what is different from what. Be very specific. You haven’t even shown us the CVX or solver output. What exactly is “feasible solution of the input”? Are you claiming there is a feasible solution which provides a better (larger) objective value than what CVX says is the optimal solution? If so, are you sure that “feasible solution” is actually feasible?

The objective function includes expressions, and not just variables. That means that after cvx_end, min((1/taut(1))*Rtauidi_v)+eta*Omega_theta_v might not be the actual optimal objective value. However, if you recompute this after cvx_end, starting only from CVX variables (which should be populated with their optimal values), you should get the optimal objective value. CVX does populate cvx_optval with the optimal objective value if the optimization is solved.

Anything other that declared variables, is an expression, whether or not it is declared as an expression.