How do I solve this convex problem

Hi all!
I am a first timer at the CVX community. I am just a novice who has begun trying to understand CVX. I am currently working on a minor project which includes a convex problem,

F(z) ≜   max┬Q_k⁡∑_k▒γ_k g_k’ Q_k g_k
s.t. Q_k is positive semidefinite and Tr(Q_k)≤1

I tried solving it this way

N=5;
h0=0.24+0.78i;
g0=1.12-1.15i;
H0=(abs(h0))^2;
G0=(abs(g0))^2;
Hk=[0.76-0.64i -0.10-0.84i;-1.077+1.15i -0.96-0.18i;0.28+0.09i -0.03-0.65i;0.55+0.69i -0.03+0.23i;0.39+0.01i -0.82+0.27i];% Channel from helper k to Bob
Gk=[0.22-0.03i 0.88+0.15i;-0.165-0.29i 0.24+0.77i;1.10-0.47i 0.77+0.27i;0.33+0.79i 0.20-0.24i;0.88-0.05i 0.52-0.50i];% Channel from helper k to Eve
SNR_00=5;
snr_00=10^(SNR_00/10);
SNR_k=2;;
snr_k=10^(SNR_k/10);
     
cvx_begin
variable Qk(Nk,Nk)
Fz=0;

    for k=1:N
        x2=snr_k*Gk(k,:)*Qk*Gk(k,:)';
        Fz=Fz+x2;
    end

maximize Fz
subject to
trace(Qk)<=1
Qk==semidefinite(Nk)
cvx_end

I’m not sure if it is the proper way to write the CVX code. There are a few errors in the program and I cannot figure out where i went wrong. It would be great if anyone could help me with this problem. Thanks.

Is Qk just a single matrix variable independent of any value of k? Perhaps there is a display issue here, but are the dimensions of Qk, Nk by Nk for some Nk which you haven’t defined, or is that Nk by Nk, but your only definition of k is as the index of a for loop after Qk is declared as a variable, which doesn’t make sense and makes the dimensions incompatible? Based on your x2 expression, it appears that Qk needs to be 2 by 2 (2 being the number of columns in Gk). You don’t seem to use Hk at all. It might be a good idea to declare Fz as an expression, although I don’t think it’s necessary, and you could also declare x2 as an expression, or just change x2= to Fz=Fz+ .

So get straight on how many Qk’s there are, and make sure that the dimensions in your variable declaration evaluate to numerical values at the time of declaration.

Your objective function needs to evaluate to a (scalar) real, not complex as currently (given the complex entries in Gk). I’ll leave it to you to determine the correct definition of objective function for your intended use. I will also leave it to you whether Qk will need to be declared complex, depending on how you wind up defining the objective function.

I guess there was a display issue here. Actually, I’m not sure how to include a mathematical equation in a post. I’ll repost my problem here.

Fz≜max ∑_k γ_k g_k’ Q_k g_k ; k=1,2...N
s.t. Q_k is positive semidefinite and Tr(Q_k)≤1

Qk is of size Nk by Nk and Nk=2. I must have missed it out when I posted the code. I need an optimal Qk for each value of k which is used further in the equation,

z=∑_k γ_k h_k’ Q_k h_k ; k=1,2...N

I need the objective function to be real. Will Fz be scalar if Qk is declared complex? Also I’m not sure where I should declare Qk. Is it inside the loop, before or after?

Fz is not going to be real unless you make it so. I don’t know what your objective function is supposed to be, so you need to figure that out, and it needs to evaluate to a real (scalar). With your current value of G_k, it is not. So that’s step one, regardless of what optimization software or modeling environment you’re using.

As currently defined, you are essentially solving N independent (i.e., non-coupled) optimization problems So these could as well be solved separately. I’ll leave it to you to determine whether you actually intend there to be no coupling across the N summand terms of the objective function. Nevertheless, by adding an extra dimension to the declaration of Qk, you can solve all of them at once by essentially stacking them together as you are doing by summing the objective over k from 1 to N. See Creating Dynamic Variables with Constraints (avoid for loop) for how to declare Qk and making all N of its constituent Nk by Nk matrices semidefinite. If you take this approach, you need to declare Qk before the for loop. You also need to specify the trace constraint for each of the N 2 by 2 constituent matrices, and you may be done.

I’ll check out the link and will try it out again including your suggestions. Thanks so much for all your help.