Converting Higher-Order ODEs to State-Space Representation ($x' = Ax$)
1. What is State-Space Representation?
State-space representation is a mathematical model of a physical system using a set of input, output, and state variables related by first-order differential equations. It's a standard and powerful technique, especially in control systems engineering and for analyzing complex systems.
The general form for a linear time-invariant (LTI) system is:
- State Equation: $x'(t) = Ax(t) + Bu(t)$
- Output Equation: $y(t) = Cx(t) + Du(t)$
Where:
- $x(t)$: The state vector (a column vector containing the state variables). The number of state variables $n$ is equal to the order of the system's differential equation.
- $x'(t)$: The time derivative of the state vector.
- $u(t)$: The input or control vector.
- $y(t)$: The output vector.
- $A$: The state matrix (or system matrix).
- $B$: The input matrix.
- $C$: The output matrix.
- $D$: The feedforward or direct transmission matrix.
This explanation focuses on the homogeneous system ($u(t) = 0$), which takes the form $x' = Ax$.
2. Converting a Higher-Order ODE to State-Space ($x' = Ax$)
Consider a general $n$-th order linear homogeneous ODE with constant coefficients:
Where $y^{(k)}$ denotes the $k$-th derivative of $y$ with respect to time $t$, and $a_n, a_{n-1}, \dots, a_0$ are constants. We assume $a_n \neq 0$.
Steps:
-
Normalize the Equation: Divide by $a_n$ to make the coefficient of the highest derivative equal to 1:
$$y^{(n)} + \frac{a_{n-1}}{a_n} y^{(n-1)} + \dots + \frac{a_1}{a_n} y' + \frac{a_0}{a_n} y = 0$$Let's denote $b_k = a_k / a_n$. The equation becomes:$$y^{(n)} + b_{n-1} y^{(n-1)} + \dots + b_1 y' + b_0 y = 0$$
-
Define State Variables: Define $n$ state variables, typically as follows:
- $x_1 = y$
- $x_2 = y' = x_1'$
- $x_3 = y'' = x_2'$
- $\dots$
- $x_n = y^{(n-1)} = x_{n-1}'$
-
Formulate the State Equations: Find expressions for the derivatives of each state variable ($x_1', x_2', \dots, x_n'$).
- $x_1' = y' = x_2$
- $x_2' = y'' = x_3$
- $\dots$
- $x_{n-1}' = y^{(n-1)} = x_n$
-
$x_n' = y^{(n)}$: Rearrange the normalized ODE from Step 1:
$$y^{(n)} = -b_0 y - b_1 y' - \dots - b_{n-1} y^{(n-1)}$$Substitute the state variables:$$x_n' = -b_0 x_1 - b_1 x_2 - \dots - b_{n-1} x_n$$
-
Write in Matrix Form ($x' = Ax$): Assemble the first-order differential equations.
The state vector is $x = \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix}$.
The derivative is $x' = \begin{bmatrix} x_1' \\ x_2' \\ \vdots \\ x_n' \end{bmatrix}$.
$$ \begin{bmatrix} x_1' \\ x_2' \\ \vdots \\ x_{n-1}' \\ x_n' \end{bmatrix} = \begin{bmatrix} 0 & 1 & 0 & \dots & 0 \\ 0 & 0 & 1 & \dots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \dots & 1 \\ -b_0 & -b_1 & -b_2 & \dots & -b_{n-1} \\ \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_{n-1} \\ x_n \end{bmatrix} $$This gives the state-space representation $x' = Ax$, where the matrix $A$ (in Companion Form) is:$$ A = \begin{bmatrix} 0 & 1 & 0 & \dots & 0 \\ 0 & 0 & 1 & \dots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \dots & 1 \\ -b_0 & -b_1 & -b_2 & \dots & -b_{n-1} \\ \end{bmatrix} $$
Important Note: The characteristic equation of the original ODE ($r^n + b_{n-1} r^{n-1} + \dots + b_1 r + b_0 = 0$) is identical to the characteristic equation of the matrix $A$ ($\det(A - \lambda I) = 0$), where $\lambda$ represents the eigenvalues. The eigenvalues of $A$ are the roots of the characteristic equation of the original ODE.
3. Solving $x' = Ax$ and Examples
The general solution to the homogeneous system $x' = Ax$ depends on the eigenvalues ($\lambda$) and eigenvectors ($v$) of the matrix $A$. The eigenvalues are found by solving $\det(A - \lambda I) = 0$, and the corresponding eigenvectors are found by solving $(A - \lambda I)v = 0$.
The general solution is a linear combination of terms involving $e^{\lambda t}v$. The exact form depends on whether the eigenvalues are real and distinct, real and repeated, or complex conjugates.
Let's use a second-order ODE ($n=2$) for simplicity: $y'' + b_1 y' + b_0 y = 0$.
State variables: $x_1 = y$, $x_2 = y'$. State equations: $x_1' = x_2$, $x_2' = -b_0 x_1 - b_1 x_2$.
Matrix form: $x' = Ax$ where
Characteristic equation for $A$: $\lambda^2 + b_1\lambda + b_0 = 0$.
Example 1: Real and Distinct Eigenvalues
- ODE: $y'' + 3y' + 2y = 0$
- Characteristic Equation (ODE): $r^2 + 3r + 2 = 0 \implies (r+1)(r+2) = 0$. Roots $r_1 = -1$, $r_2 = -2$.
- State-Space Conversion: $b_0 = 2$, $b_1 = 3$.
$$ A = \begin{bmatrix} 0 & 1 \\ -2 & -3 \end{bmatrix} $$
- Eigenvalues of A: $\det(A - \lambda I) = \lambda^2 + 3\lambda + 2 = 0$. Eigenvalues $\lambda_1 = -1$, $\lambda_2 = -2$.
- Eigenvectors of A:
- For $\lambda_1 = -1$: $(A - (-1)I)v = 0 \implies \begin{bmatrix} 1 & 1 \\ -2 & -2 \end{bmatrix} \begin{bmatrix} v_1 \\ v_2 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}$. $v_1 + v_2 = 0$. Choose eigenvector $v_1 = \begin{bmatrix} 1 \\ -1 \end{bmatrix}$.
- For $\lambda_2 = -2$: $(A - (-2)I)v = 0 \implies \begin{bmatrix} 2 & 1 \\ -2 & -1 \end{bmatrix} \begin{bmatrix} v_1 \\ v_2 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}$. $2v_1 + v_2 = 0$. Choose eigenvector $v_2 = \begin{bmatrix} 1 \\ -2 \end{bmatrix}$.
- General Solution (State-Space): $x(t) = c_1 e^{\lambda_1 t} v_1 + c_2 e^{\lambda_2 t} v_2$
$$ x(t) = c_1 e^{-t} \begin{bmatrix} 1 \\ -1 \end{bmatrix} + c_2 e^{-2t} \begin{bmatrix} 1 \\ -2 \end{bmatrix} = \begin{bmatrix} c_1 e^{-t} + c_2 e^{-2t} \\ -c_1 e^{-t} - 2c_2 e^{-2t} \end{bmatrix} $$
- Solution for $y(t)$: $y(t) = x_1(t)$
$$ y(t) = c_1 e^{-t} + c_2 e^{-2t} $$
Example 2: Real and Repeated Eigenvalues
- ODE: $y'' + 4y' + 4y = 0$
- Characteristic Equation (ODE): $r^2 + 4r + 4 = 0 \implies (r+2)^2 = 0$. Root $r = -2$ (repeated).
- State-Space Conversion: $b_0 = 4$, $b_1 = 4$.
$$ A = \begin{bmatrix} 0 & 1 \\ -4 & -4 \end{bmatrix} $$
- Eigenvalues of A: $\det(A - \lambda I) = \lambda^2 + 4\lambda + 4 = 0$. Eigenvalue $\lambda = -2$ (repeated).
- Eigenvector and Generalized Eigenvector:
- For $\lambda = -2$: $(A - (-2)I)v = 0 \implies \begin{bmatrix} 2 & 1 \\ -4 & -2 \end{bmatrix} \begin{bmatrix} v_1 \\ v_2 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}$. $2v_1 + v_2 = 0$. Choose eigenvector $v = \begin{bmatrix} 1 \\ -2 \end{bmatrix}$.
- Find generalized eigenvector $w$ such that $(A - \lambda I)w = v$: $\begin{bmatrix} 2 & 1 \\ -4 & -2 \end{bmatrix} \begin{bmatrix} w_1 \\ w_2 \end{bmatrix} = \begin{bmatrix} 1 \\ -2 \end{bmatrix}$. $2w_1 + w_2 = 1$. Choose $w_1=0$, then $w_2=1$. So $w = \begin{bmatrix} 0 \\ 1 \end{bmatrix}$.
- General Solution (State-Space): $x(t) = c_1 e^{\lambda t} v + c_2 e^{\lambda t} (t v + w)$
\begin{align*} x(t) &= c_1 e^{-2t} \begin{bmatrix} 1 \\ -2 \end{bmatrix} + c_2 e^{-2t} \left( t \begin{bmatrix} 1 \\ -2 \end{bmatrix} + \begin{bmatrix} 0 \\ 1 \end{bmatrix} \right) \\ &= c_1 e^{-2t} \begin{bmatrix} 1 \\ -2 \end{bmatrix} + c_2 e^{-2t} \begin{bmatrix} t \\ -2t + 1 \end{bmatrix} \\ &= \begin{bmatrix} (c_1 + c_2 t) e^{-2t} \\ (-2c_1 + c_2(-2t + 1)) e^{-2t} \end{bmatrix} \end{align*}
- Solution for $y(t)$: $y(t) = x_1(t)$
$$ y(t) = c_1 e^{-2t} + c_2 t e^{-2t} $$
Example 3: Complex Conjugate Eigenvalues
- ODE: $y'' + 2y' + 5y = 0$
- Characteristic Equation (ODE): $r^2 + 2r + 5 = 0$. Roots $r = \frac{-2 \pm \sqrt{4 - 20}}{2} = -1 \pm 2i$.
- State-Space Conversion: $b_0 = 5$, $b_1 = 2$.
$$ A = \begin{bmatrix} 0 & 1 \\ -5 & -2 \end{bmatrix} $$
- Eigenvalues of A: $\det(A - \lambda I) = \lambda^2 + 2\lambda + 5 = 0$. Eigenvalues $\lambda_{1,2} = -1 \pm 2i$.
- Eigenvectors of A:
- For $\lambda_1 = -1 + 2i$: $(A - (-1+2i)I)v = 0 \implies \begin{bmatrix} 1-2i & 1 \\ -5 & -1-2i \end{bmatrix} \begin{bmatrix} v_1 \\ v_2 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}$. From row 1: $(1-2i)v_1 + v_2 = 0$. Choose $v_1=1$, then $v_2 = -1+2i$. Eigenvector $v_1 = \begin{bmatrix} 1 \\ -1 + 2i \end{bmatrix}$.
- Eigenvector for $\lambda_2 = -1 - 2i$ is the conjugate: $v_2 = \begin{bmatrix} 1 \\ -1 - 2i \end{bmatrix}$.
- General Solution (State-Space - Real Form):
Let $\lambda = \alpha \pm i\beta$ and $v = a \pm ib$. Two independent real solutions are $e^{\alpha t}(\mathbf{a} \cos(\beta t) - \mathbf{b} \sin(\beta t))$ and $e^{\alpha t}(\mathbf{a} \sin(\beta t) + \mathbf{b} \cos(\beta t))$.
Here $\alpha = -1$, $\beta = 2$.
$v_1 = \begin{bmatrix} 1 \\ -1 + 2i \end{bmatrix} = \begin{bmatrix} 1 \\ -1 \end{bmatrix} + i \begin{bmatrix} 0 \\ 2 \end{bmatrix}$. So $\mathbf{a} = \begin{bmatrix} 1 \\ -1 \end{bmatrix}$, $\mathbf{b} = \begin{bmatrix} 0 \\ 2 \end{bmatrix}$.
- Real Solution 1: $x_{real1}(t) = e^{-t} \left( \begin{bmatrix} 1 \\ -1 \end{bmatrix} \cos(2t) - \begin{bmatrix} 0 \\ 2 \end{bmatrix} \sin(2t) \right) = e^{-t} \begin{bmatrix} \cos(2t) \\ -\cos(2t) - 2\sin(2t) \end{bmatrix}$
- Real Solution 2: $x_{real2}(t) = e^{-t} \left( \begin{bmatrix} 1 \\ -1 \end{bmatrix} \sin(2t) + \begin{bmatrix} 0 \\ 2 \end{bmatrix} \cos(2t) \right) = e^{-t} \begin{bmatrix} \sin(2t) \\ -\sin(2t) + 2\cos(2t) \end{bmatrix}$
- Solution for $y(t)$: $y(t) = x_1(t)$
$$ y(t) = C_1 e^{-t} \cos(2t) + C_2 e^{-t} \sin(2t) $$
In summary, converting a higher-order ODE to the state-space form $x' = Ax$ provides a systematic way to analyze the system using linear algebra techniques. The solution involves finding the eigenvalues and eigenvectors of the state matrix $A$, which directly correspond to the roots of the original ODE's characteristic equation. The structure of the solution for the state vector $x(t)$, and consequently for the original variable $y(t) = x_1(t)$, depends directly on whether the eigenvalues are real/distinct, real/repeated, or complex conjugates.