Recommended resources
The freely available resources this lesson will direct you to.
Welcome back. Last lesson, you scaled a fixed-centre gravitational model so that its equations could be interpreted without committing to kilometres, seconds, or a particular central mass. That model treated the central body as stationary. Now we remove that approximation: both bodies move, and each feels the gravity of the other.
This is the starting point for a genuine two-body orbital simulation. We will formulate the coupled equations in a common inertial frame, check their directions and units, and express them as the kind of initial-value problem you can eventually integrate in Python. The next lesson will show how a change of coordinates simplifies these coupled equations; for now, the aim is to understand precisely what is being simplified.
One separation, two forces
Consider two isolated Newtonian point masses and . Their positions, measured from the same origin in a non-rotating inertial frame, are and . Their masses are constant, and mutual gravity is the only force in the model.
Define the vector pointing from body 1 to body 2 as
The scalar is their separation. We require : point-mass gravity is undefined when both positions coincide.
Newton’s gravitational law gives the magnitude of the force on either body:
A magnitude is not yet an equation of motion. Gravity is attractive, so the force on body 1 points along , towards body 2. The unit vector in that direction is . Thus
The third power in the denominator does not make gravity an inverse-cube law. The vector in the numerator contributes one power of distance, leaving the force magnitude proportional to .
Newton’s third law gives the force on body 2:
It has the same magnitude and points towards body 1. These are forces on different bodies, not two forces that cancel on either individual body.
Project V Two-Body Problem (Part A) Lecture 58 Numerical Methods for Engineers
Watch Project V Two-Body Problem (Part A) by Jeffrey Chasnov for a visual derivation of the force directions and the coupled equations.
Watch the force derivation. In the diagram, follow which body each force acts on before interpreting its sign. The lecturer writes the separation as body 1’s position minus body 2’s; our \mathbf d points the other way. Both conventions give the same physical forces when their signs are handled consistently.
A reliable way to check a gravitational force formula is to temporarily place the bodies on a line. Suppose body 1 is to the left of body 2. Then points right, and the formula for points right too. Its negative, , points left. Both bodies are pulled towards one another.
Deriving the coupled equations
Apply Newton’s second law to each body separately:
Substituting the gravitational forces and dividing by the respective masses yields the governing equations:
Equivalently, using ,
Notice the apparent exchange of masses: body 1’s acceleration depends on , while body 2’s acceleration depends on . Each body’s own mass cancels between its gravitational force and . That cancellation does not make the two accelerations equal. The forces have equal magnitude, but the less massive body accelerates more.
The equations are coupled because neither acceleration can be evaluated from that body’s position alone. To compute , you need both and ; the same is true of . As the bodies move, their shared separation changes, changing both accelerations.
This also clarifies what “isolated” means here. It does not mean that either body experiences zero force. It means no external forces act on the two-body system. Mutual gravity remains in the model. Atmospheric drag, other gravitating bodies, and departures from the point-mass approximation do not.
Checks that catch modelling mistakes
Before trusting an ODE implementation, test the equations against simple physical requirements. These checks are particularly useful because a sign error can still produce a smooth-looking trajectory.
First, the force magnitude must have the correct units:
Consequently, has units of length divided by time squared, as an acceleration should. Using consistent units matters: positions in kilometres require a value of expressed using kilometres, not its numerical value in SI units.
Second, the forces must be equal and opposite. Multiplying the two acceleration equations by their respective masses gives
This identity follows directly from the paired force formulas. It is a powerful implementation check: if your computed gravitational forces do not sum to zero, you have broken the action–reaction symmetry of this isolated model. In the next lesson, this identity will help us understand the motion of the system as a whole.
Third, compare the equations with the fixed-centre approximation used earlier. If is much larger than , then body 1’s acceleration, proportional to , is very small, while body 2’s acceleration, proportional to , is not. Treating body 1 as fixed can then be an excellent approximation over a suitable interval. Small is not the same as zero, however: the coupled equations allow body 1 to respond.
At the opposite extreme, imagine equal masses initially separated by a distance , with no other forces. Each experiences a force of magnitude , and their acceleration magnitudes are equal. Declaring either mass permanently stationary would impose an artificial constraint absent from the two-body model.
These cases test different aspects of the formulation. The large-mass-ratio case explains why the earlier model often works; the equal-mass case exposes why it is not the general model.
From two acceleration equations to one initial-value problem
You have already converted a second-order gravitational equation into a first-order state equation. The same construction now includes both bodies. Define their velocities by
and stack the variables in a specified order:
In three spatial dimensions, has twelve scalar components. Its first-order equation is
The initial-value problem is completed by specifying, at some initial time ,
along with , , and a consistent value of . The initial positions must be distinct. There is no requirement that either initial position or velocity be zero; the inertial origin need not be attached to a body.
Here is a direct translation of that right-hand side into Python. It evaluates derivatives at a supplied state; it does not yet advance the state through time.
import numpy as np
def two_body_rhs(t, state, m1, m2, G):
"""Derivative of [r1, r2, v1, v2] in a common inertial frame."""
r1 = state[0:3]
r2 = state[3:6]
v1 = state[6:9]
v2 = state[9:12]
d = r2 - r1
d_squared = np.dot(d, d)
if d_squared == 0.0:
raise ValueError("Point-mass gravity is undefined at collision.")
inverse_d_cubed = 1.0 / (d_squared * np.sqrt(d_squared))
a1 = G * m2 * d * inverse_d_cubed
a2 = -G * m1 * d * inverse_d_cubed
return np.concatenate((v1, v2, a1, a2))
The argument t is present because ODE solvers commonly expect it. This particular right-hand side has no explicit time dependence: time affects acceleration through the changing positions in state.
A practical discipline is to keep the state ordering written beside the code. If positions and velocities are packed in one order but unpacked in another, the resulting numerical trajectory may be wrong without producing a Python error. The paired formulas also make two inexpensive checks available before integration: a1 must point towards r2, and m1 * a1 + m2 * a2 should be approximately zero up to floating-point rounding.
Connecting to last lesson’s scaling
The dimensional two-body equations can use the characteristic scales introduced last lesson. Choose a length , a mass , and
Write and . Substitution into the two acceleration equations gives
For two freely moving bodies, is a useful choice. The dimensionless equations then retain two mass fractions whose sum is one. Unlike the fixed-centre model, the individual bodies’ equations need not each have a gravitational coefficient of one: their different accelerations are part of the physics.
This is a useful distinction to preserve in the simulator. Scaling changes the numbers used to describe a system, not which bodies are allowed to move.
Key takeaways
A Newtonian two-body model uses two positions in one inertial frame and one shared separation vector. Gravity produces equal-and-opposite forces, but generally unequal accelerations:
These are coupled equations: both positions are needed to calculate either acceleration. Four initial vectors—two positions and two velocities—turn them into an initial-value problem ready for numerical integration.
Next, we will use the system’s collective motion and the separation between the bodies to simplify these equations, without reverting to the assumption that one body is fixed.