Evaluating an improper integral using the Residue Theorem I have:
\begin{equation}
\int_{-\infty}^{\infty}\frac{x^2}{(x^2+1)(x^2+9)}dx
\end{equation}
and I want to solve it using a complex closed contour on C. I do the following:
\begin{equation}
\int_{-\infty}^{\infty}\frac{z^2}{(z^2+1)(z^2+9)}dz
\end{equation}
which clearly has 4 poles, $\pm i,\pm3i $. The greatest radius of the clontour is thus $\rho=3$, therefore I get the following integral form:
\begin{equation}  
\int_{\gamma_3}\frac{z^2}{(z^2+1)(z^2+9)}dz=2\pi i Res(f;i,+3i)
\end{equation}
which gives for i:
\begin{equation}
Res(i)=\lim_{z\longrightarrow i}(z-i)\frac{z^2}{(z-i)(z+i)(z+3i)(z-3i)}dz=i/16
\end{equation}
and for 3i:
\begin{equation}
Res(3i)=\lim_{z\longrightarrow 3i}(z-3i)\frac{z^2}{(z-i)(z+i)(z+3i)(z-3i)}dz=-i/48
\end{equation}
Plugging into the formula given above, I get:
\begin{equation}  
\int_{\gamma_3}\frac{z^2}{(z^2+1)(z^2+9)}dz=2\pi i (i/16-i/48)=-\frac{\pi}{12}
\end{equation}
But this is not correct, as the integral is negative.  Where is the error?
Thanks!
 A: Also, using Calculus
$$
\frac{x^2}{(x^2+1)(x^2+9)}=\frac{1}{8}\left(\frac{9}{x^2+9}-\frac{1}{x^2+1}\right)
$$
and
$$
\int_{-\infty}^\infty\frac{dx}{x^2+1}=\tan^{-1}(x)\Big|_{x=-\infty}^{x=\infty}=\pi, \qquad
\int_{-\infty}^\infty\frac{dx}{x^2+9}=\frac{1}{3}\tan^{-1}(x/3)\Big|_{x=-\infty}^{x=\infty}=\frac{\pi}{3},
$$
and hence
$$
\int_{-\infty}^\infty\frac{x^2}{(x^2+1)(x^2+9)}=\frac{\pi}{4}.
$$
A: As pointed out in the comments, the residue you found was incorrect:
$$\operatorname{Res}(f(z),3i) = \lim_{z\to3i}(z-3i)f(z) = \lim_{z\to3i}\frac{z^2}{(z^2+1)(z+3i)} = \frac{-9}{(-9+1)(3i+3i)} = \frac9{48i} = -\frac{3i}{16}$$
But what your solution is really missing is an indication of the contour you're using, and showing that the contribution of the integral over the part of the contour not containing the real line is zero. (Maybe you've already done this but omitted the details from your post, but I'll just add the details here for posterity as well as personal practice.)
Presumably, you take $\gamma$ to be the upper half of a circle with its diameter on the real interval $[-R,R]$. Then
$$\oint_\gamma f(z) \, dz = \int_{\gamma_R} f(z) \, dz + \int_{-R}^R f(z) \, dz$$
where $\gamma_R$ refers to the arc $|z|=R \land \operatorname{Im}(z)\ge0$.
As $R\to\infty$, we recover the integral you want to compute from the second integral above. Meanwhile, the first integral is bounded by
$$\begin{align}
\left|\int_{\gamma_R}f(z) \, dz\right| &= \left|\int_0^\pi f\left(Re^{it}\right) \, iRe^{it} \, dt\right| \\[1ex]
&\le \frac{\pi R^3}{\left|R^2e^{2it}+1\right|\left|R^2e^{2it}+9\right|}
\end{align}$$
and this vanishes as $R$ gets arbitrarily large.
