N-Body Simulation
Numerical integration of gravitational systems with energy and time-step control.
Conceptual context
An N-body simulation follows several objects interacting through gravity. At each instant, the code knows , , masses, and velocities; it computes , then , and finally updates positions and velocities. The challenge is not only obtaining plausible orbits but controlling how numerical integration alters . The decisive parameter is . A large step can invent precession, ejections, or collisions; a smaller step increases computational cost. The central question is how decreases under temporal refinement and when the expected law stops applying.
🟢 Essential level
In a gravitational simulation, every body feels the attraction of all others. The computer repeats a cycle: it computes , obtains , sums , determines , and advances the system through a small . A smaller interval resolves orbital curvature and close encounters more accurately. It does not repair incorrect masses, inconsistent initial conditions, or an untreated singularity. Quality is monitored through , which should remain nearly constant in an isolated system. compares current energy with . A regular trend under decreasing supports convergence. Growing drift, a plateau, or abrupt jumps indicate that the integrator, a close encounter, or the energy definition requires inspection.
Energy and orbital shape must be checked together because either diagnostic alone can hide a different numerical defect. A convincing orbit may accumulate phase error, and a dramatic ejection may disappear when the calculation is repeated at higher resolution. Runs must therefore be compared before accepting a physical conclusion, and the comparison should always report both the energy trend and the orbital shape side by side.
🔵 Formal level
Basic formulas
The gravitational interaction between two bodies follows:
Vector gravitational force
The total force on body i gives through:
Acceleration of one body
Leapfrog separates the update into staggered velocity and new position:
Leapfrog velocity update
Leapfrog position update
Global kinetic energy is:
Total kinetic energy
Potential energy must sum unique pairs:
Total gravitational potential energy
The mechanical total is:
Total mechanical energy
Real student questions
Does energy conservation mean the orbit is exact? No. Phase error can accumulate while energy stays bounded.
Why does Leapfrog use ? Staggering improves geometric structure and limits secular drift.
What if is nearly zero? Relative error becomes unstable; use another normalization scale.
Why do close encounters break convergence? They introduce a much shorter time scale and rapidly changing force.
Is adaptive stepping always better? It resolves encounters efficiently, but may lose symplectic advantages if designed carelessly.
Final synthesis
An N-body simulation is trustworthy when dynamics, units, and integration are coherent. Reducing should decrease predictably until another source dominates. Convergence turns a computed orbit into numerical evidence.
Formal development
This section is part of the complete theory. See the subscription options to access it.
🔴 Structural level
This section is part of the complete theory. See the subscription options to access it.
Deep physical interpretation
This section is part of the complete theory. See the subscription options to access it.
Order of magnitude
This section is part of the complete theory. See the subscription options to access it.
Personalized resolution method
This section is part of the complete theory. See the subscription options to access it.
Special cases and extended example
This section is part of the complete theory. See the subscription options to access it.
Cross-cutting connections and study paths
This section is part of the complete theory. See the subscription options to access it.