Pressure inside a gravitationally bound sphere of uniform density I've looked in many places to find an equation for the pressure inside a sphere of uniform density, but didn't find any, so I decided to take a stab at it. I first found the equation for gravitational acceleration inside a sphere,
$$g(r)=\frac{GM\left(\frac{r}{R}\right)^3}{r^2}=\frac{GMr}{R^{3}}$$
where $M$ is the mass of the sphere, $R$ is the radius of the sphere, and $r$ is the distance from the center. I took this to get the integral of the density times the acceleration of gravity as the distance from the center changes, $$\rho\int_{r}^{R}g\left(x\right)dr,$$
where $\rho$ is the density $\frac{3M}{4\pi R^3}$, and this expanded to
$$\frac{3M}{4\pi R^{3}}\int_{r}^{R}\frac{GMx}{R^{3}}dx=\frac{3GM^{2}}{4\pi R^{6}}\int_{r}^{R}xdx.$$
The resulting equation was
$$\frac{3GM^{2}}{4\pi R^{6}}\left(\frac{1}{2}R^{2}-\frac{1}{2}r^{2}\right)=\frac{3GM^{2}}{8\pi R^{6}}\left(R^{2}-r^{2}\right).$$
Did I get it right?
 A: The expression given in the question is correct. Maybe for some context: the relevant equation for the pressure balancing gravity inside a static, spherically symmetric body is given by Newton's hydrostatic equilibrium:
$$
\frac{dP}{dr}=-\frac{GM(r)\rho(r)}{r^2}=-g(r)\,\rho(r)\longrightarrow dP = - \rho(h)\,g(h)\, dh.
$$
In the present case the enclosed mass is just given by $M(r)=\frac{M r^3}{R^3}$ while the density is constant ($\rho(r)=\rho=\frac{3 M}{4 \pi  R^3}$). Inserting those expressions and integrating from the surface of the sphere $R$ with ($P(R)=0$) to $r$ with $0\le r\le R$ yields the expression in question
$$P(r)=\frac{3 \,GM^2}{8 \pi  R^6}\left(R^2-r^2\right).$$
A similar computation is also possible in General Relativity where this scenario and the corresponding solution is known as interior Schwarzschild solution:
$$
P(r)=\frac{3\, G Z }{4 \pi  R^2 }\frac{\sqrt{1-2 Z r^2/R^2 }-\sqrt{1-2 Z}}{\sqrt{1-2 Z}-\sqrt{1-2 Zr^2/R^2 }},
$$
with the compactness $Z=\frac{G}{c^2}\frac{M}{R}$. Expanding this expression for small $Z$ -- non-compact objects -- yields the Newtonian result
$$
P(r)=\frac{3 Z^2 }{8 \pi  R^4}\left(R^2-r^2\right)+O(Z^3).
$$
For reference the compactness $Z$ of the sun is $\sim 2\times10^{-6}$ while typical neutron stars have compactnesses of order $10^{-1}$.
