lqr (MathScript RT Module Function)
- Updated2023-03-14
- 2 minute(s) read
lqr (MathScript RT Module Function)
Owning Class: ssdesign
Requires: Control Design and Simulation Module and MathScript RT Module
Syntax
[K, X, eig] = lqr(A, B, Q, R)
[K, X, eig] = lqr(A, B, Q, R, N)
[K, X, eig] = lqr(SysInSS, B, Q, R)
[K, X, eig] = lqr(SysInSS, B, Q, R, N)
Description
Calculates the optimal steady-state feedback gain matrix K that minimizes a quadratic cost function for a linear discrete state-space system model. The cost function weights the model states. The quadratic cost function J is defined as the following equation:
integral(x'(t)Qx(t) + u(t)' Ru(t) + 2x(t)'Nu(t), t, 0, +inf), where t is continuous time, u is the input vector, and x is the state vector.
Inputs
| Name | Description |
|---|---|
| SysInSS | Specifies a linear time-invariant (LTI) model in state-space form. |
| A | Specifies an n x n state matrix, where n is the number of states. The default is an empty matrix. A is a real matrix. |
| B | Specifies an n x m input matrix, where m is the number of inputs. The default is an empty matrix. B is a real matrix. |
| Q | Specifies a symmetric, positive semi-definite matrix that penalizes the state vector x in the cost function. Q is a real matrix. |
| R | Specifies a symmetric positive definite matrix that penalizes the input vector u in the cost function. The default is the identity matrix. R is a real matrix. |
| N | Specifies a matrix that penalizes the cross product between input and state vectors, such that (Q - N*inv(R)*N') is positive semi-definite. The default is an appropriately sized matrix of zeros. N is a real matrix. |
Outputs
| Name | Description |
|---|---|
| K | Returns the gain matrix such that K = inv(R)*(B'X + N'). K is a real matrix. |
| X | Returns the symmetric, positive semi-definite (stabilizing) solution to the discrete algebraic Riccati equation. X is a real matrix. |
| eig | Returns the eigenvalues of the matrix (A - BK). These eigenvalues are the closed-loop pole locations. eig is a complex vector. |
Details
The following table lists the support characteristics of this function.
| Supported in the LabVIEW Run-Time Engine | Yes |
| Supported on RT targets | Yes |
| Suitable for bounded execution times on RT | Not characterized |
Examples
A = [-1, -2; 0, -4]
B = [0; 1]
Q = [2, 0; 0, 2]
R = 1
[K, X, eig] = lqr(A, B, Q, R)