# Evaluate a real integral, e.g. $\int_{0}^{\infty}\frac{x^2}{(x^2+1)(x^2+4)}\:\mathrm dx$ with complex analysis

My question is more theoretical, i.e, i cannot quiet understand the "method" itself.

For example $$\int_{0}^{\infty}\frac{x^2}{(x^2+1)(x^2+4)}\:dx$$ I know that the fact of the denominator having no real roots and that $$deg((x^2+1)(x^2+4))-deg(x^2)\geq2$$ are "important informations" but i dont how to apply them. Can someone help me? I know that we are supposed to apply the residue Theorem after, but i cannot understand the steps in order to apply it.

Thank you!

Generally, one tries to find a closed contour $$\Gamma = \Gamma_1 + \dots + \Gamma_n$$ in $$\mathbb{C}$$ such that part of $$\Gamma$$ relates to your original real integral, and the other part is "easy" to evaluate. To be a bit more concrete, let's look at applying this to your example.
Note first that $$I = \int_{0}^{\infty}\frac{x^2}{(x^2+1)(x^2+4)}\:dx = \frac{1}{2} \int_{-\infty}^{\infty}\frac{x^2}{(x^2+1)(x^2+4)}\:dx$$ Let $$f(z)$$ be your integrand evaluated at $$z \in \mathbb{C}$$, and take $$\Gamma_1$$ to be the path from $$-R$$ to $$R$$ for some large $$R > 0$$. We do this because as $$R \to \infty$$, $$\int_{-R}^R f(z) \; dz \to 2I$$ This is all very well and good, but how does it get us closer to finding $$I$$? We have another tool, the residue theorem, which we'd like to apply - but for that we need a closed contour. Let's close our contour in the upper-half plane by taking a semicircle of radius $$R$$ from $$R$$ to $$-R$$, that is $$\Gamma_2 = \lbrace R e^{i \theta} : \theta \in [0, \pi] \rbrace$$ and let $$\Gamma = \Gamma_1 + \Gamma_2$$ be the closed contour formed by the union of these two (very similar to that described in this answer). The trick now is to compute both of $$\int_\Gamma f(z) \; dz \; \text{ and } \; \int_{\Gamma_2} f(z) \; dz$$ Since $$\Gamma$$ is closed, we can apply the residue theorem to the former by computing the residues at the poles of $$f(z)$$ that are enclosed by $$\Gamma$$ (in this case, at $$z = i$$ and $$z = 2i$$, assuming $$R > 2$$).
For the latter, we can try to show that this is negligible in the limit $$R \to \infty$$. A common trick is to use $$\Bigg\lvert \int_{\Gamma_2} f(z) \; dz \Bigg\rvert \leq \operatorname{length}(\Gamma_2) \cdot \sup_{z \in \Gamma_2} \lvert f(z) \rvert$$ Very roughly, we can see this will be the case in this example since $$\operatorname{length}(\Gamma_2) = \pi R$$, whereas on $$\Gamma_2$$ we have $$\lvert f(z) \rvert \approx R^{-2}$$.
Putting this all together, we can now find our original integral by taking the limit $$R \to \infty$$, since we have $$\underbrace{\int_\Gamma f(z) \; dz}_\text{By the residue theorem} = \underbrace{\int_{\Gamma_1} f(z) \; dz}_\text{Desired, gives 2I} + \underbrace{\int_{\Gamma_2} f(z) \; dz}_\text{Known, tends to 0}$$ And so we can rearrange this to find $$\int_{\Gamma_1} f(z) \; dz$$, and hence $$I$$, in terms of known quantities.
Note that sometimes one has singularities along the ideal contour, and this often requires adding in small semicircles of radius $$\varepsilon \to 0$$. Sometimes these contributions vanish in much the same way as our $$\Gamma_2$$ integral did above, but other times these give further contributions (see the answer I linked above for such semicircular "residues") - but the point is we can rewrite our unknown integral in terms of integrals that are "easy" to evaluate via residues and ones that we can argue are negligible in appropriate limits.
Define $$f:\mathbb{C}\mapsto\mathbb{C}$$ by $$f(z)=\frac{z^2}{(z^2+1)(z^2+4)}=\frac{z^2}{(z+i)(z-i)(z+2i)(z-2i)}$$ Then we want to calculate $$\int_0^\infty f(z)\mathrm{d}z=\frac12\int_{-\infty}^\infty f(z)\mathrm{d}z$$where the latter equality holds as $$f$$ is even. Now consider the semi-circular contour, $$C$$, containing the real interval $$(-R,R)$$ and passing through $$Ri$$ on the imaginary axis. The contour integral of $$f(z)$$ over $$C$$ can be found easily for $$R\gt2$$ by applying Cauchy's residue theorem. We get $$\oint_Cf(z)\mathrm{d}z=2\pi i\cdot (\text{Res}(f,i)+\text{Res}(f,2i))=\frac{\pi}3$$Now taking $$R\to\infty$$ the contour integral of $$f(z)$$ over the arc of the semi-circular contour tends to zero so we get $$\int_0^\infty f(z)\mathrm{d}z=\frac12\cdot\frac{\pi}3=\frac{\pi}6$$