explainer
State-space models: connect states, inputs, and outputs
Build a cart state-space model from Newton’s law. Read A, B, C, and D, separate initial motion from force response, and choose position, velocity, or acceleration as the output.
What you will learn
- Convert a cart’s force equation into two first-order state equations.
- Interpret the dimensions and physical units of A, B, C, and D.
- Change an output map without changing the state trajectory.
- Separate zero-input and zero-state responses, including direct feedthrough.
- Check an exact response with and without viscous damping.
Before you start
A state-space model describes how a system’s internal variables change under an input, then defines the output you observe. Position and velocity can form the state of a cart. A position sensor reports only one part of that state.
You will derive this model from force balance, read its four matrices, and calculate its motion. The same cart can report position, velocity, or acceleration without changing its underlying trajectory.
Define a state-space model
A state collects the variables needed to predict the modeled future when you also know the future input. It carries the effect of earlier motion into the next calculation. Choosing a state does not imply that a sensor measures every component.
For a continuous-time linear time-invariant model, write:
ẋ(t) = Ax(t) + Bu(t)
y(t) = Cx(t) + Du(t)
The first equation determines motion. The second specifies a measured or modeled output. MathWorks’ state-space reference uses this form and defines the corresponding matrix dimensions.
State-space modeling also includes nonlinear equations such as ẋ = f(x,u). Constant A, B, C, and D describe the linear time-invariant case used here. A model can contain useful internal coordinates even when it is not a minimal representation of one selected output.
Derive the cart’s state equations
Consider a cart on a horizontal track. Applied force u and velocity v are positive to the right. Viscous damping supplies force −bv, opposing either direction of motion.
With constant mass m and damping coefficient b, Newton’s law gives:
mv̇ = u − bv
x = [p, v]ᵀ
ṗ = v, and v̇ = −(b/m)v + (1/m)u
Here m is positive and b is nonnegative. The track supplies the vertical support force, so gravity contributes no force along the modeled direction. The cart has no spring, dry friction, actuator lag, or force limit.
Two carts at the same position can have different velocities. Under the same next force, their future positions will differ. Recording position alone would omit information that this motion equation needs.
Read A, B, C, and D
Fix the state order as position first, velocity second. The equations above give:
A = [0, 1; 0, −b/m]
B = [0; 1/m]
Semicolons separate rows. Multiplying A by [p,v]ᵀ gives [v,−bv/m]ᵀ. Multiplying B by force adds [0,u/m]ᵀ.
- A describes how the current state affects its rates of change.
- B describes how the input affects those rates.
- C maps the state into the selected output.
- D maps the current input directly into that output.
For a position output, C = [1,0] and D = 0. These matrices change if you reorder the state coordinates. Keep the coordinate order with the model whenever you save or share its numbers.
Check dimensions and physical units
This model has two states, one input, and one output. Its matrix sizes are A: 2 × 2, B: 2 × 1, C: 1 × 2, and D: 1 × 1. Matrix size and physical units answer different questions.
| Quantity | Meaning | Units |
|---|---|---|
| p | Position | m |
| v | Velocity | m/s |
| u | Applied force | N |
| m | Cart mass | kg |
| b | Viscous damping coefficient | N·s/m |
| b/m | Velocity decay rate | 1/s |
| 1/m | Force-to-acceleration coefficient | 1/kg |
The state vector mixes position and velocity units. Each matrix entry must convert its input component into the units of its destination row. For example, A₁₂ = 1 maps velocity directly into ṗ, so that entry is dimensionless; A₂₂ = −b/m has units 1/s.
The product (1/m)u has units N/kg = m/s². Position and acceleration output maps require different units in C and D. A blanket claim that every entry of A has units 1/s would fail for these physical coordinates.
Separate the state from the output
Choose an output according to the question or sensor interface:
| Output y | C | D | Output units |
|---|---|---|---|
| Position p | [1, 0] | 0 | m |
| Velocity v | [0, 1] | 0 | m/s |
| Acceleration v̇ | [0, −b/m] | 1/m | m/s² |
Acceleration follows y = −(b/m)v + u/m. Its nonzero D is direct feedthrough: a finite force step changes acceleration immediately in this ideal model. Position and velocity remain continuous because the force step has no impulse.
For example, a 1 kg cart at rest under a new 1 N force has acceleration 1 m/s² at time 0+. Its position and velocity still equal their initial values. The plus sign in 0+ means immediately after the force takes effect.
This acceleration output describes horizontal coordinate acceleration. An actual accelerometer adds a sensor model, including its frame and specific-force convention. Selecting an output here changes C and D; it adds no sensor noise or state estimator.
A Luenberger observer adds a model-based estimate of the state. Its cart example uses measured position and known force to correct an estimated velocity, with a separate equation for the estimation error.
Keep the initial-condition response
An input does not determine motion by itself. You also need an initial state x₀. A moving cart can continue changing position even when the applied force is zero.
For a constant LTI model, the exact state response has two terms:
x(t) = eAtx₀ + ∫₀ᵗ eA(t−τ)Bu(τ) dτ
The first term is the zero-input response from the initial state. The integral is the zero-state response to the input. Their sum gives the complete state.
Derek Rowell’s MIT notes derive this split and then apply the output equation. At the output, keep the direct term with the input-driven part:
y zero-input = Cx zero-input
y zero-state = Cx zero-state + Du
y = y zero-input + y zero-state
For the acceleration output, dropping Du would remove the immediate force contribution. The widget includes it. Direct feedthrough describes an output map; feedforward control describes a way to choose an input.
Calculate the exact cart motion
Hold force u constant from time zero. For positive damping, define E(t) = exp(−bt/m). Integrating the velocity equation and then position gives:
v(t) = v₀E + (u/b)(1 − E)
p(t) = p₀ + (m/b)v₀(1 − E)
+ (u/b)[t − (m/b)(1 − E)]
At the defaults, m = 1 kg, b = 1 N·s/m, u = 1 N, and p₀ = v₀ = 0. At t = 2 s, E = e⁻² = 0.135335. The resulting position is 1.135335 m, velocity is 0.864665 m/s, and acceleration is 0.135335 m/s².
With b = 0, use the constant-acceleration limit:
v(t) = v₀ + ut/m
p(t) = p₀ + v₀t + ut²/(2m)
These formulas also explain what damping cannot do. With u = 0 and positive b, velocity approaches zero, but position approaches p₀ + (m/b)v₀. No spring restores the cart to the origin.
With a nonzero held force and positive damping, velocity approaches u/b while position continues changing. A velocity limit does not imply a finite final position.
Change the model and inspect its outputs
Start with Force from rest. Switch among position, velocity, and acceleration. A and B stay fixed, while C and D change. The state plot remains the same because selecting an output changes no physical equation.
Try these checks:
- Coast from an offset: zero force still permits motion from the initial state.
- Reverse the initial motion: positive force first slows a cart moving left, then moves it right.
- Remove damping: velocity changes linearly and position follows a quadratic under constant force.
- Choose acceleration and inspect time zero: its zero-state output already contains u/m.
For Reverse the initial motion, m = 2, b = 0.5, u = 1, p₀ = −0.5, and v₀ = −1 in the stated SI units. At 2 s, the position contributions are −2.073877 m from the initial state and +0.852245 m from force. Their sum is −1.221632 m, even though velocity has become positive at 0.180408 m/s.
The state plot uses position horizontally and velocity vertically. Those axes have different units and independent scales; the curve does not depict a path through a room. The time plot separates three signed output responses, with overlapping curves when a contribution vanishes.
The lab samples exact solutions every 0.025 s for drawing. Its inspection readout evaluates the chosen time directly, and it uses stable series near zero damping to avoid subtracting almost equal numbers. The plotted line segments approximate the display curve; the simulation uses no time-stepping integrator.
Connect representations without losing assumptions
With zero initial state, the same cart has force-to-position transfer function 1/[s(ms + b)]. Selecting velocity gives 1/(ms + b). Changing the output can therefore change the input-output description while preserving the two-state physical model.
Transfer functions emphasize that zero-state relation. State-space equations retain the initial state explicitly and can describe several inputs or outputs together. Neither representation removes modeling assumptions.
A nonlinear robot can require ẋ = f(x,u), with a linear model valid only near a chosen operating point. MIT’s state-space text, Chapter 7, develops these model distinctions. Numerical agreement with the cart formulas verifies this calculation; it does not validate a real cart’s mass, damping, or actuator behavior.
The next questions concern access to the state. Can the input move every relevant direction? Can the chosen output reveal an unknown initial state? Controllability and observability make those questions precise.
To check whether a state-space model converges to its equilibrium, try a Lyapunov function. The worked certificate bounds all initial states while its interactive example shows transient growth in ordinary distance.
For two actuators that both affect two outputs, multivariable control compares independent feedback with a matrix decoupler. The same model exposes cross-output motion, model mismatch, and large cancelling commands.
Reproduce the responses in Python
This standard-library example evaluates the closed-form expressions and the undamped limit. It uses ordinary positive damping for the illustrated damped cases. The widget also uses a series for very small positive b to protect numerical precision.
from math import exp, expm1
def cart(m, b, u, p0, v0, t):
if b == 0:
p = p0 + v0*t + u*t*t/(2*m)
v = v0 + u*t/m
else:
decay = exp(-b*t/m)
q = -expm1(-b*t/m)
v = v0*decay + (u/b)*q
p = p0 + (m/b)*v0*q + (u/b)*(t-(m/b)*q)
return p, v, (u-b*v)/m
for name, params in [
("forced", (1, 1, 1, 0, 0)),
("coast", (1, 1, 0, 1, 1)),
("combined", (2, 0.5, 1, -0.5, -1)),
("undamped", (1, 0, 1, 0, 1)),
]:
p, v, a = cart(*params, 2)
print(f"{name} at 2 s: p={p:.6f} m, v={v:.6f} m/s, a={a:.6f} m/s^2")
m, b, u, p0, v0 = 2, 0.5, 1, -0.5, -1
free = cart(m, b, 0, p0, v0, 2)
forced = cart(m, b, u, 0, 0, 2)
print(f"combined position parts: {free[0]:.6f} + {forced[0]:.6f} m")
print(f"combined acceleration parts: {free[2]:.6f} + {forced[2]:.6f} m/s^2")
initial = cart(1, 1, 1, 0, 0, 0)
print(f"rest at 0+: p={initial[0]:.6f}, v={initial[1]:.6f}, a={initial[2]:.6f}")
Expected output:
forced at 2 s: p=1.135335 m, v=0.864665 m/s, a=0.135335 m/s^2
coast at 2 s: p=1.864665 m, v=0.135335 m/s, a=-0.135335 m/s^2
combined at 2 s: p=-1.221632 m, v=0.180408 m/s, a=0.454898 m/s^2
undamped at 2 s: p=4.000000 m, v=3.000000 m/s, a=1.000000 m/s^2
combined position parts: -2.073877 + 0.852245 m
combined acceleration parts: 0.151633 + 0.303265 m/s^2
rest at 0+: p=0.000000, v=0.000000, a=1.000000
Try it yourself
Exercise 1. A cart has m = 2 kg, b = 1 N·s/m, state [p,v]ᵀ = [3 m,−1 m/s]ᵀ, and applied force 4 N. Write A and B, then calculate ẋ. For acceleration output, write C and D and check the output. These hand-calculation values need not fit the widget’s control limits.
Check the matrices and rates
A = [0,1; 0,−0.5] and B = [0;0.5]. Position changes at −1 m/s. Acceleration is (4 − 1 × (−1))/2 = 2.5 m/s².
For acceleration output, C = [0,−0.5] and D = 0.5. Thus y = (−0.5)(−1) + 0.5(4) = 2.5 m/s². The 3 m position does not enter acceleration because the model has no position-dependent force.
Exercise 2. Set m = 1 kg, b = 1 N·s/m, u = 0, p₀ = 1 m, and v₀ = 1 m/s. Calculate position and velocity at 2 s, then their limits as time grows. Which response component supplies this motion?
Check the coasting response
Velocity is e⁻² = 0.135335 m/s. Position is 1 + (1 − e⁻²) = 1.864665 m. As time grows, velocity approaches zero and position approaches 2 m.
All of this is the zero-input response from the initial state. The zero-state response is zero because the applied input is zero. Damping removes velocity; this spring-free model does not drive position back to zero.
Sources and further study
- MathWorks, State-space model reference: continuous-time state and output equations, matrix roles, and dimensions.
- Derek Rowell, MIT 2.14, Time-Domain Solution of LTI State Equations, 2002, Sections 1–3: the matrix-exponential solution and the initial-state, input, and direct-output terms.
- MIT 6.241J, Lectures on Dynamic Systems and Control, Chapter 7: state-space descriptions and linear versus nonlinear models.
Take the chosen C matrix into controllability and observability. A model can contain a state variable that a particular measurement never reveals.