ControlDesign

 LQR
 design linear quadratic state feedback regulator (LQR) for a given state-space system

 Calling Sequence LQR(sys, Q, R, opts)

Parameters

 sys - System; system object Q - Matrix; state weighting matrix R - Matrix; input weighting matrix opts - (optional) equation(s) of the form option = value; specify options for the LQR command

Options

 • N = Matrix or Vector
 Weighting on the state-input multiplication term in the cost function. If omitted, a zero matrix with appropriate dimensions will be considered.
 • poles = true or false
 True means the eigenvalues of A-BK are returned. The default value is false.
 • riccati = true or false
 True means the solution of the associated Riccati equation is returned.

For a continuous system, the infinite horizon solution of the following continuous-time Riccati equation (CARE) is returned.

${A}^{T}X+\mathrm{XA}-\left(\mathrm{XB}+N\right){R}^{-1}{\left(\mathrm{XB}+N\right)}^{T}+Q=0$

The LQR feedback gain is calculated as

$K={R}^{-1}{\left(\mathrm{XB}+N\right)}^{T}$

For a discrete system, the infinite horizon solution of the following discrete-time Riccati equation (DARE) is returned

${A}^{T}\mathrm{XA}-X-\left({A}^{T}\mathrm{XB}+N\right){\left({B}^{T}\mathrm{XB}+R\right)}^{-1}\left({B}^{T}\mathrm{XA}+{N}^{T}\right)+Q=0$

The LQR feedback gain is calculated as

$K={\left({B}^{T}\mathrm{XB}+R\right)}^{-1}\left({B}^{T}\mathrm{XA}+{N}^{T}\right)$

The default value is false.

 • return_Kr = true or false
 True means the direct gain Kr is returned. The default value is false.
 • parameters = {list, set}(name = complexcons)
 Specifies numeric values for the parameters of sys. These values override any parameters previously specified for sys. The numeric value on the right-hand side of each equation is substituted for the name on the left-hand side in the sys equations. The default is the value of sys given by DynamicSystems:-SystemOptions(parameters).

Solvability Conditions

 • The pair $\left(A,B\right)$ must be stabilizable.
 • The pair $\left(Q-N{R}^{-1}{N}^{T},A-B{R}^{-1}{N}^{T}\right)$ must have no unobservable modes on the imaginary axis in continuous-time domain or on the unit circle in discrete-time domain.
 • $R>0$ (positive definite) and $Q-N{R}^{-1}{N}^{T}\ge 0$ (positive semidefinite).

Description

 • The LQR command calculates the LQR state feedback gain for a system.
 • The system sys is a continuous or discrete time linear system object created using the DynamicSystems package. The system object must be in state-space (SS) form. The state-space system can be either single-input/single-output (SISO) or multiple-input/multiple-output (MIMO).
 • In continuous time, the optimal state feedback gain, $K$, is calculated such that the quadratic cost function

$J\left(u\right)={\int }_{0}^{\infty }\left({x}^{T}\mathrm{Qx}+{u}^{T}\mathrm{Ru}+2{x}^{T}\mathrm{Νu}\right)ⅆt$

is minimized by the feedback law u = -Kx subject to the system dynamics

$\stackrel{·}{x}=\mathrm{Ax}+\mathrm{Bu}$

 • In discrete time, the optimal state feedback gain, $K$, is calculated such that the quadratic cost function

$J\left(u\right)=\sum _{n=0}^{\infty }\left({x}^{T}\mathrm{Qx}+{u}^{T}\mathrm{Ru}+2{x}^{T}\mathrm{Νu}\right)$

is minimized by the feedback law u[n] = -Kx[n] subject to the system dynamics

$x\left[n+1\right]=\mathrm{Ax}\left[n\right]+\mathrm{Bu}\left[n\right]$

 • Q and R are expected to be symmetric. If the input Q and/or R are not symmetric, their symmetric part will be considered since their antisymmetric (skew-symmetric) part has no role in the quadratic cost function.
 • In addition to the state feedback gain, depending on the corresponding option values, the command also returns the closed-loop eigenvalues and the solution of the associated Riccati equation.
 • The direct gain $\mathrm{Kr}$ is computed as follows:

$\left(C-\mathrm{D}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}.\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}K\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}.\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\left(\frac{1}{-A+B\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}.\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}K}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}.\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}B+\mathrm{D}$ (continuous time)

