Part: control Week 11 Published state_space.py test_state_space.py

State-Space Models and Transfer Functions

The entry to control theory: the linear state-space model, the transfer function, and their equivalence. Two views of one dynamical system, the state-similarity invariance that makes the transfer function the coordinate-free object, and the discrete-time model that is exactly the MDP dynamics control assumes known.

On this page
  1. The linear state-space model
  2. The transfer function
  3. Two views, one system
  4. Discretization: the bridge to a step map
  5. The dynamic-programming bridge
  6. What’s next
  7. Exercises
  8. Companion code

State-Space Models and Transfer Functions

Where we are. Part I learned policies and values from interaction, with the dynamics unknown or only sampled. Part II turns to control theory, which starts from the opposite end — an explicit model of the dynamics — and asks what optimal feedback that model permits. The foundational object is the linear state-space model h˙=Ah+Bu\dot{\statevec} = \statemat\statevec + \inputmat u, $y = \outputmat\statevec

  • \feedmat u,anditsfrequencydomaintwin,thetransferfunction, and its frequency-domain twin, the **transfer function** H(s) = \outputmat(s I - \statemat)^-1\inputmat + \feedmat$. They are two views of one system. This chapter sets up that object — and shows its discrete-time form is exactly the known MDP dynamics that LQR (Week 13) will solve in closed form.

The linear state-space model

Definition 11.1 (Linear time-invariant state-space model).

A continuous-time LTI system with state hRn\statevec\in\R^n, input uRmu\in\R^m, and output yRpy\in\R^p is

h˙=Ah+Bu,y=Ch+Du,\dot{\statevec} = \statemat\statevec + \inputmat u, \qquad y = \outputmat\statevec + \feedmat u,

with ARn×n\statemat\in\R^{n\times n}, BRn×m\inputmat\in\R^{n\times m}, CRp×n\outputmat\in\R^{p\times n}, DRp×m\feedmat\in\R^{p\times m}. Its discrete-time counterpart, sampled at step Δ\stepsize, is hk+1=Aˉhk+Bˉuk\statevec_{k+1} = \discA\statevec_k + \discB u_k, yk=Chk+Duky_k = \outputmat\statevec_k + \feedmat u_k.

The running example is the mass–spring–damper mq¨+cq˙+kq=um\ddot{q} + c\dot{q} + kq = u: taking the state h=(q,q˙)\statevec = (q, \dot q) gives A=(01k/mc/m)\statemat = \begin{pmatrix} 0 & 1 \\ -k/m & -c/m \end{pmatrix}, B=(01/m)\inputmat = \begin{pmatrix} 0 \\ 1/m \end{pmatrix}, and C=(10)\outputmat = \begin{pmatrix} 1 & 0 \end{pmatrix} if we measure position. A second-order mechanical law has become a first-order vector ODE — the form every method in Part II acts on.

The transfer function

Laplace-transforming the state equation at zero initial condition and eliminating the state gives the input–output map directly.

Definition 11.2 (Transfer function).

The transfer function of (A,B,C,D)(\statemat,\inputmat,\outputmat,\feedmat) is the rational matrix

H(s)=C(sIA)1B+D,H(s) = \outputmat\,(s I - \statemat)^{-1}\inputmat + \feedmat,

mapping input to output in the Laplace domain, Y(s)=H(s)U(s)Y(s) = H(s)\,U(s). Its poles are the eigenvalues of A\statemat (those not cancelled by zeros), and its zeros are the frequencies it blocks.

For the mass–spring–damper the single-input single-output transfer function is H(s)=1ms2+cs+kH(s) = \tfrac{1}{m s^2 + c s + k} — the poles are the roots of the characteristic polynomial, i.e. the eigenvalues of A\statemat, exactly the natural frequencies of the oscillator. Åström and Murray \AAström & Murray (2021) develop both views and their interplay; the state-space form carries the internal dynamics, the transfer function the external behaviour.

Two views, one system

The two representations are equivalent, with one asymmetry worth making precise: the transfer function is unique, but the state-space realization is not — any invertible change of state coordinates leaves the input–output behaviour untouched.

Proposition 11.1 (State-similarity invariance).

