← Back to Portfolio
Simulations•

Simulating Chaotic Physics Systems in C++

Why the multi-pendulum is the perfect gateway into deterministic chaos, and how to build a high-fidelity simulator that reveals the butterfly effect in action.


Few physical systems reveal the true nature of chaos as elegantly as the multi-pendulum. It is fully deterministic — governed by classical Newtonian mechanics — yet two trajectories starting a nanometer apart will diverge exponentially until they bear no resemblance to each other within seconds. This is the butterfly effect, made tangible.

Building PendulumSim required solving the Euler-Lagrange equations of motion for a coupled pendulum system. The equations are non-linear second-order ODEs — not analytically solvable for n > 1 pendulums. The workhorse here is the 4th-order Runge-Kutta (RK4) integrator, which achieves significantly better energy conservation than simpler Euler methods over long simulation windows.

One of the most striking outputs of the simulation is the Lyapunov exponent plot. By running twin trajectories with infinitesimally different initial conditions and tracking their divergence over time, the positive Lyapunov exponent becomes visually obvious — confirming the system's sensitivity to initial conditions in a way that no text description can match.

The interactive visualization layer allows users to drag-and-drop initial positions and watch trajectories explode into entirely different phase-space paths. It is, frankly, the most effective demonstration I've built for communicating the concept of chaos to non-specialists.

Author: Noor Ul AminExplore more insights →