Consider a spherical galaxy with volumetric mass density, at a distance $s$ from the center, is given by
$$ \rho = \frac{k}{1+s^3} $$
where $k$ is a constant. Let $k = 25$. Determine the total mass $M$ enclosed within a distance $r$ to the galaxy center (using spherical shells).
I think the total mass, $M$, would be
$$ M = \int_{-r}^r \rho(x)V(x)dr $$ Since $$ m = \rho V $$ Then $$ M = \int_{-r}^r\left(\frac{25}{1+x^3}\right)\left[\frac{4\pi}{3}\left(x^3-R^3\right)\right]dx\\ M = \frac{100\pi}{3}\int_{-r}^r\frac{x^3-R^3}{1+x^3}dx $$
No. The radius $r$ goes from zero to $R$. The mass distribution is spherically symmetric, and we want to sum together the masses of the spherical layers. At radius $r$ the density is $\rho(r)$ and the volume of a thin layer of thickness $dr$ is $4\pi r^2 dr$. Thus $$ M=\int_0^R\rho(r)4\pi r^2dr. $$ The point is to use $m=\rho V$ for each spherical layer separately, since it does not hold for objects with varying density.