Measuring Chaos in the Browser
By Lucian — builder & engineer, LK Forge
"Chaotic" gets thrown around loosely, so we made it a number. Our physics labs run real integrators in your browser, so we took the exact engines behind two of them — the double pendulum and the bifurcation diagram — and measured how fast order turns into unpredictability. Every figure below comes straight out of that code; the reproduce-this box at the end shows exactly how.
A thousandth of a radian, gone in seven seconds
Release two identical double pendulums from almost the same spot and watch how long they stay in step. We start both from the simulator's default position (173.12° and 178.85° from hanging), then nudge one of them by just 0.001 radian — that's 0.0573°, about a seventeenth of a single degree — and integrate both forward with the same RK4 solver the live lab uses.
Key finding: the two pendulums stay visually locked for about 5.61 seconds, then fully decorrelate by 7.2 seconds. The largest Lyapunov exponent is ≈ 1.095 per second — a Lyapunov time of 0.91 s, meaning the gap between them multiplies by e (≈2.7×) roughly every second.
The straight climb is the whole story: the error doesn't grow steadily, it grows exponentially. Make the initial nudge ten times bigger and you don't lose ten times the time — full divergence just arrives sooner (2.82 s for a 0.05 rad start versus 7.2 s for 0.001 rad). No matter how precisely you measure the start, the unknown part doubles and redoubles until it swamps everything. That is why the third swing of a double pendulum is, for all practical purposes, unpredictable.
Where chaos begins: r ≈ 3.56989
The double pendulum is chaos in continuous motion. The bifurcation
diagram shows the other classic route in, from one of the simplest equations that can misbehave —
the logistic map x → r·x·(1−x). Pick a growth rate r, iterate, and see
what value the population settles onto. For low r it settles on one number. Turn
r up and that single value splits in two, then four, then eight — a
period-doubling cascade — with the splits crowding together until, at a precise
point, the sequence never repeats at all.
Key finding: the cascade lands at r ≈ 3.00 (period 2), 3.449 (4), 3.544 (8), 3.564 (16), accumulating into chaos at r ≈ 3.56989. About 39% of the range r ∈ [3, 4] is chaotic; the rest still settles to a finite cycle.
The spacing between successive doublings shrinks by a fixed ratio. From our own numbers that ratio comes out to 4.749 then 4.652 — converging on the Feigenbaum constant, 4.669. This is the strange, beautiful part: that same 4.669 governs the double pendulum too, and dripping taps, and heart-rhythm models. The route into chaos is universal — it doesn't care what the underlying equation is. Two labs, one constant.
Reproduce this
Every number and both charts come from scripts/gen-chaos-study.mjs, which copies the
exact engines the live labs ship. No dependencies, fully deterministic — you get the same output
every run. The two engines are just these:
// Double pendulum — one RK4 step of the equations of motion (g = 9.8, DT = 1/240)
function deriv([th1, w1, th2, w2]) {
const d = th1 - th2, cd = Math.cos(d), sd = Math.sin(d)
const den = 3 - Math.cos(2*th1 - 2*th2) // 2*M1 + M2 - M2*cos(...), equal masses
const a1 = (-g*3*Math.sin(th1) - g*Math.sin(th1 - 2*th2)
- 2*sd*(w2*w2 + w1*w1*cd)) / den
const a2 = (2*sd*(w1*w1*2 + g*2*Math.cos(th1) + w2*w2*cd)) / den
return [w1, a1, w2, a2]
}
// Logistic map — the whole of it
const next = (x, r) => r * x * (1 - x)
Run two pendulums 0.001 rad apart and time the separation → 7.2 s to full
divergence. Iterate the logistic map while raising r and record where the cycle
length doubles → chaos at r ≈ 3.56989. That's the entire study.
See it move
Open the double pendulum, turn on the ghost twin, and watch the two arms trace each other for a few seconds before splitting for good — the 7.2-second number, live. Then drag the growth-rate slider on the bifurcation diagram across r ≈ 3.56989 and see the single line shatter into a band. Both run entirely in your browser; nothing is uploaded.
Keep exploring the physics labs
- Lorenz Attractor — the weather-model system whose butterfly shape gave "the butterfly effect" its name.
- Reaction–Diffusion — simple local rules that grow the spots and stripes of chaos's creative cousin.
- All the physics labs — orbits, collisions, waves, fields and fluids, each running real physics in the browser.