LQR controller design using LMI approach

I am trying here to design an LQR controller using LMI method, the result obtained from cvx is very different from results obtained using matlab lqr built-in function! surely there are error affecting the results.
Any suggestions are appreciated. thanks in advance

check the attached code

When I try to solve the problem in cvx, I receive the following warning messages:

Warning: The use of strict inequalities in CVX is strongly discouraged,
because solvers treat them as non-strict inequalities. Please
consider using “>=” instead.

> In cvx.gt at 21 
Warning: This linear matrix inequality appears to be unsymmetric. This is
very likely an error that will produce unexpected results. Please check
the LMI; and, if necessary, re-enter the model. 
> In cvxprob.newcnstr at 241
  In cvx.gt at 22 
Warning: The use of strict inequalities in CVX is strongly discouraged,
    because solvers treat them as non-strict inequalities. Please
    consider using ">=" instead.

The code is:

A=[-30*10^3 376.8 -671 0 0; -376.8 -30*10^3 0 0 0; 2013 0 0 0 0; 0 1 0 0 0; 0 0 1 0 0];
B=[-200*10^3 0; 0 -200*10^3; 0 0; 0 0; 0 0];
Q=[10 0 0 0 0; 0 10 0 0 0; 0 0 10^3 0 0; 0 0 0 10^3 0; 0 0 0 0 10^5];
R=[1 0; 0 1];
cvx_begin sdp
variables P(5,5) Y(2,5) X(2,2)
minimize (trace(Q*P)+trace(X))
subject to
A*P+P*transpose(A)+(B*Y)+(transpose(Y)*transpose(B))+eye(5)>0;
P>0;
[X R*Y; transpose(Y)*R P]>0;
cvx_end
K=Y*inv(P);

First of all: you need to declare P to be symmetric; and you may need to wrap your Ricatti equation in a sym() function to ensure it is numerically symmetric as well. Roundoff error can sometimes prevent an apparently symmetric construct from being exactly so.

And secondly you are going to have to figure out how to eliminate at least some of the strict inequalities; otherwise, the zero solution is valid. Read more here.

Dear mcg

Thanks very much for your response. After I modified the code as shown below, The results has improved quite significantly, (almost matching the Matlab LQR built-in function results), thought I still receive the warning message:

Warning: This linear matrix inequality appears to be unsymmetric. This is
very likely an error that will produce unexpected results. Please check
the LMI; and, if necessary, re-enter the model.

In cvxprob.newcnstr at 241
In cvx.ge at 21

The modified code:

 A=[-30*10^3 376.8 -671 0 0; -376.8 -30*10^3 0 0 0; 2013 0 0 0 0; 0 1 0 0 0; 0 0 1 0 0];
B=[-200*10^3 0; 0 -200*10^3; 0 0; 0 0; 0 0];
Q=[10 0 0 0 0; 0 10 0 0 0; 0 0 10^3 0 0; 0 0 0 10^3 0; 0 0 0 0 10^5];
R=[1 0; 0 1];
cvx_begin sdp
variable P(5,5) symmetric
variables Y(2,5) X(2,2)
minimize (trace(Q*P)+trace(X))
subject to
A*P+P*transpose(A)+(B*Y)+(transpose(Y)*transpose(B))+eye(5)<= (1e-10)*-eye(5);
P>=(1e-10)*eye(5);
[X R*Y; transpose(Y)*R P]>=(1e-10)*eye(7);
cvx_end
K=Y*inv(P)

The results obtained from the code above:
3.1143 0.0001 31.6307 -0.0182 316.1780
0.0000 3.0130 0.0181 31.5938 0.1813

The result obtained from the Matlab
-3.1149 -0.0001 -31.6356 0.0182 -316.2277
-0.0001 -3.0159 -0.0183 -31.6228 -0.1824

The difference in “negative” sign is due to I am assuming u=Kx while Matlab LQR assumes u=-Kx

You did not use sym as I instructed. I’m glad you’re getting close results. Still, the remaining differences are likely due to your use of 1e-10 to shift the inequalities. That number is “small” as far as the solvers are concerned.

Dear Sir I still don’t understand where to use “sym” !. Do you mean adding it to the constraint ? you mentioned in your previous answer that I have to “wrap your Ricatti equation in a sym()”, but I don’t use Riccati equation to design the LQR,I am posing the LQR problem as LMI optimization problem.

check this paper by S. Boyd et al: https://web.stanford.edu/~boyd/papers/pdf/h2.pdf

sym() takes the symmetric part of an expression. Use it anywhere you expect a symmetric matrix but, due to roundoff error, you might not have it. For instance: sym(A*P+P*transpose(A))