I am doing an indefinite integral,
$$f=\int\frac{r^2}{(r^2 + d^2 -2rd\cos{\theta})^2}dr$$ where $0\leq r< \infty$, $0\leq d< \infty$ and $0\leq \theta \leq \pi$. The integral that I am getting (I used Wolfram Alpha to calculate the integral) is as follows $$f = \frac{1}{4 \sin^2{\theta}}\left[\frac{\tan^{-1}{\left(\frac{r-d\cos{\theta}}{d\sin{\theta}}\right)}}{d\sin{\theta}}+ \frac{2r\cos^2{\theta}-d\cos{\theta}-r}{r^2 +d^2 -2rd \cos{\theta}}\right]$$ which is singular at $\theta = 0,\pi$ and at $d=0$ whereas the integrand was only singular at $(r,\theta)=(d,0)$. I don't understand why is it so. Why am I getting singularities in the solution of the integral at places where there were no singularities in the integrand? Thanks!
The singularity of the expression signals you that the integral tends to diverge. A closer look confirms that the definite integral diverges whenever $\sin\theta=0$ and $r_1\le d\cos\theta\le r_2$, where $r_1 <r_2$ are the integration limits. You can however convince yourself that if $d\cos\theta $ is outside the integration range the definite integral converges: $$ \lim_{\sin\theta\to0}f (r_2,d,\theta)-f (r_1,d,\theta)<\infty. $$