Illegal operation: sqrt( {complex affine}

I try to solve this problem:
image
whileimage
only relevant to the Pe of the previous iteration .
image
This is my code
function [Pe,deta_a]= cvx_Pe(h_ae2,h_ae1,h_ak1,z_all,Pe,A,Pth,E,deta_a)
F_az=zeros(1,A);
f_a1=zeros(1,A);
F_ae=zeros(E,A);
f_ae=zeros(E,A);
for a=1:A
F_az(1,a)=abs(h_ae2(:,:,a,1)’*(h_ak1(:,:,a,1)+z_all(:,:,a,1))).^2;
f_a1(1,a)=norm(h_ak1(:,:,a,1)+z_all(:,:,a,1));
end
for a=1:A
for e= 1:E
F_ae(e,a)=abs(h_ae2(:,:,a,1)’*h_ae1(:,:,a,e)).^2;
f_ae(e,a)=norm(h_ae1(:,:,a,e));
end
end
temp_detas=F_az;
temp_detax=f_a1;
for a=1:A
temp_detas(1,a)=temp_detas(1,a)+Pe(:,1)’*f_ae(:,a);
temp_detax(1,a)=temp_detax(1,a)+Pe(:,1)’*f_ae(:,a);
end

subject to
cvx_begin quiet
cvx_precision low

variable Pe(E,1) complex;
minimize (sum(2*deta_a*sqrt(F_az+Pe'*F_ae)-deta_a*(f_a1+Pe'*f_ae)))
subject to
   sum(Pe)<=Pth;

cvx_end
deta_a=temp_detas./temp_detax;
end

Looking at “illegal opera…” of your output, the error is clear: Pe is complex, so sqrt(F_az+Pe'*F_ae) is complex too, you can’t minimize a complex thing.

Oh,I see! Because of the language, I confuse “complex/complexity” and “plural”.I got it wrong,Pe is a real number, the problem is solved,thanks

Besides that, I would like to ask if the code of the objective function is correct?
image
F_az,F_ae et.al represents real numbers in formulas, but vectors in code. If not in CVX, I usually solve it with loops and overlays. The error says ‘‘Inner matrix dimensions must agree’’. Although I’m checking other places, I’m not sure if there is an error here

The objective function code is
maximize (sum(2deta_asqrt(F_az+Pe’F_ae)-deta_a(f_a1+Pe’*f_ae)))

Most of the time CVX is unlikely to cause a dimension issue, please check your code.

1 Like