Solution (source code)

= Solution

For a component with the <barotropic equation of state> $P=w\rho$, the <cosmological perfect-fluid continuity equation> is
$$
\dot\rho+3H(1+w)\rho=0.
$$
Using $H=\dot a/a$ makes this a <separable differential equation>:
$$
\frac{d\rho}{\rho}=-3(1+w)\frac{da}{a}.
$$
Taking $a_0=1$ gives the <constant-equation-of-state density scaling>
$$
\boxed{\rho(a)=\rho_0a^{-3(1+w)}
=\rho_0(1+z)^{3(1+w)}}.
$$
The spatially flat <Friedmann equation> and the <cosmological density parameters> therefore give
$$
\boxed{H(z)=H_0E(z)},
\qquad
E(z)=\left[\sum_i\Omega_{i,0}(1+z)^{3(1+w_i)}\right]^{1/2}.
$$
Along a radial light ray, $d\chi=dt/a$. Since the <redshift-time relation> is $dt=-dz/[(1+z)H]$ and $a=(1+z)^{-1}$,
$$
d\chi=-\frac{dz}{H(z)}.
$$
Hence the <comoving radial distance> is
$$
\boxed{\chi(z)=\frac1{H_0}\int_0^z
\frac{dz'}{\left[\sum_i\Omega_{i,0}(1+z')^{3(1+w_i)}\right]^{1/2}}}.
$$