```
clc,clear;
close all;
N=2;
delta=rand(1);
h=rand(N,1)+1i*rand(N,1);
cvx_begin
variable W(N,N) hermitian semidefinite
variables eta a b
minimize (real(trace(W)))
subject to
A=[eye(N),zeros(N,1);
zeros(1,N), -delta^2];
% B=[-W,-W*h;
% -h'*W,square_pos(norm(a))/2+square_pos(norm(b))/2-h'*W*h];
B=[-W,-W*h;
-h'*W,a*a/2+b*b/2-h'*W*h];
eta*A-B==hermitian_semidefinite(N+1)
cvx_end
```

The error is because the matrix constrained to be `hermitian_semidefinite`

is not linear (affine) in he CVX variables. Specifically, `a*a`

and `b*b`

.

Change the program to declare variables `a_squared b_squared`

, because the SDP constraint is linear (affine) in those variables.

```
cvx_begin
variable W(N,N) hermitian semidefinite
variables eta a_squared b_squared
minimize (real(trace(W)))
subject to
A=[eye(N),zeros(N,1);
zeros(1,N), -delta^2];
B=[-W,-W*h;
-h'*W,a_squared/2+b_squared/2-h'*W*h];
eta*A-B==hermitian_semidefinite(N+1)
cvx_end
```

**Edit**: Inserted missing `/2`

after `b_squared`

.

thank you, but the change the variables a to a_squared can not guarantee the equivalence, can you help me?

I don’t understand why my formulation is not adequate for you. My formulation is “equivalent”: to your formulation. But unlike your formulation, it is a linear SDP, compliant with CVX’s rules.

The well known “trick” I used (it is so simple and obvious, it is not much of a trick) is very standard for linear SDP (LMI). It works provided there is no separate need for the unsquared original variables `a`

and `b`

elsewhere in the problem formulation.

If you need the values of `a`

and `b`

, place these statements after `cvx_end`

.

```
a = sqrt(a_squared);
b = sqrt(b_squared);
```

Or you could just as well insert `-`

before `sqrt`

.

Note that I ignored the commented out version of `B`

in your program.

ok， i have got it, thank you very much.