For any invertible TRn×nT\in\R^{n\times n}, the coordinate change h=Tz\statevec = T z produces the system (T1AT,  T1B,  CT,  D)(\,T^{-1}\statemat T,\; T^{-1}\inputmat,\; \outputmat T,\; \feedmat\,) with the same transfer function H(s)H(s).

Proof.

Substitute h=Tz\statevec = Tz into Definition 11.1: z˙=T1ATz+T1Bu\dot z = T^{-1}\statemat T z + T^{-1}\inputmat u and y=CTz+Duy = \outputmat T z + \feedmat u, so the transformed matrices are as stated. Its transfer function is

H~(s)=(CT)(sIT1AT)1(T1B)+D(Def. 11.2 on the transformed system)=CT[T1(sIA)T]1T1B+D(sI=T1(sI)T)=CTT1(sIA)1TT1B+D=C(sIA)1B+D=H(s).(TT1=I)\begin{aligned} \tilde H(s) &= (\outputmat T)\big(sI - T^{-1}\statemat T\big)^{-1}(T^{-1}\inputmat) + \feedmat && \text{(Def. 11.2 on the transformed system)} \\ &= \outputmat T\,\big[\,T^{-1}(sI - \statemat)T\,\big]^{-1}T^{-1}\inputmat + \feedmat && \text{($sI = T^{-1}(sI)T$)} \\ &= \outputmat T\,T^{-1}(sI - \statemat)^{-1}T\,T^{-1}\inputmat + \feedmat = \outputmat(sI - \statemat)^{-1}\inputmat + \feedmat = H(s). && \text{($T T^{-1} = I$)} \end{aligned}

The similarity transform cancels, leaving HH unchanged. \qquad\blacksquare

So the state-space model is a coordinate choice on the same dynamics, and the transfer function is the coordinate-free invariant.

The reverse direction — building a state-space model from a transfer function — is realization, and its non-uniqueness (canonical forms) is the companion’s round-trip check.

Discretization: the bridge to a step map

Control plants are continuous, but computation and the MDP view are discrete. Exact zero-order-hold (ZOH) discretization at step Δ\stepsize — holding uu constant across the interval — gives

Aˉ=eAΔ,Bˉ=(0ΔeAτdτ)B,\discA = e^{\statemat\stepsize}, \qquad \discB = \Big(\textstyle\int_0^{\stepsize} e^{\statemat\tau}\,d\tau\Big)\inputmat,

the matrix exponential of AΔ\statemat\stepsize. The cheap alternative, forward Euler, takes AˉI+AΔ\discA \approx I + \statemat\stepsize — the first two terms of that exponential, accurate only for small Δ\stepsize. Either way the result hk+1=Aˉhk+Bˉuk\statevec_{k+1} = \discA\statevec_k + \discB u_k is a deterministic step map.

The dynamic-programming bridge

That step map closes the loop with Part I. hk+1=Aˉhk+Bˉuk\statevec_{k+1} = \discA\statevec_k + \discB u_k is precisely a Markov decision process’s transition — deterministic, linear, and known — where Chapters 1–10 had a stochastic kernel learned from samples. Control theory’s premise is that the model is in hand, so the Bellman recursion can be solved exactly rather than approximated from experience. Three threads run forward from here:

  • To stability and structure (Week 12). Before designing any controller, ask what the model permits: stability from the eigenvalues of A\statemat, and whether the input can steer and the output can observe the full state.
  • To LQR (Week 13). Put a quadratic cost on this linear model and the Bellman equation has a closed-form solution — the Riccati equation — the exact dynamic-programming fixed point Chapter 1’s HJB aside promised.
  • To SSMs (Week 24). The very same (A,B,C,D)(\statemat,\inputmat,\outputmat,\feedmat) and its ZOH discretization are a structured-state-space neural layer (S4, Mamba); the control plant and the sequence model share one skeleton.

What’s next

  • Week 12 asks what can be known about a state-space model before designing a controller: stability (eigenvalue locations, Lyapunov), and the structural properties of controllability and observability that decide whether control and estimation are even possible.

