# lqry

Calculates the optimal steady-state feedback gain matrix K.

## Syntax

[K, X, E] = lqry(SYS, Q, R)

[K, X, E] = lqry(SYS, Q, R, N)

[K, X, E] = lqry(A, B, C, D, Q, R)

[K, X, E] = lqry(A, B, C, D, Q, R, N)

## Inputs

SYS
A continuous or discrete-time linear time-invariant model.
Q
The output weighting matrix (q x q), where q is the number of outputs.
R
The input weighting matrix (p x p), where p is the number of inputs.
N
The output/state cross product weighting matrix, such that (Q-N*inv(R)*N') is positive semi-definite.
A
The state matrix (n x n), where n is the number of states.
B
The input matrix (n x p), where p is the number of inputs.
C
The output matrix (q x n), where q is the number of outputs.
D
The direct transmission matrix (q x p).

## Outputs

K
The gain matrix. K = inv(R)*(B'X+N').
X
The symmetric, positive semi-definite solution to the Discrete Algebraic Riccati Equation.
E
The closed-loop pole locations; the eigenvalues of the matrix A-BK.

## Examples

Gain matrix obtained from the state-space model:
A = [0.9, 0.25; 0, 0.8];
B = [0; 1];
C = [1, 0];
D = 0;
sys = ss(A, B, C, D);
Q = 2;
R = 1;

[K, X, e] = lqry(sys, Q, R)
K = [Matrix] 1 x 2
12.73999  3.44764
X = [Matrix] 2 x 2
89.05966  12.73999
12.73999   3.44764
e = [Matrix] 2 x 1
-0.87382 + 0.19637i
-0.87382 - 0.19637i
Gain matrix obtained from the transfer function model:
sys_tf=tf([1],[1 6 1]);
sys=ss(sys_tf);
Q = 2;
R = 1;
[K, X, e] = lqry(sys.a, sys.b, sys.c, sys.d, Q, R)
K = [Matrix] 1 x 2
0.12079  0.73205
X = [Matrix] 2 x 2
0.12079  0.73205
0.73205  4.60152
e = [Matrix] 2 x 1
-5.82336
-0.29743