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 is:
where the dimensionless Hubble parameter is:
for a flat universe with negligible radiation, and 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 and . We use the trapezoidal rule with steps:
For standard flat CDM (, , ):
- At : Mpc
- At : Mpc
Your Task
Implement the following functions. All constants must be defined inside each function body.
E_z(z, Omega_m, Omega_Lambda)— returnscomoving_distance_Mpc(z, H0_km_s_Mpc, Omega_m, Omega_Lambda)— returns in Mpc using trapezoidal integration with steps and km/s