Exercises

  1. (Derive) From mq¨+cq˙+kq=um\ddot{q} + c\dot{q} + kq = u with state h=(q,q˙)\statevec=(q,\dot q), derive the matrices A,B,C\statemat,\inputmat,\outputmat and the transfer function H(s)=1/(ms2+cs+k)H(s) = 1/(m s^2 + c s + k).

    Solution

    q˙1=q2\dot q_1 = q_2 and q˙2=(ucq2kq1)/m\dot q_2 = (u - c q_2 - k q_1)/m give the stated A,B\statemat, \inputmat; measuring position gives C=(1 0)\outputmat = (1\ 0). Then H(s)=C(sIA)1B=1det(sIA)1m=1ms2+cs+kH(s) = \outputmat(sI-\statemat)^{-1}\inputmat = \tfrac{1}{\det(sI-\statemat)}\cdot\tfrac1m = \tfrac{1}{m s^2 + c s + k}, since det(sIA)=s2+(c/m)s+k/m\det(sI-\statemat) = s^2 + (c/m)s + k/m.

  2. (Prove) Show the transfer function is invariant under a state-similarity transform h=Tz\statevec = Tz (Prop. 11.1), identifying where TT cancels.

    Solution

    The transformed system is (T1AT,T1B,CT,D)(T^{-1}\statemat T, T^{-1}\inputmat, \outputmat T, \feedmat); using sIT1AT=T1(sIA)TsI - T^{-1}\statemat T = T^{-1}(sI-\statemat)T and inverting, the TT and T1T^{-1} on either side of (sIA)1(sI-\statemat)^{-1} cancel against CT\outputmat T and T1BT^{-1}\inputmat, returning H(s)H(s).

  3. (Compute) For A=(0123)\statemat=\begin{pmatrix}0&1\\-2&-3\end{pmatrix}, B=(01)\inputmat=\begin{pmatrix}0\\1\end{pmatrix}, C=(1 0)\outputmat=(1\ 0), D=0\feedmat=0, compute H(s)H(s) and its poles.

    Solution

    det(sIA)=s2+3s+2=(s+1)(s+2)\det(sI-\statemat) = s^2+3s+2 = (s+1)(s+2), and H(s)=1/(s2+3s+2)H(s) = 1/(s^2+3s+2). Poles at s=1,2s=-1,-2 — the eigenvalues of A\statemat, both in the left half-plane (stable, as Week 12 will formalize).

  4. (Implement) In the companion, verify the SS→TF→SS round-trip preserves the transfer function, the mass–spring–damper TF matches 1/(ms2+cs+k)1/(ms^2+cs+k), and the step response settles to the DC gain H(0)=1/kH(0)=1/k.

    Solution

    See experiments/python/week11/test_state_space.py: python-control converts SS↔TF (round-trip preserves the rational function up to a state similarity); the mass–spring–damper TF coefficients match the analytic form; and the unit-step final value equals the final-value-theorem prediction H(0)=1/kH(0)=1/k.

  5. (Extend) Compare exact ZOH (Aˉ=eAΔ\discA = e^{\statemat\stepsize}) against forward Euler (AˉI+AΔ\discA \approx I + \statemat\stepsize): how does the discretization error scale with Δ\stepsize?

    Solution

    ZOH is exact for piecewise-constant input; Euler is its first-order truncation, with error O(Δ2)O(\stepsize^2) per step (it drops the 12A2Δ2\tfrac12\statemat^2\stepsize^2 and higher terms of the exponential). The companion shows the gap vanishing as Δ0\stepsize\to0 and growing — eventually destabilizing Euler — for large Δ\stepsize.

Companion code

The Week-11 companion lives at experiments/python/week11/ and is the first control companion (Python, on scipy + the python-control library).

  • state_space.py — builds the mass–spring–damper state-space model, converts SS↔TF (python-control), simulates impulse/step/forced responses, and discretizes via exact ZOH (scipy.linalg.expm) and forward Euler.
  • test_state_space.py — mathematical-correctness tests: the SS→TF→SS round-trip preserves the transfer function; the mass–spring–damper TF equals 1/(ms2+cs+k)1/(ms^2+cs+k); the step response settles to the DC gain H(0)=1/kH(0)=1/k; ZOH equals eAΔe^{\statemat\stepsize} while Euler is its first-order truncation; and the transfer function is invariant under a random state-similarity transform (Prop. 11.1).
# core algorithms + correctness tests (scipy + python-control)
PYTHONPATH=. pytest experiments/python/week11/test_state_space.py -q

# worked mass-spring-damper SS/TF + response plots (saved locally, not committed)
PYTHONPATH=. python experiments/python/week11/state_space.py --plot