Numerical solution of the geodesic equation of the Schwarzschild metric
Updated: December 22, 2024
sympy is a great tool for symbolic computations developed in Python. It has a module for differential geometry that allows you to compute some of the important objects as the Christoffel symbols and curvature objects. I wanted to give it a try and I created a jupyter notebook with a simple test using the Schwarzschild metric and numerically computing some geodesics.
# General imports from itertools import product import matplotlib import numba import numpy as np import matplotlib.pyplot as plt from IPython.display import display, Math
# Basic imports and functions from sympy import latex, symbols, sin, cos, pi, simplify, lambdify, Matrix from scipy.integrate import solve_ivp
from sympy.diffgeom import ( Manifold, Patch, CoordSystem, metric_to_Christoffel_2nd, TensorProduct as TP )
deflprint(v): display(Math(latex(v)))
Create now the coordinate system to define the metric as:
# Get the Christoffel symbols of the second kind. christoffel = metric_to_Christoffel_2nd(metric)
1 2 3 4
# Let's print this in an elegant way ;) for i, j, k in product(range(4), range(4), range(4)): if christoffel[i, j, k] != 0: display(Math(f'\Gamma^{i}_{{{j},{k}}} = ' + latex(christoffel[i, j, k])))
Solving the geodesic equation.
The geodesic equation is
The term is a path depending on .
Let and , then we can translate the geodesic equation into the equations