Lesson 4 of 15

Comoving Distance

Comoving Distance

When we say a galaxy is "3 billion light-years away", we need to be careful — in an expanding universe, distance is not a single number. The comoving distance is the coordinate distance that factors out the expansion of the universe, remaining constant as the universe grows.

Definition

The comoving distance to a source at redshift zz is:

χ(z)=cH00zdzE(z)\chi(z) = \frac{c}{H_0} \int_0^z \frac{dz'}{E(z')}

where the dimensionless Hubble parameter is:

E(z)=H(z)H0=Ωm(1+z)3+ΩΛE(z) = \frac{H(z)}{H_0} = \sqrt{\Omega_m(1+z)^3 + \Omega_\Lambda}

for a flat universe with negligible radiation, and DH=c/H0D_H = c/H_0 is the Hubble distance.

Why Comoving Distance?

Comoving coordinates expand with the universe. Two galaxies at fixed comoving positions are moving apart only because space itself is expanding — not because they have any peculiar velocity. This makes comoving distance the natural coordinate for large-scale structure.

Numerical Integration

The integral has no closed-form solution for general Ωm\Omega_m and ΩΛ\Omega_\Lambda. We use the trapezoidal rule with N=1000N = 1000 steps:

χ(z)DHΔzi1E(zi)\chi(z) \approx D_H \cdot \Delta z \sum_{i} \frac{1}{E(z_i)}

For standard flat Λ\LambdaCDM (H0=70H_0 = 70, Ωm=0.3\Omega_m = 0.3, ΩΛ=0.7\Omega_\Lambda = 0.7):

  • At z=0.1z = 0.1: χ418.5\chi \approx 418.5 Mpc
  • At z=1.0z = 1.0: χ3303.8\chi \approx 3303.8 Mpc

Your Task

Implement the following functions. All constants must be defined inside each function body.

  • E_z(z, Omega_m, Omega_Lambda) — returns E(z)=Ωm(1+z)3+ΩΛE(z) = \sqrt{\Omega_m(1+z)^3 + \Omega_\Lambda}
  • comoving_distance_Mpc(z, H0_km_s_Mpc, Omega_m, Omega_Lambda) — returns χ(z)\chi(z) in Mpc using trapezoidal integration with N=1000N = 1000 steps and c=299792.458c = 299792.458 km/s
Python runtime loading...
Loading...
Click "Run" to execute your code.