Two bodies pull on each other, so both positions evolve. An N-body model extends the same rule: sum pairwise forces, then update every body from the same time snapshot. It is not a collection of independent orbit drawings; every mass changes the acceleration field for every other mass under the chosen approximation.
Think like a programmer
Use a double loop over unordered pairs, accumulate equal-and-opposite forces or mass-weighted accelerations from one immutable state snapshot, then integrate after all forces are known. Store stable body ids, masses, positions, velocities, force/acceleration arrays, gravitational constant, softening policy and units, boundary/external force policy, integrator/step, pair order/reduction policy, and diagnostics. Updating a body immediately inside the loop introduces ordering bias and changes the model.
Model checklist
Inputs
Body ids/masses/positions/velocities, gravitational constant, softening length/policy, collision/merge policy, external fields/boundaries, pair traversal/reduction order, integrator/step, output times, and tolerance.
State
Snapshot body array, per-body force/acceleration arrays, unordered pair ledger, total momentum/energy/centre-of-mass diagnostics, close-approach data, and refinement history.
Rule
For each pair i less than j, calculate one softened or unsoftened relative contribution, add equal-and-opposite force to the two bodies, then advance every body synchronously under the stated integrator.
Output
Coupled trajectories, pair/close-approach diagnostics, total momentum/energy/centre-of-mass residuals, performance/cost metadata, and model-scope warnings.
Check
Pair force sums to zero; isolated total momentum and centre-of-mass velocity remain bounded under refinement; body-array permutation does not change physical output beyond stated floating-point reduction policy; two-body limit agrees with a reference orbit; softening length zero rejects coincident point bodies while nonzero softening remains finite; changing softening is reported as a force-model change.
Loading the interactive visual. The lesson text and model remain available while it starts.
The pair loop visits indices with i less than j, not both orderings. That avoids double-counting and makes equal-and-opposite force application local. Acceleration is not equal-and-opposite when masses differ; force is. Keep this distinction visible in tests. The centre of mass moves uniformly in an isolated system, so it is a useful aggregate diagnostic alongside total momentum.
Softening replaces the singular point-force behavior below a chosen length scale. It can stabilize close encounters and reduce extreme steps, but it changes force law and small-scale energy/orbit behavior. Record epsilon in physical units and run a sensitivity study. Do not describe a softened close binary as an exact Newtonian point-mass result.
Pairwise work grows roughly as N squared. Neighbour methods, tree codes, meshes, and parallel reductions change approximation and reproducibility properties. A deterministic body-id order or numerically robust reduction policy belongs in provenance when chaotic multi-body paths are compared.
Try this experiment
Prediction: Doubling one body's mass changes both bodies' accelerations, but their center of mass still moves uniformly without external force.
Sketch the unordered pair indices that avoid computing each pair twice. Run two bodies with different masses and verify equal/opposite force plus unequal acceleration. Add a third body, then compare total momentum and centre-of-mass velocity at fixed output times. Introduce softening only for a declared close approach and report which conservation/reference comparison changes with epsilon.
Where this model breaks
Pairwise gravity costs roughly the square of body count. Close encounters also need softening or adaptive techniques to avoid unstable enormous accelerations. The model omits extended-body structure, collisions unless added, relativity, drag, radiation, mass loss, and non-gravitational forces. Chaotic multi-body trajectories can differ under tiny numeric changes even when aggregate invariants remain acceptable.
Summary
N-body physics is a synchronous array problem: accumulate each symmetric interaction once from a shared snapshot, then update together. Track force versus acceleration, centre of mass, momentum/energy, close approaches, softening sensitivity, cost, and deterministic reduction policy.
Glossary
N-body problem: motion of many mutually interacting masses.
Pairwise force: contribution from one unordered body pair.
Softening: numerical modification that limits singular close-range force.
Unordered pair: one body pair visited once, conventionally with i less than j.
Centre of mass: mass-weighted aggregate position whose motion diagnoses isolated internal-force systems.
Self-check
Why update after force accumulation?
Why are pair forces but not accelerations equal and opposite for unequal masses?
What invariant checks internal-force symmetry?
Why can N-body work become expensive?
Sources
S. Aarseth, Gravitational N-Body Simulations.
J. Binney and S. Tremaine, Galactic Dynamics.
Model contract
Treat the lesson as a small function before treating it as a fact to memorize. Give every value a unit, keep only the state needed for the next step, and make the output easy to inspect.
Quantities you set or measure, with units and useful bounds.
State
Values the program must retain to reproduce the next result.
Rule
The relationship or update that turns inputs and state into a result.
Check
A known limit, unit check, invariant, or measured result that can expose a bad model.
Implement the idea as a model
For Two-Body and N-Body Problems, write down the quantities you can control, the values your program must retain, and the result a reader could inspect. In Gravitation, the useful program is not the drawing: it is the smallest explicit model that makes a prediction you can test.
Guided experiment
Prediction: changing one declared input while holding the others fixed should change only the outputs that the model connects to that input. Choose one input, predict the direction of change, then check a limiting case such as zero, a symmetric arrangement, or a familiar low-speed or small-change approximation.
Where this model breaks
This lesson is a teaching model, not a complete simulator. Before using it outside the stated question, check which interactions, scales, uncertainties, boundary conditions, and measurement limits it leaves out.
Summary
Treat Two-Body and N-Body Problems as a contract: named inputs and units enter a rule, the rule produces an observable result, and a known limit or invariant checks whether the implementation deserves trust.
Glossary
Input: a measured value or chosen parameter supplied to a model.
State: the smallest set of values needed to continue or reproduce a model.
Validation: comparing an output with a known result, limit, invariant, or measurement.
Self-check
Which values are inputs, and which values must remain state?
What observable result would tell you the model is behaving as expected?
Which assumption would you test first before applying the model to a real system?
Model review: turn Two-Body and N-Body Problems into a test
Build coupled gravitational simulations by accumulating symmetric pairwise forces before each update.
Name the inputs and units that the gravitation model needs.
Separate the state you must keep from values you can calculate when needed.
Write one rule that maps the current state and inputs to an observable result.
Choose a limiting case, unit check, invariant, or known result before trusting an output.
State one assumption you would change before using this simplified model for a real decision.