# How to modify the error when the window sow me Invalid constraint: {complex affine} >= {real affine}

I want to write a code about optimal,so i use cvx in matlab,the picture below is what i want to write

`````` %declare
K=4;
N=4;
nois_var_ak_2pow=[10^-10 10^-10 10^-10 10^-10 ];
nois_var_dk_2pow=[10^-8 10^-8 10^-8 10^-8 ];
bar_r=[10 10 10 10];
P_hat=0.00001;
P_T=10;
h_1=sqrt(1/2)*(randn(N,1)+1i*randn(N,1));
h_2=sqrt(1/2)*(randn(N,1)+1i*randn(N,1));
h_3=sqrt(1/2)*(randn(N,1)+1i*randn(N,1));
h_4=sqrt(1/2)*(randn(N,1)+1i*randn(N,1));
h_kk=cat(2,h_1 ,h_2 ,h_3, h_4)
for n=1:4
h_k{n}=h_kk(1:4 , n);
n=n+1;
end
%===========================================================
cvx_begin
variable FNNK(N,N,K) semidefinite; %c7
variable P ;
Fkk=cat(2,FNNK);

u=0
for o=1:4
Fk{o}=Fkk(1:4,o+3*u:4*o)
u=u+1;
end
%====================================
%object function
minimize( P )
subject to
%====================================
%C6
tr_Fk=0;
for k=1:K
t=trace(Fk{k});
tr_Fk=tr_Fk+t;
end
tr_Fk<=P_T;
%====================================
%c9
total = 0;
for k = 1:K
sumja = 0;
for j = 1:K
if j ~= k
sumja = sumja +  h_k{k}' * Fk{j} * h_k{k};
end
end
total = total + sumja+ nois_var_ak_2pow(1);
end

abs(total) >= P
cvx_end
``````

However,after running the code,the window show me some error in this line total >= P

total >= P : Invalid constraint: {complex affine} >= {real affine}

so i modify it as below

abs(total) >= P,but the window show me :Invalid constraint: {convex} >= {real affine}

I don’t know how to modify it,can anyone help me?because the constraint does write the total in the code has to be larger than P

I think the problem is due to fussiness of CVX concerning roundoff level imaginary term in
`h_k{k}' * Fk{j} * h_k{k}` .

So use
`real(total) >= P`

However, your problem is unbounded.

from where you know my problem is unbounded?

I ran it with both SDPT3 and SewDuMi after making the change I suggested.

well,i don’t understand your meaning very much.after running it,like you said,it is unbound,what should i add to let the problem become bounded?

My cvx file has both SDPT3 and SeDuMi,but i don’t know how to run the code with SDPT3 and SeDuMi.Now i just press F5 to let matlab simulate this code.Can you teach me how to use SDPT3 and SeDuMi ?

Your program has `minimize(P)` . Of course, P = -infinity is optimal for that objective, hence it is unbounded.

The figure shows `maximize(P).` That results in optimal P = 2.

thankyou,but my optimal value is at least 50,why are our results so different? i have modified it to maximize§

I made a copy and paste error. The optimal objective value is 97.1452.

ok but it is weird ,my power budget is only 10,so the optimal P should be less or equal than 10.

That is a modeling matter for you to resolve. You can verify that the optimal solution returned by solver/CVX satisfies the constraints. So if this “should not” be possible, you need to reevaluate your model and input data.