Solution (source code)

= Solution

The <cosmological perfect-fluid continuity equation> is
$$
\dot\rho+3H(\rho+p)=0.
$$
For constant <equation-of-state parameter> $w=p/\rho$, integration gives
$$
\rho_i(a)=\rho_{i,0}a^{-3(1+w_i)}
=\rho_{i,0}(1+z)^{3(1+w_i)},
$$
where $a_0=1$. Define the present <cosmological density parameter>
$$
\Omega_{i,0}=\frac{\rho_{i,0}}{\rho_{c,0}},
\qquad
\rho_{c,0}=\frac{3H_0^2}{8\pi G}.
$$
The <Friedmann equation> then gives
$$
\boxed{H(z)=H_0E(z),\qquad
E(z)=\left[\sum_i\Omega_{i,0}(1+z)^{3(1+w_i)}\right]^{1/2}}.
$$
Spatial curvature may be included as an effective $w=-1/3$ component. Once the parameters are specified, the scale factor follows from the first-order equation $\dot a=aH(a)$, or equivalently
$$
\boxed{t(a)-t(a_i)=\int_{a_i}^a\frac{da'}{a'H(a')}.}
$$