Numerical error can look like real orbital behaviour
In an ideal two-body orbit, the spacecraft is only acted on by central gravity. There is no drag, no thrust, and no perturbation. That means the specific mechanical energy should remain constant. If a simulation shows the orbit spiraling outward or decaying inward, the first question should be: is this physics, or is this numerical error?
This page uses Runge–Kutta methods as a space-mechanics diagnostic tool. The goal is not to memorize solver formulas. The goal is to learn how propagation accuracy, timestep size, and conservation checks affect trajectory prediction.
numerical propagation → energy must be checked
Orbit propagation as a numerical experiment
Define the ideal gravitational model and compute initial orbit quantities.
Compare Euler, RK4, RK7, and a reference-like solution visually.
Use specific mechanical energy as a physics diagnostic.
Measure final position error after several revolutions.
Sweep timestep values and see how error grows.
Treat timestep selection as an engineering decision, not a cosmetic setting.
The model: central gravity only
The two-body model assumes a spacecraft moving under Earth’s central gravitational acceleration. In vector form, the acceleration points toward Earth’s centre.
For a clean educational setup, the spacecraft starts at perigee. The initial velocity is computed from the chosen altitude and eccentricity using the vis-viva equation. When eccentricity is zero, the orbit is circular. When eccentricity is above zero, the starting point is perigee of an elliptical orbit.
Seeing orbit distortion directly
Orbit plots make numerical error visually obvious. Euler can spiral outward or distort because it does not preserve the orbital geometry well. RK4 and RK7 stay closer to the reference trajectory, especially when the timestep is reasonable.
Energy drift as a physics diagnostic
Specific mechanical energy is a powerful diagnostic because the ideal two-body problem should conserve it. This plot shows how much the numerical energy changes over time.
Small per-step errors compound
A propagator can look acceptable after one orbit but become poor after many revolutions. This section compares final-state prediction error against a reference-like RK7 solution with a very small timestep.
Timestep is an engineering choice
This is the strongest diagnostic section. Instead of testing one timestep, sweep a range of timesteps and compare final position error and energy drift. This shows how quickly a numerical method becomes unreliable as the timestep increases.
Code patterns for orbit propagation checks
These snippets show the core checks used in this page: two-body acceleration, Runge–Kutta stepping, and specific mechanical energy monitoring.
% Two-body acceleration in 2D
mu = 398600.4418; % km^3/s^2
r = x(1:2);
v = x(3:4);
rnorm = norm(r);
a = -mu * r / rnorm^3;
xdot = [v; a];
% Fixed-step RK4 update
k1 = f(t, x);
k2 = f(t + dt/2, x + dt*k1/2);
k3 = f(t + dt/2, x + dt*k2/2);
k4 = f(t + dt, x + dt*k3);
x_next = x + dt*(k1 + 2*k2 + 2*k3 + k4)/6;
% Specific mechanical energy diagnostic
rnorm = norm(r);
vnorm = norm(v);
energy = 0.5*vnorm^2 - mu/rnorm;
% For an ideal two-body orbit, energy should remain nearly constant.
% If energy drifts strongly, check timestep and integration method.
Orbit propagation must be checked against invariants
A visual orbit plot can reveal spiraling, distortion, or phase error.
Specific mechanical energy is a diagnostic for ideal two-body propagation.
Small per-step errors can become large final-state errors over many orbits.
A timestep that works for one orbit may fail for long propagation.
Higher-order methods help, but only when timestep choice remains reasonable.
The solver is part of the simulation assumption set.