# How is the transfer function of a state-space representation numerically computed?

This question is a duplicate of this question that I asked on dsp stack exchange. However, nobody had the answer there but the question seems more appropriate on this forum (If not feel free to tell me, it's my first post here).

The question is the following :

I've got my state space representation $$\dot{X} = AX+BU$$ $$Y = CX$$

with Laplace we get : $$Y(s) = C(A-sI)^{-1}BU(s) = H(s)U(s)$$ And I want to evaluate the coefficients of the rational function matrix : $$H(s) = C(A-sI)^{-1}B$$

my first idea was to use the cofactor formula : $$(sI-A)^{-1} = \frac{1}{det(sI-A)}Com(sI-A)^T$$ with $$Com(sI-A)^T$$ the matrix of the cofactors of $$sI-A$$.

my second idea was $$A-sI = -s(I-\frac{1}{s}A)$$

and then if you have $$(\frac{1}{s}A)^{n} \xrightarrow[n \to \infty]{} 0$$ for $$|s|$$ above a certain threshold: $$(I-\frac{1}{s}A)^{-1} = \sum_{k=0}^{\infty}(\frac{1}{s}A)^{k} \approx \sum_{k=0}^{N}(\frac{1}{s}A)^{k}$$

Although I feel like it's a bad idea somehow.

I also checked the ss2tf scipy function code but I really don't get what they do (especially in the loop l 278/280).

Can anyone enlighten me?

• What do you mean exactly with "evaluate the coefficients" of a rational function matrix? Are you interested in evaluating its entries in a given $s$? Computing the coefficients of the polynomials $p_{ij},q_{ij}$ such that $A_{ij}(s) = p_{ij}(s) / q_{ij}(s)$? Converting it into a matrix-valued power series and evaluating the matrix coefficients of this power series? Feb 22 at 15:43
• Also, be aware that explicit representations as polynomials are often unstable; your final goal (whichever it is) may be better obtained without going through computing polynomial coefficients. Feb 22 at 15:44
• @FedericoPoloni true enough. I changed that. Also I want the coefficients, it allows to have transfer function instead of a state space model. My final goal is to understand how a function like ss2tf from scipy works. What do you mean by "explicit representations as polynomials are often unstable"? Feb 23 at 7:46
• One could demonstrate that $H(s)$ is a matrix of rational functions that share the same denominator (cofactor formula). By coefficients I mean both the coefficients of the numerator and the denominator polynomials. By coefficients of a polynomials I mean the $a_k$ in $P(X)=\sum_{k=0}^{n}a_kX^{k}$. If you know an algorithm that efficiently outputs a different representation (zeros or other points) of the rational functions in $H(s)$ please show me. Feb 24 at 11:37
• And thank you for the Wilkinson example, I suspected it was unstable (I knew that truncation errors can move the poles of a tf) but not in that scale. However in control and DSP, except in some specific cases (flexible structures), state space models have a reasonable size (2, 3, 4, 5 max). I went for the coefficient representation because it is intuitive, I had ideas on how to compute it and it actually is what the scipy function in my post outputs. However I do believe that inverting $sI-A$ for many s also comes with its own challenges, I wouldn't recommend doing that in most DSP context. Feb 24 at 11:47