Conversion from double to cvx

Uncategorized
Jul 15, 2021
H

I am pasting my code below. I need to find the best c_q. So, I declared it as a variable. This variable is used in calculation of dist, dist_UM which are then used in constraints and objective.

The current code is throwing the error that conversion from double to cvx is not possible. But I do not know any other way to code this situation. Kindly help

dist = zeros(K,M,N);
dist_UM = zeros(M,N);

cvx_begin
variables c_q(M,N, 1,2);

    for k = 1:K
        for m = 1:M
            for n = 1:N
                dist(k,m,n) = norm(reshape(c_q(m,n,:,:),[1 2]) -W_k(k,:),2);
            end
        end
    end
h_DU = h_0 ./ (dist.^2 + H^2);
gamma_DU = (P_DU .* h_DU) / sigma2;

  
    for m = 1:M
            for n = 1:N
                dist_UM(m,n) = norm(reshape(c_q(m,n,:,:),[1 2]) - W_m,2);
            end
     end

h_UM = h_0 ./ ( dist_UM.^2 + (H-H_m)^2 );
gamma_UM = (P_UM .* h_UM) / sigma2;
E_DU = myObj.cal_energy(delta, sigma2, h_DU, l_DU,B_DU);
E_UM = myObj.cal_energy(delta, sigma2, permute(repmat(h_UM,1, 1,K),[3 1 2]), l_UM,B_UM);
E_UK = myObj.cal_energy(delta, sigma2, h_DU, l_UK,B_UK);
temp_E = w_1 * a .* E_DU + w_2 * (E_UM + a .* E_UK);
E_f = myObj.calc_Ef(c_q,Delta,Q,M,N);
Rcup_kmn = R_kmn;
for k = 1:K
    for m = 1:K
        for n = 1:N
            pir = [m*n*k m*n];
            Rcup_kmn(k,m,n) = B*log2(1 + C/(sigma2 * D1*D2 + A)) + (B/log(2))*(1/(D1*D2 + (A+C)/sigma2) - 1/(D1*D2))*(pir*( c_q(m,n,:,:) - q(m,n,:,:))')

        end
    end
end

Rcup = (1/N) * sum(a.*Rcup_kmn, 3);
aR =  a .* Rcup;   
LO = L_k .* (1+O_k);
minimize sum(temp_E(:)) + sum(E_f(:)) - zeta*(sum(Rcup_kmn(:))/N);  

for m = 1:M
    c_q(m,1,:,:) == c_q(m,1,:,:); %C6
end
for m = 1:M
    for n = 1:N-1
        norm(c_q(m,n+1,:,:) - c_q(m,n,:,:))^2 <= S_max^2; %C7
    end
end
a .* dist <= H *sqrt(3); %C8
sum(LO) <= sum(aR(:)) <= C_max;%C10 
for n = 1:N
    for m = 1:M
        for j = m+1:M
            - norm(reshape(q(m,n,:,:),[1 2])-reshape(q(j,n,:,:),[1 2]))^2 +  2*(reshape(q(m,n,:,:),[1 2])-reshape(q(j,n,:,:),[1 2])) * transpose(reshape(c_q(m,n,:,:),[1 2])-reshape(c_q(j,n,:,:),[1 2])) >= d_min^2;
        end
    end
end
0 <= a <= 1; %C21

cvx_end

M

You need to use expression holders http://cvxr.com/cvx/doc/basics.html#assignment-and-expression-holders

However, I believe there are other very serious issues you will encounter after fixing that.

M

Re: those other, perhaps unrepairable, issues, please carefully read

You will need to revector your thinking regarding use of CVX.

H
Replying to #3

Thanks for the reply…

Are you saying that my formulation is not convex? Or is the issue with syntax /DCP standards?

I removed the steps to calculate D1,D2, A, C for brevity

M

A quick glance appears to show massive CVX rules violations of the non-convexity variety. i haven’t looked into whether the problem is actually (can be reformulated as) convex, which I leave to you, per the previously-linked FAQ.