This might be a very basic question, and for years I have gone by simply accepting it as a fact. That whenever the density is uniform the formula $\frac{m}{V}$ gives that uniform value of density and when the density varies the same formula gives the average value of density. However, I don't understand why the latter is true. Why $\frac{m}{V}$ gives the average value of density when it is not uniform?
I have worked something out but I'm not really sure if that's the right way to go about it.
My Work: Let there be a quantity of matter of mass m kg and volume V$mm^3$. The density is non-uniform that is every unit volume (say 1$mm^3 $) doesn't have the same mass. Let $\rho_1 , \rho_2, \rho_3...$ be the masses of unit volumes taken in the quantity of matter. We can write,
$$\rho_1 kg +\rho_2 kg+\rho_3 kg+.........+\rho_n kg=m kg \quad \quad (1)$$ and $$n \text{ mm}^3= Vmm^3 \quad \quad (2)$$
The average density will be, $$\rho_{avg} \frac{kg}{mm^3}=\frac{\rho_1 + \rho_2 +\rho_3 +.....+ \rho_n}{n} \frac{kg}{mm^3}$$ Dividing (1) and (2),
$$\frac{\rho_1 kg +\rho_2 kg+\rho_3 kg+.........+\rho_n kg}{n \text{ mm}^3}=\frac{m kg}{Vmm^3}$$
$$\rho_{avg} \frac{kg}{mm^3}= \frac{m}{V} \frac{kg}{mm^3}$$
$$\rho_{avg} = \frac{m}{V}$$