The 3D companion evaluates the exact Hirota closed-form solution of the Korteweg–de Vries equation directly, so it can never go numerically unstable. This 2D version instead does what the field actually does in practice: it integrates the raw PDE forward in time step-by-step by finite differences, using no closed-form shortcut at all —
u_t + 6 u u_x + u_xxx = 0
leapfrog time-step (Zabusky-Kruskal, 1965 — the scheme that
first revealed solitons numerically):
u[j]ⁿ⁺¹ = u[j]ⁿ⁻¹ − 2Δt·( 3(u[j+1]²−u[j−1]²)/2Δx
+ (u[j+2]−2u[j+1]+2u[j−1]−u[j−2])/2Δx³ )
The grid only ever sees this update rule — it has no idea the answer is supposed to be two clean soliton bumps. Two independent checks confirm it is nonetheless computing the right physics:
- Mass conservation — ∫u dx is an exact invariant of the KdV equation for any solution; the readout tracks the live drift in this quantity on the periodic grid, which stays at machine-precision (≪0.01%) if the scheme is implemented correctly.
- Deviation vs exact — the same closed-form Hirota formula used by the 3D sim is evaluated alongside, purely as a reference (dashed line), and the readout is the live maximum pointwise gap between the two — small right after a collision, growing slowly afterward from ordinary finite-difference phase drift.
Because a finite grid can only resolve a soliton a few points wide, the wavenumber sliders here are kept narrower (0.7–1.6) than the 3D sim's so every soliton stays well-resolved at the grid's fixed 0.2-unit spacing — a genuine, honest constraint of numerical PDE solving that the exact 3D formula never has to face.
- k₁, k₂ — set each soliton's wavenumber; speed cᵢ = kᵢ² and amplitude = kᵢ²/2, same relations as the exact solution.
- Initial separation — starting gap between the solitons; smaller gaps mean an earlier, sharper collision that is harder for the grid to resolve.
- Time speed — sub-steps the leapfrog scheme multiple times per rendered frame so playback stays smooth even though the stable time-step is tiny (~10⁻³ time units).
The result: watch the same elastic soliton collision as the 3D sim, but built up from nothing more than local grid arithmetic, with two live numbers proving it converges to the same exact answer.