$\left(C-\mathrm{D}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}.\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}K\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}.\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\left(\frac{1}{-A+I+B\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}.\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}K}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}.\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}B+\mathrm{D}$ (discrete time)

 • If sys contains structured uncontrollable states, they are removed before computing the LQR state feedback. The resulting gain $K$ is then filled with zeros at positions corresponding to the removed states; however, the other outputs are not filled and, consequently, they may have lower dimensions as expected.

Examples

 > $\mathrm{with}\left(\mathrm{ControlDesign}\right):$
 > $\mathrm{with}\left(\mathrm{DynamicSystems}\right):$
 > $\mathrm{csys}≔\mathrm{NewSystem}\left(\mathrm{Matrix}\left(\left[\left[\frac{2}{{s}^{2}+3s+1},\frac{1}{s+2}\right],\left[\frac{s-1}{{s}^{2}+5},\frac{7}{\left(s+1\right)\left(s+4\right)}\right]\right]\right)\right):$
 > $\mathrm{csys}:-\mathrm{tf}$
 $\left[\begin{array}{cc}\frac{{2}}{{{s}}^{{2}}{+}{3}{}{s}{+}{1}}& \frac{{1}}{{s}{+}{2}}\\ \frac{{s}{-}{1}}{{{s}}^{{2}}{+}{5}}& \frac{{7}}{{{s}}^{{2}}{+}{5}{}{s}{+}{4}}\end{array}\right]$ (1)
 > $\mathrm{sys}≔\mathrm{StateSpace}\left(\mathrm{csys}\right):$
 > $\mathrm{sys}:-a;$$\mathrm{sys}:-b;$$\mathrm{sys}:-c;$$\mathrm{sys}:-d$
 $\left[\begin{array}{rrrrrrr}{0}& {1}& {0}& {0}& {0}& {0}& {0}\\ {0}& {0}& {1}& {0}& {0}& {0}& {0}\\ {0}& {0}& {0}& {1}& {0}& {0}& {0}\\ {-}{5}& {-}{15}& {-}{6}& {-}{3}& {0}& {0}& {0}\\ {0}& {0}& {0}& {0}& {0}& {1}& {0}\\ {0}& {0}& {0}& {0}& {0}& {0}& {1}\\ {0}& {0}& {0}& {0}& {-}{8}& {-}{14}& {-}{7}\end{array}\right]$
 $\left[\begin{array}{rr}{0}& {0}\\ {0}& {0}\\ {0}& {0}\\ {1}& {0}\\ {0}& {0}\\ {0}& {0}\\ {0}& {1}\end{array}\right]$
 $\left[\begin{array}{rrrrrrr}{10}& {0}& {2}& {0}& {4}& {5}& {1}\\ {-}{1}& {-}{2}& {2}& {1}& {14}& {7}& {0}\end{array}\right]$
 $\left[\begin{array}{rr}{0}& {0}\\ {0}& {0}\end{array}\right]$ (2)
 > $Q≔\frac{1\mathrm{LinearAlgebra}:-\mathrm{IdentityMatrix}\left(7\right)}{3};$$R≔2\mathrm{LinearAlgebra}:-\mathrm{IdentityMatrix}\left(2\right)$
 ${Q}{:=}\left[\begin{array}{ccccccc}\frac{{1}}{{3}}& {0}& {0}& {0}& {0}& {0}& {0}\\ {0}& \frac{{1}}{{3}}& {0}& {0}& {0}& {0}& {0}\\ {0}& {0}& \frac{{1}}{{3}}& {0}& {0}& {0}& {0}\\ {0}& {0}& {0}& \frac{{1}}{{3}}& {0}& {0}& {0}\\ {0}& {0}& {0}& {0}& \frac{{1}}{{3}}& {0}& {0}\\ {0}& {0}& {0}& {0}& {0}& \frac{{1}}{{3}}& {0}\\ {0}& {0}& {0}& {0}& {0}& {0}& \frac{{1}}{{3}}\end{array}\right]$
 ${R}{:=}\left[\begin{array}{rr}{2}& {0}\\ {0}& {2}\end{array}\right]$ (3)
 > $K≔\mathrm{LQR}\left(\mathrm{sys},Q,R\right)$
 ${K}{:=}\left[\begin{array}{ccccccc}{0.0166389810974705}& {0.299443675955044}& {0.867776452191478}& {0.301850931076329}& {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}& {0.}& {0.0104098937986105}& {0.0195439507289429}& {0.0146813589873455}\end{array}\right]$ (4)
 > $\mathrm{Kpr}≔\mathrm{LQR}\left(\mathrm{sys},Q,R,'\mathrm{poles}'=\mathrm{true},'\mathrm{riccati}'=\mathrm{true},'\mathrm{return_Kr}'=\mathrm{true}\right):$${\mathrm{Kpr}}_{1};$${\mathrm{Kpr}}_{2};$${\mathrm{Kpr}}_{3};$${\mathrm{Kpr}}_{4}$
 $\left[\begin{array}{ccccccc}{0.0166389810974705}& {0.299443675955044}& {0.867776452191478}& {0.301850931076329}& {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}& {0.}& {0.0104098937986105}& {0.0195439507289429}& {0.0146813589873455}\end{array}\right]$
 $\left[\begin{array}{c}{-}{2.62756665299744}{+}{0.}{}{I}\\ {-}{0.145624709217511}{+}{2.22784297750641}{}{I}\\ {-}{0.145624709217511}{-}{2.22784297750641}{}{I}\\ {-}{0.383034859643869}{+}{0.}{}{I}\\ {-}{1.00185981437603}{+}{0.}{}{I}\\ {-}{1.98515367555330}{+}{0.}{}{I}\\ {-}{4.02766786905801}{+}{0.}{}{I}\end{array}\right]$
 $\left[\begin{array}{ccccccc}{3.5035710678024963642735698334738086970173092871078}& {8.9063101270541111531167581075671803104947792461458}& {3.1283881812209808268605882029451459276062782436105}& {0.033277962194940937420660323652668921352991539626009}& {0.}& {0.}& {0.}\\ {8.9063101270541111531167581075671803104947792461458}& {27.017929837486759850611800937425078242698100086181}& {10.999686730609094484906069375902437265430236365035}& {0.59888735191008724334359278295378054778377357379270}& {0.}& {0.}& {0.}\\ {3.1283881812209808268605882029451459276062782436105}& {10.999686730609094484906069375902437265430236365035}& {8.7538607942749524452688978919514869492958202135138}& {1.7355529043829555120085717535997438572353549848779}& {0.}& {0.}& {0.}\\ {0.033277962194940937420660323652668921352991539626009}& {0.59888735191008724334359278295378054778377357379270}& {1.7355529043829555120085717535997438572353549848779}& {0.60370186215265844164465469332087994051094168275939}& {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}& {0.}& {0.60458713892716850967689842079379231322521721813087}& {0.38094591975383059966396461879896053218176570663419}& {0.020819787597221039613645137137870970189590359262787}\\ {0.}& {0.}& {0.}& {0.}& {0.38094591975383059966396461879896053218176570663419}& {0.66444743776701954149815236150708781014928590795157}& {0.039087901457885851258326665942712298638987275213164}\\ {0.}& {0.}& {0.}& {0.}& {0.020819787597221039613645137137870970189590359262787}& {0.039087901457885851258326665942712298638987275213164}& {0.029362717974691029572229097828269653238134822396934}\end{array}\right]$
 $\left[\begin{array}{cc}{0.487728789828921}& {-}{0.139351082808263}\\ {0.0556278464847126}& {0.556278464847126}\end{array}\right]$ (5)

