Is it a calculation trick to make the solution easier or is it a necessary step? I was solving a electrostatic problem, I had to calculate the voulume charge density by using the equation,
$\rho=\epsilon_0\nabla\cdot\vec E$
$\vec E=\epsilon_0(\frac{\lambda Ae^{-\lambda r}}{r}+\frac{Ae^{-\lambda r}}{r^2})\hat r$
I got the divergence as
$\nabla\cdot\vec E=\frac{1}{r^2}\frac{d}{dr}(r^2E_r)=-\frac{\epsilon_0A\lambda^2e^{-\lambda r}}{r} $
The answer is $\epsilon_0 A\left[4\pi\delta^3(r)-\frac{\epsilon_0A\lambda^2e^{-\lambda r}}{r}\right] $
I have the solution manual too where it is given how the answer can be obtained but i dont understand if it is one of the ways to get the answer or is the only way. In the method they used, the separated the $\vec E$ function into $fA$ where $f$ is a scalar function and $A$ is the vector. That is, $\vec E=\epsilon_0 A(e^{-\lambda r}(1+\lambda r))\frac{\hat r}{r^2}$
So, $f$ is $\epsilon_0 A(e^{-\lambda r}(1+\lambda r))$ and $A$ is $\frac{\hat r}{r^2}$
Why was this splitting into $f$ and $A$ necessary?Why was $A$ taken as $\hat r/r^2$ What is wrong in considering the whole thing as $E_r$ and calculating the divergence.? I am aware of the dirac delta function but i dont see why it used here because the function here is not just $1/r^2$ but there is a $e^{-\lambda r} $ too. I want some clarity regarding the calculation of divergence and for what functions we use dirac delta.
 A: Is it necessary to split up the problem this way? No. You can always factor terms however you want and you should always get the same answer.
So why would you choose to factor it this way. Well firstly we need to think about what is "the difficult bit" here. Now taking the divergence of an analytic function is easy. We just have to plug into a formula and differentiate. The subtle thing is what happens when $r \rightarrow 0$ and the electric field blows up.
So now why would we choose to write this as $fA$ with $A = \frac{\hat{r}}{r^2}$? Well the thing to spot here is that $f$ is a nice well behaved function with no singularities and we already know the divergence of $A$ for $r \rightarrow 0$; $A$ is just the coulomb potential. So we have isolated the difficult bit of the problem and turned it into a problem we already understand. From here it is just a case of applying the equivalent of the product rule for the divergence.
$$
\nabla\cdot fA = f\nabla\cdot A + A \cdot \nabla f
$$
Why doesn't the exponential screw up the delta function? Well, in a sense, the delta function only really cares about the behavior of $\hat{E}$, for small $r$ (where the divergence occurs), and for $r \ll \frac{1}{\lambda}$, $e^{\lambda r}\approx 1$, so it does not matter. Also notice that
$$
f(r)\delta(\vec{r}) = f(0)\delta(\vec{r})
$$
as the $\delta$ is $0$ for $r\ne 0$
