Devlog #42 – Wave 22: Statistics, Special Relativity & Electrochemistry Simulations

Wave 22 adds three new interactive simulations spanning special relativity (relative simultaneity), electrochemistry (the Nernst equation and galvanic cell voltage), and linear algebra (eigenvectors and eigenvalues). Two long-form posts accompany the wave — a Category Spotlight on statistics and probability theory, and a Learning post on differential equations in physics.

Platform Stats after Wave 22

348
Simulations
75
Categories
127
Blog Posts
22
Content Waves
43
Spotlights
32
Learning Posts
42
Devlogs

Wave 22 focus: bridging the abstract mathematics of statistics and linear algebra with concrete physical phenomena — the simultaneity breakdown at relativistic speeds, the voltage shifts in an electrochemical cell, and the geometric meaning of a matrix’s eigenvectors. Each simulation aims to make the equation visible.

Wave 22 Blog Posts

Relative Simultaneity

Einstein’s 1905 thought experiment with a moving train and two simultaneous lightning strikes is one of the most powerful illustrations of special relativity: events that are simultaneous in the platform frame are not simultaneous in the train frame. The simulation makes this concrete with a side-by-side animation of both reference frames.

How the Simulation Works

A train moves at β = v/c from left to right. Two lightning bolts strike the front and rear of the train simultaneously in the platform frame (the bolts are equidistant from the platform observer, so light from both reaches them at the same moment). The simulation shows both frames simultaneously:

Lorentz Transformation Used

t′ = γ(t − vx/c²)
x′ = γ(x − vt)

γ = 1/√(1−β²),  β = v/c

Platform-frame events (simultaneous): t₁ = t₂ = 0
Train-frame events (not simultaneous):
  t′₁ = γ(0 − v·x₁/c²) = −γv·x₁/c²   (rear: x₁ < 0)
  t′₂ = γ(0 − v·x₂/c²) = −γv·x₂/c²   (front: x₂ > 0)
  Δt′ = γv·L/c²   where L = train length in platform frame

Controls include a β-slider (0.1 → 0.95), a play/pause/reset button, and a speed multiplier. An information panel below the canvases shows γ, Δt′ (the simultaneity gap in the train frame), and the Lorentz-contracted train length L′ = L/γ.

Nernst Equation — Galvanic Cell Voltage

The Nernst equation describes how the electromotive force (EMF) of a half-cell or galvanic cell depends on temperature and the concentrations (or activities) of the ionic species involved. It is the fundamental equation of electrochemistry, underpinning batteries, fuel cells, biological ion channels, and analytical chemistry (pH electrodes, ion-selective electrodes).

Simulation Design

The simulation models a complete galvanic cell (e.g., the Daniell cell: Zn | ZnSO4 || CuSO4 | Cu). The user controls:

Nernst Equation

E = E° − (RT/nF) ln Q

E    = cell potential [V]
E°   = standard potential (at 298 K, 1 M, 1 atm) [V]
R    = 8.314 J mol⁻¹ K⁻¹
T    = temperature [K]
n    = moles of electrons transferred
F    = 96485 C mol⁻¹  (Faraday constant)
Q    = reaction quotient  = [products]/[reactants]

At 25°C:  RT/F = 0.025693 V ≈ 25.7 mV
  ⇒ E = E° − (0.05916/n) log₁₀ Q  (Nernst at 25°C)

Half-cell (reduction half-reaction):
  Ox + ne⁻ → Red
  E_half = E°_half − (RT/nF) ln([Red]/[Ox])

The canvas renders a schematic galvanic cell: two beakers connected by a salt bridge, with animated ion migration (cations drifting toward cathode, anions toward anode). An electrode mass indicator shows the anode dissolving (decreasing bar) and cathode plating (growing bar). A live E vs. ln(Q) graph plots the Nernst curve with a moving dot tracking the current operating point. A secondary panel shows ΔG = −nFE and equilibrium constant K = exp(nFE°/RT) for the selected cell.

Eigenvectors & Eigenvalues Visualiser

Eigenvectors are the directions in which a linear transformation acts purely as a stretch (by a factor λ, the eigenvalue). They appear everywhere: principal axes of an ellipsoid (the symmetric matrix in an inertia tensor), normal modes of a coupled oscillator (the stiffness matrix), quantum observables (Hermitian operators in Hilbert space), Google’s PageRank (leading eigenvector of the link matrix), and PCA dimensionality reduction (eigenvectors of the covariance matrix).

Characteristic Polynomial

A = [[a, b], [c, d]]    (2×2 real matrix)

Characteristic polynomial:  det(A − λI) = 0
  ⇒  λ² − (a+d)λ + (ad−bc) = 0
  ⇒  λ² − tr(A)·λ + det(A) = 0

Eigenvalues: λ₁,λ₂ = [tr(A) ± √(tr(A)² − 4·det(A))] / 2

Real if discriminant ≥ 0: tr(A)² ≥ 4·det(A)

Eigenvector for λ_i:  (A−λ_i I)v = 0
  v = [b, λ_i − a]  (or any nonzero scalar multiple)

The visualiser draws on a 540×440 canvas: a unit grid, the standard basis vectors and alongside their images A / A, the unit circle and its image (an ellipse whose semi-axes are aligned with the eigenvectors and scaled by |λ|), and two eigenvector direction lines. Eight presets cover Identity, x-Scale 3, Rotation 90°, Shear, Symmetric (PCA-like), Reflection, and Saddle cases. An info panel shows trace, determinant, eigenvalues, matrix type, and a note when eigenvalues are complex.

Engineering Note: Simultaneous Dual-Canvas Animation

The relative simultaneity simulation renders two canvases side by side within a single requestAnimationFrame loop. Simulation time is stored as a single master clock variable tsim (in units of L/c where L is train length). Each canvas gets its own coordinate transformation: the platform canvas uses tsim directly; the train canvas applies Lorentz transforms to all event coordinates before rendering.

The key implementation detail is that the light pulse radii also expand at c in the transformed frame — confirmed by the fact that c = 1 in natural units is frame-invariant. A small edge-case: when β → 0.999, γ ≈ 22, so the simultaneity gap Δt′ = γvL/c² becomes very large; the animation is automatically scaled so both light pulses remain visible on screen.

What’s Next — Wave 23

Wave 23 will focus on topology and advanced geometry: a Klein bottle and torus genus explorer (Euler characteristic χ = V−E+F), a knot invariant visualiser (Alexander polynomial), and a geodesic Schwarzschild orbit simulator modeling photon and massive-particle paths around a non-rotating black hole. On the content side, Wave 23 will include a Spotlight on General Relativity & Cosmology and a Learning post on Complex Analysis and Conformal Mapping.

Have a simulation idea? The project is open-source. See CONTRIBUTING.md for the contributor guide or open an issue in the repository.