Lite / Engineering Complex Systems / Week 11
From one second-order equation to two first-order ones
Computers can only take small steps forward. How do you step forward an equation that talks about acceleration?
Why should I care?
Every serious simulation tool, flight controller and robotics library works with first-order state equations. Learning this one rewrite lets you simulate almost anything with the same few lines of code.
- Rewrite an nth-order differential equation as n first-order equations in state variables.
- Write a linear system in the form dx/dt = A·x + B·u and identify A and B.
- Relate the eigenvalues of A to growth, decay and oscillation (preview).
Predict
For m = 1, c = 0, k = 4, what will the phase-plane path look like?
- A spiral into the origin
- A closed ellipse
- A straight line to the origin
- A spiral outwards
Guess first, then reveal
With no damping, energy is conserved, so the state goes round the same closed path forever. A has eigenvalues ±2j: purely imaginary, no growth or decay.
Discover
Set c = 0 and k = 4 and check the eigenvalues read 0 ± 2j. Now raise c slowly. Find the value of c where the eigenvalues stop having an imaginary part, and check it against c = 2√(km).
What the interactive shows (text version)
With damping c = 0 and stiffness 4, the phase-plane path is a closed ellipse and the eigenvalues are 0 ± 2j. As c increases the path becomes an inward spiral and the eigenvalues get a negative real part. At c = 4 (twice the square root of k times m) the imaginary part vanishes and the path slides into the origin without circling.
Understand
Any order, first-order steps
An nth-order equation needs n initial conditions, so it has n states. Define x₁ = y, x₂ = ẏ, …, xₙ = y⁽ⁿ⁻¹⁾. Each state's derivative is the next state, except the last, which comes from the original equation.
The A and B matrices
For linear systems the right-hand sides are weighted sums, so they fit in matrices: dx/dt = A·x + B·u. A says how the states push on each other; B says how the input pushes on each state. The same code steps any system once you supply A and B.
Eigenvalues preview
Each eigenvalue λ of A gives a mode that behaves like e^(λt). Negative real part: decays. Positive: grows. Imaginary part: oscillates. You will use this in week 15; for now, notice that the phase-plane readout's eigenvalues change exactly when the picture changes shape.
Explain it another way
Intuitive
A second-order equation is like a staircase you can't step up in one go. Introducing velocity as a state adds a landing halfway, so each step is a small first-order one.
Technical
Companion form maps y⁽ⁿ⁾ + aₙ₋₁y⁽ⁿ⁻¹⁾ + … + a₀y = b·u to dx/dt = A·x + B·u with A in companion form. The characteristic polynomial of A equals that of the ODE.
Mathematical
For A = [[0,1],[−k/m,−c/m]]: trace = −c/m, determinant = k/m, so λ = (−c/m ± √((c/m)² − 4k/m))/2. Real eigenvalues exactly when c² ≥ 4km, that is c ≥ 2√(km).
Applied
Robotics libraries describe a drone, an arm or a car as A and B (after linearising), then reuse the same simulation, estimation and control code.
Derivation: Mass–spring–damper in state-space form
Start from Newton's second law for a mass on a spring with a damper: m·ẍ = F − c·ẋ − k·x.
Choose states x₁ = x (position) and x₂ = ẋ (velocity). Then ẋ₁ = x₂ by definition.
Divide Newton's law by m: ẋ₂ = ẍ = −(k/m)·x₁ − (c/m)·x₂ + F/m.
Stack them: d/dt [x₁; x₂] = [[0, 1], [−k/m, −c/m]]·[x₁; x₂] + [0; 1/m]·F. That is dx/dt = A·x + B·u with u = F.
The eigenvalues of A solve λ² + (c/m)·λ + k/m = 0, the same characteristic equation as the original ODE: λ = −ζωn ± ωn√(ζ² − 1).
Worked example 1
Write L·di/dt + R·i + q/C = V(t) with q the capacitor charge (i = dq/dt) in state-space form.
States x₁ = q, x₂ = i. Then ẋ₁ = x₂ and ẋ₂ = (V − R·x₂ − x₁/C)/L. So A = [[0, 1], [−1/(LC), −R/L]], B = [0; 1/L]. It has the same shape as the mass–spring–damper with m ↔ L, c ↔ R, k ↔ 1/C.
Common mix-ups
State-space form is a different model from the differential equation.
✓ It is the same model written differently. The characteristic polynomial, and so the behaviour, is identical.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Write the state-space form of a DC motor with states speed ω and current i: J·dω/dt = kₜ·i − b·ω and L·di/dt = V − R·i − kₑ·ω. Identify A and B and say which entry couples the electrical and mechanical parts.
Reflect
Why do you think almost every simulation library asks for first-order equations rather than higher-order ones?
Write your answer on paper or in your own notes. Lite never stores what you write.