Hi there, I am running cvx but I run into this error.

Error using + (line 45)

Matrix dimensions must agree.

Error in multi_power (line 14)

(1/N)*sum(sum(a(k,:,:).*(log(sum(P_crl.*h(k,:,:), 3) + sigma_2)/log(2) - (D(k,:,:).*(P_crl - P) + log(E(k,:,:))/log(2))), 3), 2) >= eta_pow;

My code is as follows:

function [result,output] = multi_power(P, K, N, M, P_max, a, h, sigma_2, D, E)

cvx_begin quiet

variables P_crl(1,N,M)

variable eta_pow

maximize eta_pow

subject to

for m = 1:M

for n = 1:N

0 <= P_crl(1,n,m) <= P_max;

end

end

```
for k = 1:K
(1/N)*sum(sum(a(k,:,:).*(log(sum(P_crl.*h(k,:,:), 3) + sigma_2)/log(2) - (D(k,:,:).*(P_crl - P) + log(E(k,:,:))/log(2))), 3), 2) >= eta_pow;
end
cvx_end
result = cvx_optval;
output = P_crl;
```

end

In this part, variables a, h, D, E are of dimension (K,N,M), P is of dimension (1,N,M). And sigma_2 and P_max are just a number. I have no idea why it keeps telling me dimension error. Any help is greatly appreciated! Thanks!

Another thing that confuses me is that when I replace the variable P_crl with a known P, which should be of the same size, the equation will show no error. It means the LHS of Line 14 can have a certain value if I use P instead. But P_crl and P should be of the same dimension so I really have no idea why it doesn’t work when I try to use P_crl.