# LMI formulation using Yalmip vs CVX

Hi, I am trying to use cvx instead of Yalmip for solving my LMI problem. I have my opt problem formulated in yalmip as follows:

``````X = sdpvar(n,n);
L = sdpvar(1,n,'full' );

mat = [X [A*X - B*L;L;X]';[A*X - B*L;L;X] blkdiag(X,inv(R),inv(Qx))]
optimize(mat >= 0, -trace(X))

K_f = value(L)*inv(value(X))
``````

However, when I code it in cvx the K_cvx obtained is not the same as K_f.

``````cvx_begin
variable X(n,n)
variable L(1,n)
minimize (-trace(X))
subject to
[X [A*X-B*L ; L; X]';[A*X-B*L ; L; X] blkdiag(X,inv(R),inv(Qx))] >= 0
cvx_end
K_cvx = L*inv(X)
``````

The code is quite simple, so I guess they are equivalent, but there is something wrong. Do you have any hints?

1 Like

Presuming `inv(R)` and `inv(Qx)` are symmetric, the constraint in YALMIP is an LMI (SDP).

However, you have specified an elementwise nonnegativity constraint in CVX.

1. Square matrix variables in YALMIP are symmetric by default. They are not in CVX.
FIx: `variable X(n,n) symmetric`

2. YALMIP is essentially always in what is called sdp mode in CVX. But CVX by default is not.:
FIx: `cvx_begin sdp`
or instead of sdp mode, use
`LHS == semidefinite(matrix dimension being constrained)`

`variable X(n,n,N) symmetric`
declares that `X(:,:,k)` is symmetric for each value of k.