Prelude · The big idea
The mathematics of change
A swinging pendulum, a swirling fluid, a wheeling flock — the systems worth studying are usually in constant motion. You can't sum them up with one fixed number, because that number won't sit still. What you can pin down is the rule for how it changes.
And here's what makes them hard, and beautiful: nothing changes on its own. Each parcel of fluid is pushed by the ones around it — and pushes them right back. Each boid steers by its neighbors, who are steering by it. A pendulum's position decides how hard gravity pulls, and that pull decides where it swings next. The output is the input — everything wired to everything, including itself, an instant later.
So instead of a formula for the final answer, we write the rule of change: how fast each thing moves, given where everything is right now. That's a differential equation. And because change is driven by forces, the rule is usually about acceleration — the second derivative, θ̈ — which itself depends on the current state. The loop closes. You can't skip ahead; you let it run.
Our pendulum is the gentlest version of this whole idea — one variable (its angle θ), one force (gravity). Watch its loop turn: where it is sets how it accelerates (θ̈), which changes how fast it moves (θ̇), which changes where it is — and round again.
The feedback loop position → acceleration → velocity → position, forever
Notice it already takes two quantities — position and velocity — each feeding the other, even in the simplest case. (Gravity acts through the position; later, friction will act through the velocity.)
Master the loop here, with one variable, and you've got the shape of every harder one — the fluid, the flock, all of it. Let's meet it.
Step 1 · The pendulum
When a swing stops being a sine wave
A pendulum is the first differential equation most people meet. Gravity pulls the bob back toward the bottom, and the result is a swing that repeats forever. For a small swing, that motion is almost a perfect sine wave. But that sine is a lie we tell ourselves to make the math linear. The real pendulum obeys a nonlinear equation, and the bigger the swing, the more it drifts away from the sine.
To follow a swinging pendulum, the simplest thing to watch is its angle — how far it has swung from hanging straight down. We'll call that angle θ.
But the pendulum never holds still at one angle; it's always moving. How fast the angle changes is its velocity. In calculus that's all a velocity is — a rate of change: how much something shifts from one moment to the next. So velocity is just the rate of change of the angle.
And the pendulum doesn't even move at a steady speed: it races through the bottom and slows almost to a stop at the top, so its velocity is itself constantly changing. The rate at which the velocity changes is the acceleration — and that's the piece gravity acts on.
-
Position — the angle
Where the pendulum is right now: θ, its angle away from straight down.
-
Velocity — how fast the angle changes
The rate of change of the angle, written θ̇ — the dot on top just means "rate of change of." Fastest at the bottom, zero for an instant at each turning point.
-
Acceleration — how fast the velocity changes
The rate of change of the velocity, written θ̈ — two dots, the rate of change of the rate of change. This is the one gravity sets directly.
Gravity sets that acceleration. Writing it down — acceleration equals the pull of gravity along the arc — gives the pendulum's equation of motion:
The equation of motion — hover a colored term to see what it means.
Pure gravity, no air resistance. The sin θ is what makes this nonlinear — and what eventually pulls the swing off the sine.
Its small-angle approximation — an exact sine wave.
For small swings sin θ ≈ θ, collapsing the equation into a cosine at a single fixed frequency — the gray reference in the trace.
The pendulum — gravity decomposed on the bob
Angle θ(t) — the solution of real pendulum small-angle sine
Notice how it deviates. Each push of energy widens the swing. The real motion (blue) falls a little further behind the gray sine every time — the small-angle approximation quietly breaks down.
So how do we actually solve it?
Here's the catch: unlike the small-angle version, the full equation θ̈ = −(g/L)·sinθ has no clean formula for θ(t). You can't write the angle as a tidy function of time the way you can for the sine wave.
Why not? The small-angle version works because the restoring pull is exactly proportional to the angle — twice as far out, twice the pull back. A cosine fits that beautifully: its curvature is always a fixed multiple of its own height, so it stays consistent with itself forever. But sin θ bends. Past roughly 20°, the real pull grows slower than the angle does, and no cosine or exponential can keep in step with a feedback that curves like that.
You can even show it's hopeless on purpose: using energy conservation, "find θ(t)" collapses into an integral with the square root of a cosine tucked inside — and that integral has no answer in terms of ordinary functions. Mathematicians met this exact shape so often they gave it a name: an elliptic integral. It isn't that we're not clever enough — it's provably impossible to write θ(t) with elementary functions.
So instead of solving for a formula, we let the computer march the pendulum forward: start from a known state — an angle and a speed — use the equation to nudge it a few milliseconds ahead, then repeat. We'll see exactly how that stepping works in Step 2, where it has a natural home — each step nudges a single point through the space of all possible states.
Step 2 · Phase space
Every state at once
We just saw there's no formula for θ(t) — we can only march the pendulum forward, one tiny step at a time. So let's change the question. Instead of asking "where is the pendulum at time t?", we ask: what are all the states it could ever be in?
A complete snapshot of the pendulum needs just two numbers: its angle θ (where it is) and its angular velocity θ̇ (how fast, and which way, it's moving). Nothing else — those two fix everything about the next instant.
Picture two number lines. The angle runs from −180° to +180° — one full turn, where ±180° is balanced at the very top. The speed θ̇ is 0 when the pendulum is momentarily stopped, positive swinging one way, negative the other.
Stand them at right angles and every possible state becomes a single point on a 2-D map — the phase space. Below, a tiny pendulum sits at a grid of these states: θ across, θ̇ up the side (the teal arrow is its speed). The top and bottom rows are moving fast enough to swing all the way over the top.
A pendulum for every state angle across · angular velocity up the side
Each pendulum is one point. Collapse every little pendulum down to a dot and you're left with a map of all its states — the phase plane, with angle along the bottom and angular velocity up the side.
Which way does each state go?
Lining the states up is one thing — it doesn't tell us where they want to go. The equation answers that at every point: it gives the state's rate of change, its phase velocity — how fast both numbers, the angle and its speed, are changing right now:
Read the two parts. The top (horizontal) component is the angular velocity θ̇ — which way the angle is already heading. The bottom (vertical) component is the angular acceleration θ̈ — gravity's pull, the exact quantity Step 1's equation hands us, θ̈ = −(g/L)·sinθ. So the little arrows below are not velocity vectors and they're not pure acceleration either — each one is this combined tendency, velocity across and acceleration (θ̈) up, rooted at the state it belongs to. Let's build it up one effect at a time.
The flow each arrow = (θ̇, θ̈) — velocity across, acceleration up · bright dot = a sample path
Velocity moves position. On its own, every state just slides sideways — to the right if it's moving one way, left the other, faster the higher up it sits. Nothing yet pulls it back.
No friction — energy conserved
With friction — energy leaks away
Step 3 · The phase portrait
A weather of states
One path told us how a single pendulum lives out its life. Now release a few hundred at once — every starting angle and speed — and let them all flow along the field together.
What emerges is the pendulum's entire repertoire in one picture: nested loops in the middle (gentle swinging), streaming bands across the top and bottom (spinning all the way over the top), and the knife-edge separatrix dividing them — the exact energy that just barely reaches the top. Every streak is a single state carried by the flow, like a parcel of air on a weather map.
The whole phase portrait hundreds of states flowing along the field at once · brighter = faster
Frictionless — it circulates forever. Closed loops in the middle (swinging), streaming bands across the top and bottom (spinning over the top), split by the knife-edge separatrix.
But how faithfully can a computer actually trace these paths? That's the next step.
Step 4 · Stepping & stability
When the step is too big
We've trusted that little stepper to draw every path on this page. But how far can you trust a numerical step? Let's zoom in on a single vortex and stress-test it.
The loops swirling around the center are vortices — a state circling a fixed point, exactly like the swirls in the incompressible-fluid section of this site. Here the "fluid" is the flow of states itself, and with a little friction in play (θ̈ = −(g/L)sinθ − µθ̇) each loop slowly spirals inward — a draining vortex, winding down toward rest.
The shape also tells you about stability. The center at the bottom (θ = 0) is stable: nudge a state and it spirals right back down to rest. The tops at ±180° are saddles — unstable: the faintest nudge sends a state careening away along the separatrix. Now watch what the stepper does in here.
A vortex, up close background arrows = the slope (θ̇, θ̈) the stepper follows · orange = a big step · blue = a small step
The naive step (Euler) just leaps along the current arrow. With friction, the real pendulum loses energy and should spiral inward — which the small blue step does, hugging the arrows. But the big amber step overshoots so badly it fakes energy and spirals outward, the wrong way entirely. Now switch on RK4.
RK4 = 4th-order Runge–Kutta. "Samples the slope four times" means: within a single step it measures the slope — the background arrow (θ̇, θ̈) — at four points (the start, two trial midpoints, and the end), then blends them into one weighted move. Four slope evaluations per step.