How to calculate divergence of the given function? The vector function is:
$$\mathbf{v}=\frac{1}{r^2}\hat{\mathbf{r}}$$
$r$ is the magnitude of position vector and
$\hat{\mathbf{r}}$ is the unit vector along the position vector
Now divergence will be
$$\nabla \cdot \mathbf{v}={\left(\frac{\partial}{\partial x},\frac{\partial}{\partial y},\frac{\partial}{\partial z}\right)}\cdot \mathbf{v}$$
How is this evaluated?
 A: Note, in Cartesian coordinates $r = \sqrt{x^2+y^2+z^2}$ and $\mathbf{r} = x\hat{\mathbf{i}}+y\hat{\mathbf{j}}+z\hat{\mathbf{k}}$.
So, we have $\mathbf{v} =  \left( \frac{1}{r^2} \mathbf{\hat{r}} \right)$. It might be instructve to write the unit vector $\mathbf{\hat{r}} = \frac{\mathbf{\mathbf{r}}}{r}$. This is the definition of the unit vector.
Putting that together we have 
$$\mathbf{v} =  \left( \frac{\mathbf{r}}{r^3}  \right), $$
which is equivalent to
$$\mathbf{v} = \frac{x}{(x^2+y^2+z^2)^{3/2}}\hat{\mathbf{i}}+
\frac{y}{(x^2+y^2+z^2)^{3/2}}\hat{\mathbf{j}}+\frac{z}{(x^2+y^2+z^2)^{3/2}}\hat{\mathbf{k}}.$$
The divergence is then given by 
$$ \nabla \cdot \mathbf{v} = \left( \frac{\partial}{\partial x}, \frac{\partial}{\partial y},\frac{\partial}{\partial z}  \right) \cdot \left( \frac{x}{(x^2+y^2+z^2)^{3/2}},
\frac{y}{(x^2+y^2+z^2)^{3/2}}, \frac{z}{(x^2+y^2+z^2)^{3/2}} \right).$$
Can you take it from here?
As some of the comments mention, using spherical coordinates is far easier in this example.
A: Without switching coordinate systems, this is my favorite method, since it breaks down the identity into small pieces.
Let $\mathbf{r} = x\mathbf{i} + y \mathbf{j} + z \mathbf{k}$, and $r = \sqrt{x^2 + y^2 + z^2}$.  Notice that
\begin{align*}
    \mathbf{v} &= \frac{\mathbf{r}}{r^3}\\
    \mathbf{r}\cdot\mathbf{r} &= r^2 \\
    \nabla r &= \frac{\mathbf{r}}{r} \\
    \nabla \cdot \mathbf{r} &= 3 \\
\end{align*}
We can use the product rule for the divergence, and the power rule for the gradient:
\begin{align*}
    \nabla \cdot \mathbf{v} &= \nabla\cdot(r^{-3} \mathbf{r}) \\
    &= (\nabla r^{-3}) \cdot \mathbf{r} + r^{-3} \nabla \cdot \mathbf{r} \\
    &= (-3)r^{-4}\nabla r \cdot \mathbf{r} + 3 r^{-3} \\
    &= (-3)r^{-4}(r^{-1}\mathbf{r})\cdot \mathbf{r} + 3 r^{-3} \\
    &= (-3)r^{-5}\mathbf{r}\cdot\mathbf{r} + 3r^{-3} \\
    &= (-3)r^{-5}r^2 + 3r^{-3} \\
    &= (-3)r^{-3} + 3r^{-3} = 0
\end{align*}
