[Physics] Finding mass density of a sphere

homework-and-exercisesnewtonian-gravity

If the gravitational field vector is independent of the radial
distance within a sphere, find the function describing the mass
density $\rho (r)$ of the sphere.

I uses the divergence of $\bf g$:

$$\begin{align}
\nabla \cdot\vec g &= 4\pi G\rho \\
g &= -GM\frac {\hat r}{r^2}
\end{align}$$
so I can take the divergence which is (using spherical)
$$\nabla \cdot \vec g=-4\pi G M$$
So $\rho=-M$

This does not make sense to me at all. The mass density should be in units of mass/volume, but I just get mass. Any help as to where I am going wrong?

Best Answer

In cases like this, you should back up step by step from the point at which you notice a unit problem. At each step, check the units in the equation and see if they are consistent. If they are, then you know you made a mistake after that step; if you get to the first step and you find inconsistent units, you know you're using an incorrect equation.

Related Question