Solution (source code)

= Solution

For a comoving fluid volume, $V\propto a^3$ and $E=\rho c^2V$. The first-law relation $dE=-P\,dV$ gives $c^2(V\,d\rho+\rho\,dV)=-P\,dV$. Since $\dot V/V=3\dot a/a$, the <cosmological perfect-fluid continuity equation> is
$$
\boxed{\dot\rho=-3\frac{\dot a}{a}\left(\rho+\frac P{c^2}\right).}
$$
For the Newtonian energy argument, assume negligible <pressure>, spherical homogeneity, <Newtonian gravity> and constant enclosed mass. A test particle at physical radius $r=a\chi$ has constant specific energy
$$
\epsilon=\frac12\dot r^2-\frac{GM}{r},\qquad M=\frac{4\pi}{3}\rho r^3.
$$
Divide by $a^2\chi^2/2$ and set $k=-2\epsilon/(c^2\chi^2)$ to obtain the <Friedmann equation>
$$
\boxed{\left(\frac{\dot a}{a}\right)^2=\frac{8\pi G\rho}{3}-\frac{kc^2}{a^2}.}
$$
Homogeneity makes $k$ independent of the chosen comoving shell. In the relativistic interpretation it specifies the spatial-curvature sign: positive, zero or negative $k$ gives closed spherical, flat or open hyperbolic spatial geometry, with a conventional rescaling allowing $k=1,0,-1$. <Newtonian mechanics> itself derives the energy constant, not the spatial metric. When <pressure> is appreciable, the general relativistic equations still have the displayed Friedmann form, but the constant-mass Newtonian test-particle derivation cannot be applied without that qualification.