4.8.27 · D2Numerical Methods

Visual walkthrough — Systems of ODEs — RK4 for systems

1,928 words9 min readBack to topic

We assume you can add, multiply, and read a graph. That is all. Every new symbol is drawn before it is used.


Step 1 — What "solving an ODE" even means (the slope field)

WHAT. We have an unknown quantity that changes over time. Call the time and the quantity . An ordinary differential equation (ODE) is a rule that tells you the slope of at any point:

Let us name every symbol on this line, right where it sits:

  • — the slope, i.e. how fast is rising or falling. Read it "y-prime".
  • — a known formula that, given where you are () and how high you are (), hands you back that slope.

WHY. We do not know itself yet — that is the whole puzzle. But we are handed its slope everywhere. So solving means: start at a known point and walk, always obeying the slope the formula gives.

PICTURE. Figure s01 draws the slope field for : at every point a tiny arrow shows which way to walk. The true solution (the smooth curve ) is the path that stays tangent to every arrow it passes.

Figure — Systems of ODEs — RK4 for systems

Step 2 — One step is really an area (the exact integral)

WHAT. Take one small time-step of width , from to . The exact change in over that step is

Term by term:

  • — the step width, a small chosen number like .
  • — the "add-up-all-the-slopes" symbol; it sums the slope across the whole step. The letter is just a stand-in for time as it sweeps from to .
  • The result is the area under the slope curve over that step.

WHY. "Rise = area under the slope curve" is the fundamental fact of calculus. If we could compute that area exactly, we would land exactly on the true curve. We cannot — because inside is the very thing we don't know. So the entire game becomes: estimate this one area cleverly.

PICTURE. Figure s02 shades the area under the slope curve across one step. Landing accuracy = how well we guess this shaded region.

Figure — Systems of ODEs — RK4 for systems

Step 3 — Simpson's idea: sample the slope at start, middle, end

WHAT. Simpson's Rule estimates an area by sampling the curve at three places — the two ends and the midpoint — and weighting the middle four times as heavily:

Reading the weights: at the start, in the middle, at the end — total , which is exactly the dividing the outside.

WHY THIS TOOL AND NOT ANOTHER. Why Simpson, not just "slope at the start times " (that would be Euler)? Because a single starting slope ignores how the slope bends during the step. Simpson fits a parabola through three samples — it captures curvature, so it is dramatically more accurate for the same step size. That extra accuracy is what will earn RK4 its order-4 rating.

PICTURE. Figure s03 overlays a parabola on three sampled points and shows the weighting as bar heights.

Figure — Systems of ODEs — RK4 for systems

Step 4 — Building the four slope estimates

WHAT. We compute four slope samples, each using a better guess of where we are:

Symbol-by-symbol, what each guess is doing:

  • — slope at the start, using the state we already know.
  • — an Euler half-step forward using : "if the start-slope held, here's the midpoint." = slope there.
  • — a refined midpoint, now using the better slope . = slope there.
  • — a full step using the good midpoint slope , landing near the end. = slope there.

WHY. Each estimate feeds the next: we bootstrap our way to trustworthy midpoint and endpoint slopes without ever knowing the true curve. and are two independent estimates of the same midpoint slope — averaging them cancels errors.

PICTURE. Figure s04 draws all four probe arrows on one step: at the left, the two midpoint probes stacked, at the right.

Figure — Systems of ODEs — RK4 for systems

Step 5 — The weighted average that lands the step

WHAT. Combine the four slopes with Simpson's spirit — but Simpson had only one middle sample, and we have two (). So we split Simpson's weight evenly, giving each middle slope weight :

The weights match the divisor — this guarantees that if the slope were constant, we'd get exactly slope (no bias).

WHY. This precise averaging makes the error terms cancel out to fourth order — the leftover error per step is , tiny (halving shrinks it 32×). Accumulated over a whole interval the global error is ; see Local vs Global Truncation Error.

PICTURE. Figure s05 shows the four slope arrows fanned out and their weighted average arrow (in orange) pointing to the landing point.

Figure — Systems of ODEs — RK4 for systems

Step 6 — Now let become a vector

WHAT. Real problems track several quantities at once (position and velocity, prey and predator). Stack them into one list — a vector:

The bold means "the whole list at once." Crucially, each slope-formula may read every component — that is coupling: the components hold hands.

WHY THE DERIVATION IS FREE. Look back at Steps 4–5: we only ever added things and multiplied by numbers like . Those two operations work identically on a list of numbers as on a single number. So we bold every symbol and change nothing else: Each is now a vector of length .

PICTURE. Figure s06 shows two coupled trajectories advancing in lockstep — one step of the vector recipe moving both at once.

Figure — Systems of ODEs — RK4 for systems

Step 7 — The degenerate & edge cases (never leave a gap)

WHAT / WHY / PICTURE for the corners you must handle:

  • One equation (). The vector collapses to a scalar; bold marks vanish; you recover Step 5 exactly. RK4-for-systems contains scalar RK4 as a special case.
  • Uncoupled system (each depends only on its own ). Then the equations don't hold hands and you could run separate RK4s — but the vector recipe still works and costs nothing extra. Coupling is the general case; independence is the lucky one.
  • The synchronization trap (the one real mistake). Because can read , you must finish the entire vector before forming any intermediate state. If you fully finish RK4 on first, then 's reads a stale, un-advanced — silent, wrong answers.

Figure s07 contrasts the RIGHT order (all components advance together at each stage) against the WRONG order (one component races ahead, feeding stale data to the other).

Figure — Systems of ODEs — RK4 for systems

Worked check — reproduce the parent's Example 1

For , , , one step gives (parent's numbers): matching and . The VERIFY block below recomputes both from scratch.


The one-picture summary

Figure s08 compresses the whole walkthrough: the exact-area problem (Step 2), the three-sample Simpson estimate split into four probes (Steps 3–4), the weighted landing (Step 5), and the vector bolding that makes it all work for coupled systems (Step 6).

Figure — Systems of ODEs — RK4 for systems
Recall Feynman retelling (plain words)

We want to know where a moving thing will be one moment from now. The true answer is the area under its slope curve for that moment — but we can't see that area because it depends on where the thing goes, which is what we're solving for. So we cheat cleverly: we peek at the slope four times. Once at the very start. Twice in the middle — the second peek smarter than the first because it uses what the first peek learned. Once near the end using the best middle guess. Then we average the four peeks, counting the two middle ones double, and divide by six. That average slope, times the step, tells us how far to move. When several things move together holding hands, we do the exact same peeking — but every peek must move all of them at once, never one alone, or they'd be reading each other's out-of-date positions. That is RK4 for systems: four synchronized peeks, one weighted average, over and over.


Connections

  • Parent topic
  • RK4 for a single ODE — the scalar recipe we bolded.
  • Simpson's Rule — the area-sampling RK4 imitates.
  • Reducing higher-order ODEs to first-order systems
  • Euler's method for systems — the one-peek cousin.
  • Local vs Global Truncation Error — why .
  • Stiff systems and stability — where explicit RK4 struggles.