ENع
→State space ⇄ G(s)
الدرس 45 · State space and digital control

From state space to transfer function and back

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

16 دقيقة11 خطوة5 أسئلةAdvanced
عن هذا الدرس

One cart, two descriptions. Starting from its state-space matrices A, B, C and D, take the Laplace transform and solve for the output to get the transfer function G(s) = C(sI − A)⁻¹B + D. The determinant of sI − A becomes the denominator, so the poles are the eigenvalues of A. Then go back: the controllable canonical form rebuilds the matrices from G(s), and a change of states shows that many matrix models share one transfer function.

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل 45 · تفاعلي
01 / 11

A cart in state space

A 1 kg cart on a spring and a damper, pushed by a force u. Its state x is two numbers: position x₁ and velocity x₂. The state-space model is ẋ = Ax + Bu and y = Cx + Du.

m = 1 kg, k = 2 N/m, b = 3 N·s/m

state   x = (x₁, x₂) = (position, velocity)
input   u = force (N)
output  y = position (m)

ẋ = A x + B u      how the state changes
y = C x + D u      what we measure

Each integrator turns ẋ back into x,
so the state is what the integrators hold.
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. A cart in state space

    A 1 kg cart on a spring and a damper, pushed by a force u. Its state x is two numbers: position x₁ and velocity x₂. The state-space model is ẋ = Ax + Bu and y = Cx + Du.

    m = 1 kg, k = 2 N/m, b = 3 N·s/m
    
    state   x = (x₁, x₂) = (position, velocity)
    input   u = force (N)
    output  y = position (m)
    
    ẋ = A x + B u      how the state changes
    y = C x + D u      what we measure
    
    Each integrator turns ẋ back into x,
    so the state is what the integrators hold.
  2. Read the four matrices

    Newton's law gives ẋ₂ = −2x₁ − 3x₂ + u. So A = [0 1; −2 −3] holds the spring and damper, B = [0; 1] says the force changes velocity, and C = [1 0] picks position as y. D = 0.

    m·ẍ = u − b·ẋ − k·x   →   ẍ = −2x − 3ẋ + u
    
    ẋ₁ = x₂                     row 1 of A: [ 0   1]
    ẋ₂ = −2x₁ − 3x₂ + u         row 2 of A: [−2  −3]
    
    B = [0; 1]   u only enters ẋ₂
    C = [1 0]    y = x₁, the position
    D = 0        no direct path from u to y
  3. Integrators become 1/s

    A transfer function lives in the Laplace domain. There, integrating a signal divides it by s, so each integrator becomes a 1/s block. With the cart starting at rest, ẋ = Ax + Bu becomes sX(s) = AX(s) + BU(s).

    Laplace transform, zero initial state:
    
      ẋ(t)        →   s X(s)
      ∫ f dt      →   F(s) / s
    
    ẋ = A x + B u   →   s X = A X + B U
    
    X(s) and U(s) are the transforms of
    the state and the input. The Signals
    lessons on the Laplace transform cover why.
  4. Gather the X terms

    Move AX to the left: sX − AX = BU. To factor out X, write s as sI, the identity matrix times s: (sI − A)X = BU. Multiply by the inverse: X = (sI − A)⁻¹BU.

    s X − A X = B U
    (s I − A) X = B U          I = [1 0; 0 1]
    X = (s I − A)⁻¹ B U
    
    Why sI and not just s? s is a number and
    A is a matrix; s·I is the matrix with s on
    the diagonal, so the subtraction makes sense.
    
    sI − A = [ s   −1 ]
             [ 2  s+3 ]
  5. The determinant becomes the denominator

    Here sI − A = [s −1; 2 s+3]. Inverting a 2×2 matrix divides by its determinant: s(s + 3) − (−1)(2) = s² + 3s + 2. That polynomial becomes the bottom of the transfer function.

    for a 2×2 matrix  M = [p q; r t]:
      M⁻¹ = [t −q; −r p] / (p·t − q·r)
    
    det(sI − A) = s·(s+3) − (−1)·2
                = s² + 3s + 2
    
    (sI − A)⁻¹ = [s+3  1; −2  s] / (s² + 3s + 2)
  6. Multiply by C and B

    B = [0; 1] picks the second column of the inverse: (1, s) over s² + 3s + 2. C = [1 0] keeps the first entry. So G(s) = Y(s)/U(s) = C(sI − A)⁻¹B + D = 1/(s² + 3s + 2).

    (sI − A)⁻¹ B = [1; s] / (s² + 3s + 2)
    C (sI − A)⁻¹ B = 1 / (s² + 3s + 2)
    D = 0
    
    G(s) = Y(s)/U(s) = 1 / (s² + 3s + 2)
    
    Check with the cart itself (m = 1, b = 3,
    k = 2): Newton's law m x'' + b x' + k x = u
    gives 1/(m s² + b s + k) = 1/(s² + 3s + 2).
  7. Poles are eigenvalues

    s² + 3s + 2 = (s + 1)(s + 2), so G(s) has poles at −1 and −2. Those are exactly the eigenvalues of A: det(sI − A) = 0 is the eigenvalue equation. Same numbers, two names.

    poles of G(s):  s² + 3s + 2 = 0
                    s = −1, s = −2
    
    eigenvalues of A:  det(λI − A) = 0
                       λ² + 3λ + 2 = 0
                       λ = −1, λ = −2
    
    Both negative: the cart settles. Any
    model's poles sit at its A's eigenvalues
    (unless a pole cancels against a zero).
  8. Same response either way

    Push with a steady 1 N. Stepping ẋ = Ax + Bu in 1 ms steps, and the exact step response of G(s), 0.5 − e⁻ᵗ + 0.5e⁻²ᵗ, agree to within 0.10 mm. The cart settles at 0.5 m.

    # step the state-space model, u = 1 N
    import math
    x1, x2, dt = 0.0, 0.0, 0.001
    for n in range(1000):          # 1 s
        x1, x2 = x1 + dt * x2, x2 + dt * (-2 * x1 - 3 * x2 + 1)
    exact = 0.5 - math.exp(-1) + 0.5 * math.exp(-2)
    print(f"{x1:.3f} {exact:.3f}")  # 0.200 0.200
  9. Back: read off the coefficients

    Going back, write G(s) = (b₁s + b₀)/(s² + a₁s + a₀). The controllable canonical form puts −a₀ and −a₁ in the bottom row of A, sets B = [0; 1] and C = [b₀ b₁]. Our round trip lands where it started.

    G(s) = 1 / (s² + 3s + 2)
      a₁ = 3, a₀ = 2, b₁ = 0, b₀ = 1
    
    A = [  0    1 ]  = [ 0   1]
        [ −a₀ −a₁ ]    [−2  −3]
    B = [0; 1]
    C = [b₀ b₁] = [1 0]
    
    The denominator's coefficients, sign
    flipped, become A's bottom row.
  10. Many models, one G(s)

    Choose new states z = T⁻¹x, two mixes of position and velocity. Now A = [−1 0; 0 −2], B = [1; −1], C = [1 1]. Different matrices, same G(s), same response. G(s) never says which states you chose.

    T = [ 1   1]   columns: eigenvectors of A
        [−1  −2]
    
    z = T⁻¹x:  z₁ = 2x₁ + x₂,  z₂ = −x₁ − x₂
    
    A = T⁻¹AT = [−1  0; 0  −2]   (eigenvalues!)
    B = T⁻¹B   = [1; −1]
    C = C·T    = [1 1]
    
    G = 1/(s+1) − 1/(s+2) = 1/(s² + 3s + 2)
  11. Check it in Python

    For any 2×2 model the denominator is s² − (trace of A)s + det A. Our trace is −3 and det A is 2, so both models give s² + 3s + 2. In practice python-control does the general case with ss2tf and tf2ss.

    def ss2tf_2x2(A, B, C, D=0):
        (a, b), (c, d) = A
        (b1, b2), (c1, c2) = B, C
        den = [1, -(a + d), a * d - b * c]   # det(sI - A)
        n1 = c1 * b1 + c2 * b2               # C adj(sI - A) B
        n0 = c1 * (b * b2 - d * b1) + c2 * (c * b1 - a * b2)
        return [D, n1 + D * den[1], n0 + D * den[2]], den
    
    print(ss2tf_2x2([[0, 1], [-2, -3]], [0, 1], [1, 0]))
    print(ss2tf_2x2([[-1, 0], [0, -2]], [1, -1], [1, 1]))
    # ([0, 0, 1], [1, 3, 2])  both times

اختبار يتاح بعد الخطوة الأخيرة.