Skip to content
Tutorials Center
My learning

Topics

Lesson 38 of 38 · Projects and Practice

Project: A Schwarzschild Orbit Simulator

Build a numerical simulator for orbits around a Schwarzschild black hole, measure perihelion precession against theory, and compute the bending of light with scipy.

In this project you will build a small simulator that integrates the geodesic equation of the Schwarzschild spacetime. You will draw a precessing orbit, check the precession against the formula 6πGM/(c²a(1 - e²)), and compute how much light is bent by a black hole, including rays that would be captured. All code is plain numpy and scipy, written from the equations in the previous lessons.

The model

Use geometric units G = c = 1, and measure all lengths in units of M = GM/c². Then the Schwarzschild radius is r_s = 2, the photon sphere sits at r = 3 and the ISCO at r = 6. With u = 1/r and the angle φ as the independent variable:

  • Massive particle: u'' + u = 1/L² + 3u²
  • Light: u'' + u = 3u²

where primes are derivatives with respect to φ, and L is the specific angular momentum. The light equation is the massive one with the first term removed (it corresponds to L → ∞, since only the shape of the path matters for a null geodesic).

For a bound orbit, we describe the shape by the semi-latus rectum p and eccentricity e, defined through the turning points: periapsis r_p = p/(1 + e) and apoapsis r_a = p/(1 - e), in units of M. Requiring u' = 0 at both points fixes the angular momentum (this is a standard result for Schwarzschild orbits):

L² = p² / (p - 3 - e²)

We start at periapsis (φ = 0, u = (1 + e)/p, u' = 0). In the Newtonian limit p → ∞ this gives back L² = p. A stable bound orbit needs p > 6 + 2e.

This is a numerical model of a test particle in a fixed Schwarzschild geometry. It ignores the particle's own gravity and radiation. It is good for planets, stars near a heavy black hole, and light rays.

Step 1: integrate an orbit

The code below integrates u(φ) over several revolutions, then converts to x = r cos φ, y = r sin φ. A small value of p exaggerates the precession so that it is easy to see.

Python A precessing orbit

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The orbit is a rosette: each loop is a slightly rotated ellipse. The filled disc has radius 2M, the event horizon.

Step 2: measure the precession

To measure the precession, find the angles φ at which r reaches successive minima (maxima of u). The difference between consecutive periapsis angles is 2π + δφ. Compare δφ with the first-order formula 6π/p (for M = 1; in general 6πGM/(c²a(1 - e²)), and a(1 - e²) = p).

Python Measured versus predicted precession

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The ratio is close to 1 for large p and moves away as p gets small, because the formula is only the first-order term in M/p; the full result has corrections of higher order in M/p. Try other eccentricities too.

Step 3: bend light

For a light ray from far away with impact parameter b, set u(0) = 0 and u'(0) = 1/b. Integrate in φ until u returns to zero. If the ray goes straight, the path covers Δφ = π; the excess is the deflection angle α = Δφ - π. Rays that fall inside the horizon never return: we stop them when u reaches 1/2 (r = 2M).

For large b, α ≈ 4M/b, and the next order adds (15π/4)(M/b)². The critical impact parameter below which light is captured is b_c = 3√3 M ≈ 5.196 M.

Python Deflection of light by a black hole

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You should see the deflection grow without limit as b approaches 5.196 M from above (the ray winds around the black hole before escaping), while for b below that, the light is captured. For very large b the numerical value tends to 4M/b; for the Sun (b ≈ R_sun, M/b ≈ 2 × 10⁻⁶) that gives the familiar 1.75 arcseconds.

Ideas for extending the project

  1. Photon sphere: find the impact parameter b for which the ray stays at r = 3M the longest. Compare with 3√3 M.
  2. Eccentricity scan: repeat Step 2 for e = 0, 0.2, 0.5, 0.8 at fixed p. How does the precession depend on e at fixed p?
  3. A plunging orbit: choose p = 7 and e = 0.9, so that periapsis is p/(1 + e) ≈ 3.7 M. What happens to the orbit? Stop the integration at u = 0.5.
  4. Mercury: convert p/M for Mercury (a(1 - e²)/(GM/c²)) and compare 6π/p with the value from the precession lesson. Because p is about 3.9 × 10⁷ M the angle is tiny, which is why numerical integration of Mercury needs very careful tolerances.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. In geometric units with G = c = M = 1, where is the event horizon of the Schwarzschild black hole?

    r_s = 2GM/c² = 2M. The photon sphere is at 3M and the ISCO at 6M.
  2. 2. What does the term 3u² add to the Newtonian orbit equation u'' + u = 1/L²?

    The 3Mu² term (3u² in geometric units) comes from the geometry and makes the orbit non-closed.
  3. 3. For light with impact parameter b much larger than M, the deflection angle is approximately:

    α ≈ 4GM/(c²b); the 'Newtonian' time-part contribution alone would give 2M/b.
  4. 4. Light with impact parameter below 3√3 M ≈ 5.2 M around a Schwarzschild black hole:

    Below the critical impact parameter the ray crosses the photon sphere and falls into the horizon.

Summary

  • In geometric units the geodesics reduce to u'' + u = 1/L² + 3u² (massive) and u'' + u = 3u² (light).
  • Numerical integration with solve_ivp and event detection reproduces perihelion precession close to 6π/p for large orbits.
  • Light is deflected by about 4M/b for large b, with growing deflection near the critical impact parameter 3√3 M, below which it is captured.
  • A simulation is a model: state what it ignores (the test particle's own gravity, radiation, spin) when you report its results.

Back to the course overview: Special and General Relativity