N-body gravitational simulation

Level AdvancedDifficulty ★★★★★Application⌖ Open in the map

What is it?

Integrate the mutual gravity of NN bodies — planets, stars, dark-matter particles. Symplectic integrators (leapfrog) keep orbits stable for billions of steps; tree codes (Barnes–Hut) and FMM cut the cost from O(N2)O(N^2) to O(Nlog⁡N)O(N\log N) or O(N)O(N).

Formulas

x¨i=∑j≠iGmj xj−xi∥xj−xi∥3\ddot x_i = \sum_{j\ne i} G m_j\,\frac{x_j - x_i}{\norm{x_j - x_i}^3}

The mathematics behind it

  • Systems of ODEs★★★★★fundamental

    NN gravitating bodies give 6N6N coupled first-order equations.

  • Runge–Kutta methods★★★★★frequent

    High-order RK is used for accurate short-term orbits; symplectic methods for long-term stability.

  • Phase space★★★★★advanced

    Symplectic integrators preserve phase-space volume (Liouville), which keeps long simulations physically plausible.

  • Three or more gravitating bodies are generically chaotic; long-term planetary predictions have finite horizons.

This page has the essentials. A fuller treatment (intuition, formal definition, worked example) is on the way.

↑ ↓ to navigate · ↵ · Esc