ControlDesign

 ComputeQR
 compute the Q, R, and N matrices used in an LQR design based on a desired time constant of the closed-loop system

 Calling Sequence ComputeQR(sys, Tc, opts)

Parameters

 sys - System; system object Tc - And(positive, numeric); desired closed-loop time constant (in seconds) opts - (optional) equation(s) of the form option = value; specify options for the ComputeQR command

Options

 • computeN = truefalse
 True means include the $N$ weighting matrix in the returned record. The default 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).

Description

 • The ComputeQR command returns a record containing the $Q$ and $R$ weighting matrices needed by the LQR command. Optionally, the cross-coupling matrix $N$ (weighting on the state-input term in the quadratic cost function) is included in the returned record to be used with the corresponding option of the LQR command.
 • The computation of the weighting matrices is based on the desired time constant, Tc (seconds), of the closed-loop 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).
 • The ComputeQR command invokes the ReduceSystem command to remove the structural uncontrollable states of sys which may arise from using the Subsystem command before ComputeQR. The computed weighting matrices are obtained based in the reduced system (when applicable).

Examples

 > $\mathrm{with}\left(\mathrm{ControlDesign}\right):$
 > $\mathrm{with}\left(\mathrm{DynamicSystems}\right):$

Here is a state-space system corresponding to a DC motor model:

 > $\mathrm{sys_a}≔\mathrm{Matrix}\left(\left[\left[-\frac{d}{J},\frac{K}{J},0\right],\left[-\frac{K}{L},-\frac{R}{L},0\right],\left[1,0,0\right]\right]\right):$
 > $\mathrm{sys_b}≔\mathrm{Matrix}\left(\left[\left[0,\frac{1}{J}\right],\left[\frac{1}{L},0\right],\left[0,0\right]\right]\right):$
 > $\mathrm{sys_c}≔\mathrm{Matrix}\left(\left[\left[0,1,0\right],\left[1,0,0\right],\left[0,0,1\right]\right]\right):$
 > $\mathrm{sys_d}≔\mathrm{Matrix}\left(\left[\left[0,0\right],\left[0,0\right],\left[0,0\right]\right]\right):$
 > $\mathrm{sys}≔\mathrm{StateSpace}\left(\mathrm{sys_a},\mathrm{sys_b},\mathrm{sys_c},\mathrm{sys_d},\mathrm{inputvariable}=\left[V\left(t\right),T\left(t\right)\right],\mathrm{outputvariable}=\left[\mathrm{i_out}\left(t\right),\mathrm{omega_out}\left(t\right),\mathrm{theta_out}\left(t\right)\right],\mathrm{statevariable}=\left[\mathrm{ω}\left(t\right),i\left(t\right),\mathrm{θ}\left(t\right)\right]\right):$
 > $\mathrm{PrintSystem}\left(\mathrm{sys}\right)$
 $\left[\begin{array}{l}{\mathbf{State Space}}\\ {\mathrm{continuous}}\\ {\mathrm{3 output\left(s\right); 2 input\left(s\right); 3 state\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{V}{}\left({t}\right){,}{T}{}\left({t}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{i_out}}{}\left({t}\right){,}{\mathrm{omega_out}}{}\left({t}\right){,}{\mathrm{theta_out}}{}\left({t}\right)\right]\\ {\mathrm{statevariable}}{=}\left[{\mathrm{\omega }}{}\left({t}\right){,}{i}{}\left({t}\right){,}{\mathrm{\theta }}{}\left({t}\right)\right]\\ {\mathrm{a}}{=}\left[\begin{array}{ccc}{-}\frac{{d}}{{J}}& \frac{{K}}{{J}}& {0}\\ {-}\frac{{K}}{{L}}& {-}\frac{{R}}{{L}}& {0}\\ {1}& {0}& {0}\end{array}\right]\\ {\mathrm{b}}{=}\left[\begin{array}{cc}{0}& \frac{{1}}{{J}}\\ \frac{{1}}{{L}}& {0}\\ {0}& {0}\end{array}\right]\\ {\mathrm{c}}{=}\left[\begin{array}{ccc}{0}& {1}& {0}\\ {1}& {0}& {0}\\ {0}& {0}& {1}\end{array}\right]\\ {\mathrm{d}}{=}\left[\begin{array}{cc}{0}& {0}\\ {0}& {0}\\ {0}& {0}\end{array}\right]\end{array}\right$ (1)

The numeric values of the model parameters are as follows:

 > $\mathrm{params}≔\left\{J=0.01,d=0.1,K=0.01,R=1,L=0.5\right\}:$

Extract a subsystem with the desired input and output.

 > $\mathrm{subsys}≔\mathrm{Subsystem}\left(\mathrm{sys},\left\{1\right\},\left\{2\right\}\right)$
 ${\mathrm{subsys}}{:=}\left[\begin{array}{c}{\mathbf{State Space}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right); 3 state\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{V}{}\left({t}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{omega_out}}{}\left({t}\right)\right]\\ {\mathrm{statevariable}}{=}\left[{\mathrm{\omega }}{}\left({t}\right){,}{i}{}\left({t}\right){,}{\mathrm{\theta }}{}\left({t}\right)\right]\end{array}\right$ (2)

Compute the weighting Matrices Q and R for a desired time constant of 1 second:

 > $\mathrm{τ}≔1:$
 > $\mathrm{QR}≔\mathrm{ComputeQR}\left(\mathrm{subsys},\mathrm{τ},'\mathrm{parameters}'=\mathrm{params}\right)$
 ${\mathrm{QR}}{:=}{\mathrm{Record}}{}\left({Q}{=}\left[\begin{array}{ccc}{1.}& {0.}& {0.}\\ {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}\end{array}\right]{,}{R}{=}\left[\begin{array}{c}{0.00804031799261397}\end{array}\right]\right)$ (3)

Use the previous result to compute the state feedback gain:

 > $\mathrm{Kc}≔\mathrm{LQR}\left(\mathrm{subsys},\mathrm{QR}:-Q,\mathrm{QR}:-R,'\mathrm{parameters}'=\mathrm{params}\right)$
 ${\mathrm{Kc}}{:=}\left[\begin{array}{ccc}{0.963450784290618}& {0.401231880985663}& {0}\end{array}\right]$ (4)

Optionally, compute the weighting Matrix N:

 > $\mathrm{QRN}≔\mathrm{ComputeQR}\left(\mathrm{subsys},\mathrm{τ},'\mathrm{computeN}'=\mathrm{true},'\mathrm{parameters}'=\mathrm{params}\right)$
 ${\mathrm{QRN}}{:=}{\mathrm{Record}}{}\left({Q}{=}\left[\begin{array}{ccc}{1.}& {0.}& {0.}\\ {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}\end{array}\right]{,}{R}{=}\left[\begin{array}{c}{0.00804031799261397}\end{array}\right]{,}{N}{=}\left[\begin{array}{c}{0.}\\ {0.}\\ {0.}\end{array}\right]\right)$ (5)

Use matrices Q, R, and N to compute the state feedback gain. In this case, N is a zero Matrix, so the result is the same as before:

 > $\mathrm{Kc}≔\mathrm{LQR}\left(\mathrm{subsys},\mathrm{QRN}:-Q,\mathrm{QRN}:-R,'N'=\mathrm{QRN}:-N,'\mathrm{parameters}'=\mathrm{params}\right)$
 ${\mathrm{Kc}}{:=}\left[\begin{array}{ccc}{0.963450784290618}& {0.401231880985663}& {0}\end{array}\right]$ (6)