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

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

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.0481202313656361}& {0.301603484123463}& {-}{0.420834895016569}& {0.0511514302595199}& {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}& {0.}& {0.}& {0.0372408140701274}& {1.69574582391755}{}{{10}}^{{-50}}\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.0481202313656361}& {0.301603484123463}& {-}{0.420834895016569}& {0.0511514302595199}& {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}& {0.}& {0.}& {0.0372408140701274}& {1.69574582391755}{}{{10}}^{{-50}}\end{array}\right]$
 $\left[\begin{array}{c}{-}{0.0959924471141893}{+}{0.725780367537388}{}{I}\\ {-}{0.0959924471141893}{-}{0.725780367537388}{}{I}\\ {0.597646681622232}{+}{0.}{}{I}\\ {-}{0.133580894353374}{+}{0.}{}{I}\\ {0.}{+}{0.}{}{I}\\ {0.271790906819696}{+}{0.}{}{I}\\ {-}{0.271790906819696}{+}{0.}{}{I}\end{array}\right]$
 $\left[\begin{array}{ccccccc}{0.34208246631187824237153157286495650360927837605170}& {0.054836997132001587445332297967168012679100953442852}& {-}{0.076515435483573172207699371320421129543508843859046}& {0.0093002600503475245958101185386354897124328075544719}& {0.}& {0.}& {0.}\\ {0.054836997132001587445332297967168012679100953442852}& {1.0190795439133332447886728277914600122705242643576}& {-}{0.42467264923323657723212803256376233117289399958942}& {-}{0.016116727701540323095972632475427646204155394711151}& {0.}& {0.}& {0.}\\ {-}{0.076515435483573172207699371320421129543508843859046}& {-}{0.42467264923323657723212803256376233117289399958942}& {2.0214621973630230960453079020522883940353356203063}& {-}{0.50965995660268459935291011905637256031824617502949}& {0.}& {0.}& {0.}\\ {0.0093002600503475245958101185386354897124328075544719}& {-}{0.016116727701540323095972632475427646204155394711151}& {-}{0.50965995660268459935291011905637256031824617502949}& {2.2491943858427307392562163192701328010573450216742}& {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}& {0.}& {0.33333333333333333333333333333333333333333333333333}& {-}{2.4270094691034002880344198827704458842139905760299}{}{{10}}^{{-51}}& {1.0007947769608144112114941245739281902192493207633}{}{{10}}^{{-50}}\\ {0.}& {0.}& {0.}& {0.}& {-}{2.4270094691034002880344198827704458842139905760299}{}{{10}}^{{-51}}& {0.67494240312586739809613759398120641519658181476351}& {5.1012710172931811847873597214348238242769339934302}{}{{10}}^{{-50}}\\ {0.}& {0.}& {0.}& {0.}& {1.0007947769608144112114941245739281902192493207633}{}{{10}}^{{-50}}& {5.1012710172931811847873597214348238242769339934302}{}{{10}}^{{-50}}& {1.0082757364592007314294709273145397485299151480967}\end{array}\right]$
 $\left[\begin{array}{cc}{0.474104074328452}& {-}{0.135458306924427}\\ {0.0578831064342944}& {0.578831064342944}\end{array}\right]$ (9)