Every one-step method works on vectors as well as numbers. Any higher-order equation becomes a first-order system, as in Systems in Matrix Form, and then Euler, Heun or RK4 run with each $y$ replaced by a vector $\mathbf{u}$ and each $f$ by a vector function $\mathbf{F}$. The error orders stay the same.
Key idea
Why it works
Worked example: Rewriting a second-order equation
- $u_1 = y$, $u_2 = y'$, so $u_1' = u_2$.
- $y'' = -4y - 0.5y'$, so $u_2' = -4u_1 - 0.5u_2$.
- $A = \begin{bmatrix} 0 & 1 \\ -4 & -0.5 \end{bmatrix}$.
Answer: $\begin{bmatrix} 0 & 1 \\ -4 & -0.5 \end{bmatrix}$
Worked example: Euler on an oscillator
- System: $y' = v$, $v' = -y$, starting at $(1, 0)$.
- Step 1: $y_1 = 1 + 0.1(0) = 1$, $v_1 = 0 + 0.1(-1) = -0.1$.
- Step 2: $y_2 = 1 + 0.1(-0.1) = 0.99$, $v_2 = -0.1 + 0.1(-1) = -0.2$.
- The exact solution keeps $y^{2} + v^{2} = 1$; Euler gives $1$, then $1.01$, then $1.0201$: it multiplies by $1 + h^{2}$ every step, spiraling slowly outward.
Answer: $(0.99, -0.2)$
Worked example: Heun does better
- $\mathbf{k}_1 = \mathbf{F}(1, 0) = (0, -1)$. Predictor: $(1, 0) + 0.1(0, -1) = (1, -0.1)$.
- $\mathbf{k}_2 = \mathbf{F}(1, -0.1) = (-0.1, -1)$.
- $\mathbf{u}_1 = (1, 0) + 0.05\big((0, -1) + (-0.1, -1)\big) = (0.995, -0.1)$.
- Exact: $(\cos 0.1, -\sin 0.1) \approx (0.995004, -0.099833)$.
Answer: $(0.995, -0.1)$
In code, $\mathbf{u}$ is simply an array, and $\mathbf{F}$ returns an array of the same length; the stepping loop does not change at all. Systems also show why stability matters: the components can decay or oscillate at very different rates, set by the eigenvalues of $A$, and a step size must suit all of them. That is the subject of Stability of Euler's Method.
Common mistake