We can also use LQR with discrete models:

 > $\mathrm{dsys}≔\mathrm{ToDiscrete}\left(\mathrm{csys},1,'\mathrm{method}'=\mathrm{bilinear}\right)$
 ${\mathrm{dsys}}{:=}\left[\begin{array}{c}{\mathbf{Transfer Function}}\\ {\mathrm{discrete; sampletime = 1}}\\ {\mathrm{2 output\left(s\right); 2 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({z}\right){,}{\mathrm{u2}}{}\left({z}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({z}\right){,}{\mathrm{y2}}{}\left({z}\right)\right]\end{array}\right$ (6)
 > $\mathrm{sys}≔\mathrm{StateSpace}\left(\mathrm{dsys}\right)$
 ${\mathrm{sys}}{:=}\left[\begin{array}{c}{\mathbf{State Space}}\\ {\mathrm{discrete; sampletime = 1}}\\ {\mathrm{2 output\left(s\right); 2 input\left(s\right); 7 state\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({q}\right){,}{\mathrm{u2}}{}\left({q}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({q}\right){,}{\mathrm{y2}}{}\left({q}\right)\right]\\ {\mathrm{statevariable}}{=}\left[{\mathrm{x1}}{}\left({q}\right){,}{\mathrm{x2}}{}\left({q}\right){,}{\mathrm{x3}}{}\left({q}\right){,}{\mathrm{x4}}{}\left({q}\right){,}{\mathrm{x5}}{}\left({q}\right){,}{\mathrm{x6}}{}\left({q}\right){,}{\mathrm{x7}}{}\left({q}\right)\right]\end{array}\right$ (7)
 > $K≔\mathrm{LQR}\left(\mathrm{sys},Q,R\right)$
 ${K}{:=}\left[\begin{array}{ccccccc}{0.0481202313599143}& {0.301603484287272}& {-}{0.420834895345035}& {0.0511514301656090}& {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}& {0.}& {0.}& {0.0372408140701274}& {-}{9.76066563662570}{}{{10}}^{{-51}}\end{array}\right]$ (8)
 > $\mathrm{Kpr}≔\mathrm{LQR}\left(\mathrm{sys},Q,R,'\mathrm{poles}'=\mathrm{true},'\mathrm{riccati}'=\mathrm{true},'\mathrm{return_Kr}'=\mathrm{true}\right):$${\mathrm{Kpr}}_{1};$${\mathrm{Kpr}}_{2};$${\mathrm{Kpr}}_{3};$${\mathrm{Kpr}}_{4}$
 $\left[\begin{array}{ccccccc}{0.0481202313599143}& {0.301603484287272}& {-}{0.420834895345035}& {0.0511514301656090}& {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}& {0.}& {0.}& {0.0372408140701274}& {-}{9.76066563662570}{}{{10}}^{{-51}}\end{array}\right]$
 $\left[\begin{array}{c}{-}{0.0959924471365447}{+}{0.725780367567049}{}{I}\\ {-}{0.0959924471365447}{-}{0.725780367567049}{}{I}\\ {0.597646681582207}{+}{0.}{}{I}\\ {-}{0.133580894274726}{+}{0.}{}{I}\\ {0.}{+}{0.}{}{I}\\ {-}{0.271790906819696}{+}{0.}{}{I}\\ {0.271790906819696}{+}{0.}{}{I}\end{array}\right]$
 $\left[\begin{array}{ccccccc}{0.34208246630795069777141693271855815627313838388516}& {0.054836997143688792408247958303061879045638516173491}& {-}{0.076515435518044319517218299335460057103299438798401}& {0.0093002600302037228693027858413961837865887986834760}& {0.}& {0.}& {0.}\\ {0.054836997143688792408247958303061879045638516173491}& {1.0190795442103837012531041373825245474117656429532}& {-}{0.42467264975475382590709073532181913929136909457623}& {-}{0.016116727827330943226778991445093684120949837718847}& {0.}& {0.}& {0.}\\ {-}{0.076515435518044319517218299335460057103299438798401}& {-}{0.42467264975475382590709073532181913929136909457623}& {2.0214621985616492009289490977082087182086468171616}& {-}{0.50965995705126921942600611836937653744093332547732}& {0.}& {0.}& {0.}\\ {0.0093002600302037228693027858413961837865887986834760}& {-}{0.016116727827330943226778991445093684120949837718847}& {-}{0.50965995705126921942600611836937653744093332547732}& {2.2491943868514685137656620258975394150765552695306}& {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}& {0.}& {0.33333333333333333333333333333333333333333333333333}& {-}{3.8496822040751973138321389112729645857823238931349}{}{{10}}^{{-50}}& {-}{6.1340857535650804575141297226367399037182210044452}{}{{10}}^{{-51}}\\ {0.}& {0.}& {0.}& {0.}& {-}{3.8496822040751973138321389112729645857823238931349}{}{{10}}^{{-50}}& {0.67494240312586739704767351946529754472265510527072}& {-}{2.9362773606352192932407413788839969812745930630482}{}{{10}}^{{-50}}\\ {0.}& {0.}& {0.}& {0.}& {-}{6.1340857535650804575141297226367399037182210044452}{}{{10}}^{{-51}}& {-}{2.9362773606352192932407413788839969812745930630482}{}{{10}}^{{-50}}& {1.0082757364592007303810068527986308780559884386041}\end{array}\right]$
 $\left[\begin{array}{cc}{0.474104074310421}& {-}{0.135458306945628}\\ {0.0578831064518730}& {0.578831064350061}\end{array}\right]$ (9)