Use real integral to calculate $\int_R \frac{x^2 \cos (\pi x)}{(x^2 + 1)(x^2 + 2)}dx$ Problem :
Evaluate $$\int_{-\infty}^{\infty} \frac{x^2 \cos (\pi x)}{(x^2 + 1)(x^2 + 2)}dx$$
Use only real integral.

What I did : 
$$\int_{-\infty}^{\infty} \frac{x^2 \cos (\pi x)}{(x^2 + 1)(x^2 + 2)}dx$$
$$=2\int_{0}^{\infty} \frac{x^2 \cos (\pi x)}{(x^2 + 1)(x^2 + 2)}dx$$
$$=2\int_{0}^{\infty} \left( \frac{2\cos(\pi x)}{x^2+2} - \frac{\cos (\pi x)}{x^2 + 1}\right) dx$$
Any easy way to calculate this? or idea like differentiate under the integral sign?
 A: If you attempt to use the differentiation under the integral sign as you mentioned, you will run into some issues as I highlight below:
$$I=\int_{-\infty}^\infty\frac{x^2\cos(\pi x)}{(x^2+1)(x^2+2)}dx=2\int_0^\infty\left(\frac{2\cos(\pi x)}{x^2+2}-\frac{\cos(\pi x)}{x^2+1}\right)dx$$
$$I_1=\int_0^\infty\frac{2\cos(\pi x)}{x^2+2}dx\,\to\,I_1(t)=2\int_0^\infty\frac{\cos(tx)}{x^2+2}dx\tag{1}$$
By differentiating under the integral sign twice we obtain:
$$I_1''(t)=-2\int_0^\infty\cos(tx)dx+4\int_0^\infty\frac{\cos(tx)}{x^2+2}dx\tag{2}$$
$$I_1''(t)-2I_1(t)=-2\int_0^\infty\cos(tx)dx\tag{3}$$
Normally by solving this differential equation and applying initial conditions we can get a formula for $I_1(t)$ however this integral on the right does not converge on a value, it instead oscillates so we can say it has an upper and lower bound, but no exact value. This same process could be repeated for an $I_2$ and then let $I=I_1(\pi)-I_2(\pi)$.
This method works well but only in certain situations
A: We can consider a more general function
$$I(t)=2\int_0^\infty\frac{x^2\cos(tx)}{(x^2+1)(x^2+2)}\,\mathrm dx$$
and take its Laplace transform,
$$\begin{align*}
\mathcal{L}\left\{I(t)\right\} &= 2s\int_0^\infty\frac{x^2}{(x^2+s^2)(x^2+1)(x^2+2)}\,\mathrm dx\\ 
 &= 2s\int_0^\infty\left( \frac{1}{(1-s^2)(x^2+1)}+\frac{2}{(s^2-2)(x^2+2)}-\frac{s^2}{(s^4-3s^2+2)(x^2+s^2)}\right )\,\mathrm dx\\ 
 &= \frac{\pi\sqrt{2}}{s+\sqrt{2}}-\frac{\pi}{s+1},\qquad\text{do a bunch of arctan integrals and simplify.}
\end{align*}$$
 
Now if we use the fact that $\mathcal{L}\left\{e^{-\alpha t}\right\}=\frac{1}{s+\alpha}$, we find
$$I(t)=\pi\sqrt{2}e^{-\sqrt{2}t}-\pi e^{-t}.$$
Plugging in $t=\pi$ gives you what you're looking for.
A: Just A Bit of a Generalization
We may actually evaluate the integral 
$$J(a,b;t)=2\int_0^\infty \frac{x^2\cos(tx)dx}{(x^2+a^2)(x^2+b^2)}$$
for some $a, b>0$, $a\ne b$. We see that 
$$J(a,b;t)=\frac{2a^2}{a^2-b^2}f(a;t)+\frac{2b^2}{b^2-a^2}f(b;t)$$
where $$f(q;t)=\int_0^\infty \frac{\cos(tx)}{x^2+q^2}dx\, .$$
We take the Laplace transform of the remaining integral:
$$\begin{align}
\mathcal{L}\{f\}(s)&=\int_0^\infty e^{-st}\int_0^\infty \frac{\cos(tx)}{x^2+q^2}dxdt\\
&=\int_0^\infty \frac{1}{x^2+q^2}\int_0^\infty \cos(tx)e^{-st}dtdx\\
&=\int_0^\infty \frac{1}{x^2+q^2}\text{Re}\int_0^\infty e^{-(s-ix)t}dtdx\\
&=\int_0^\infty \frac{1}{x^2+q^2}\text{Re}\left[\frac1{s-ix}\right]dx\\
&=s\int_0^\infty \frac{dx}{(x^2+q^2)(x^2+s^2)}\\
&=\frac{s}{s^2-q^2}\left[\int_0^\infty \frac{dx}{x^2+q^2}-\int_0^\infty\frac{dx}{x^2+s^2}\right]\\
&=\frac{\pi}{2}\frac{s}{s^2-q^2}\left[\frac{1}{q}-\frac{1}{s}\right]\\
&=\frac{\pi}{2}\left[\frac{1}{q}\frac{s}{s^2-q^2}-\frac{1}{s^2-q^2}\right]\, .
\end{align}$$
Then we define 
$$C(z;s)=\int_0^\infty e^{-st}\cosh(zt)dt=\mathcal{L}\{\cosh(zt)\}(s)$$
$$S(z;s)=\int_0^\infty e^{-st}\sinh(zt)dt=\mathcal{L}\{\sinh(zt)\}(s)$$
So that 
$$C(z;s)+S(z;s)=\int_0^\infty e^{-(s-z)t}dt=\frac{s+z}{s^2-z^2}$$
and 
$$C(z;s)-S(z;s)=\int_0^\infty e^{-(s+z)t}dt=\frac{s-z}{s^2-z^2}\ .$$
Hence 
$$C(z;s)=\frac{s}{s^2-z^2}$$
$$S(z;s)=\frac{z}{s^2-z^2}$$
And 
$$\begin{align}
\mathcal{L}\{f\}(s)&=\frac{\pi}{2q}\left[\mathcal{L}\{\cosh(qt)\}(s)-\mathcal{L}\{\sinh(qt)\}(s)\right]\\
&=\frac{\pi}{2q}\mathcal{L}\{e^{-qt}\}(s)\, .
\end{align}$$
Therefore 
$$f(q;t)=\frac{\pi}{2q}e^{-qt}$$
and
$$J(a,b;t)=\frac{\pi}{a^2-b^2}\left[ae^{-at}-be^{-bt}\right]$$
and your integral is given by 
$$J(\sqrt{2},1;\pi)=\int_{-\infty}^\infty \frac{x^2\cos(\pi x)dx}{(x^2+2)(x^2+1)}=\pi\sqrt{2}e^{-\pi\sqrt{2}}-\pi e^{-\pi}$$
A: You can adapt the methods introduced here to deduce :
$$\int\limits_{0}^{\infty }{\frac{\cos \left( ax \right)}{{{x}^{2}}+{{b}^{2}}}dx}=\frac{\pi {{e}^{-ab}}}{2b}$$
