30. Transfer function matrices
Let’s say we have two inputs and two outputs. We can write the linearised effect as follows:
\begin{align}
y_1 &= G_{11} u_1 + G_{12} u_2 \\
y_2 &= G_{21} u_1 + G_{22} u_2
\end{align}
Which is equivalent to a matrix expression
\[\mathbf{y} = G \mathbf{u}\]
with
\[\begin{split}\mathbf{y} = \begin{bmatrix}y_1\\y_2\end{bmatrix}
\quad G = \begin{bmatrix}G_{11} & G_{12} \\ G_{21} & G_{22} \end{bmatrix}
\quad \mathbf{u} = \begin{bmatrix}u_1\\u_2\end{bmatrix}\end{split}\]
I find it useful to picture the input going into the top of the matrix and the output coming out of the side as shown in this animation

30.1. Representing matrices in SymPy
$\displaystyle \frac{s + 1}{s + 2}$
$\displaystyle \left[\begin{matrix}\frac{6 s^{3} + 17 s^{2} + 11 s + 2}{6 s^{3} + 7 s^{2} - 3 s - 1} & - \frac{12 s^{3} + 31 s^{2} + 15 s + 2}{6 s^{3} + 7 s^{2} - 3 s - 1}\\- \frac{8 s^{3} + 22 s^{2} + 13 s + 2}{6 s^{3} + 7 s^{2} - 3 s - 1} & \frac{24 s^{4} + 50 s^{3} + 35 s^{2} + 10 s + 1}{6 s^{3} + 7 s^{2} - 3 s - 1}\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}\frac{2 \left(s + 1\right)}{s + 2} & \frac{2}{2 s + 1}\\\frac{2}{3 s + 1} & \frac{2}{4 s + 1}\end{matrix}\right]$
30.2. Representing matrices using the control library
$$\begin{bmatrix}\frac{s + 2}{s + 1}&\frac{2}{2 s + 1}\\\frac{3}{3 s + 1}&\frac{4}{4 s + 1}\\ \end{bmatrix}$$
31. Conversion to state space
See the state space notebook for more information about conversion between state space and transfer function form. The examples in that notebook are for SISO transfer functions.
There are no tools in scipy.signal
to deal with mutlivariable transfer functions. However, the control library can do the conversion from a transfer function matrix to a state space form if you have the `slycot <>`__ library installed.
You can try to install slycot using this command:
\[
\left(
\begin{array}{rllrllrllrll|rllrll}
-1.&\hspace{-1em}33&\hspace{-1em}\phantom{\cdot}&-1.&\hspace{-1em}11&\hspace{-1em}\cdot10^{-16}&-1.&\hspace{-1em}67&\hspace{-1em}\cdot10^{-16}&-0.&\hspace{-1em}333&\hspace{-1em}\phantom{\cdot}&1\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&-1.&\hspace{-1em}11&\hspace{-1em}\cdot10^{-16}\\
-3.&\hspace{-1em}33&\hspace{-1em}\cdot10^{-16}&-0.&\hspace{-1em}75&\hspace{-1em}\phantom{\cdot}&-0.&\hspace{-1em}125&\hspace{-1em}\phantom{\cdot}&6.&\hspace{-1em}94&\hspace{-1em}\cdot10^{-17}&0\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&1\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}\\
1.&\hspace{-1em}11&\hspace{-1em}\cdot10^{-16}&1\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&-2.&\hspace{-1em}1&\hspace{-1em}\cdot10^{-16}&-3.&\hspace{-1em}41&\hspace{-1em}\cdot10^{-16}&0\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&0\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}\\
1\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&0\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&1.&\hspace{-1em}31&\hspace{-1em}\cdot10^{-16}&-9.&\hspace{-1em}52&\hspace{-1em}\cdot10^{-17}&0\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&0\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}\\
\hline
1\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&1\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&0.&\hspace{-1em}25&\hspace{-1em}\phantom{\cdot}&0.&\hspace{-1em}333&\hspace{-1em}\phantom{\cdot}&1\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&0\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}\\
1\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&1\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&0.&\hspace{-1em}5&\hspace{-1em}\phantom{\cdot}&1\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&0\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}&0\phantom{.}&\hspace{-1em}&\hspace{-1em}\phantom{\cdot}\\
\end{array}\right)
\]
What are the true values of those small (10:math:^{-16}) values?