How do I evaluate $\int_{-\infty}^\infty \frac{x\cos{(-\frac{\pi}{2}x)}}{x^2-2x+5} \mathrm{d}x$ using complex analysis? I am having trouble evaluating the following improper integral
$$\int_{-\infty}^\infty \frac{x\cos{(-\frac{\pi}{2}x)}}{x^2-2x+5} \mathrm{d}x$$
It is for an upcoming exam in complex analysis, and I could really use a hint. I think i need to evaluate it using the residue of the integrand, but I have not had any luck. Any suggestions/comments are welcome.
 A: Of course, $\cos(x)$ is even, so you can omit the negative sign in its argument. Consider the integral
$$I=\oint_C\underbrace{\frac{ze^{iz}}{z^2-2z+5}}_{f(z)}\,\mathrm dz$$
over the contour $C$ composed of (1) $\Gamma$, the semicircle centered at the origin with radius $R$, and (2) the line segment joining $-R$ and $R$ on the real axis. It's easy to show the integral along $\Gamma$ vanishes as $R\to\infty$:
$$\left|\int_\Gamma f(z)\,\mathrm dz\right| = \left|\int_0^\pi f(Re^{it})iRe^{it}\,\mathrm dt\right|\le\frac{\pi R^2e^{-R\sin t}}{\left|R-\sqrt 5\right|^2}\stackrel{R\to\infty}\to0$$
Meanwhile, the remaining integral over $[-R,R]$ converges to the integral you want to find.
$f(z)$ has poles at
$$z^2-2z+5=(z-1)^2+4=0 \implies z=1\pm2i$$
with $z=1+2i$ the only pole in the interior of $C$, so by the residue theorem,
$$I=2\pi i\operatorname{Res}\left(f(z),z=1+2i\right)=2\pi i\frac{(1+2i)e^{\frac{i\pi}2(1+2i)}}{4i}=-\pi e^{-\pi}+\frac{\pi e^{-\pi}}2i$$
and the real part corresponds to your original integral, so its value is $\boxed{-\pi e^{-\pi}}$.
A: We will first reshape algebraically to have a better expression to work with.
Let $J$ be the integral to be computed.
$$
\begin{aligned}
J
&:=
\int_{\Bbb R}
\frac{x\; \cos(\pi x/2)}{x^2-2x+5}\;dx
\\
&=
\int_{\Bbb R}
\frac{x\; \cos(\pi x/2)}{(x-1)^2 + 4}\;dx \qquad\text{Substitution: }x=2z+1
\\
&=
\int_{\Bbb R}
-\frac{(2z+1)\; \sin(\pi z)}{4(z^2 + 1)}\;2\; dz
\\
&=
\int_{\Bbb R}
-
\frac{z\; \sin(\pi z)}{z^2 + 1}\;dz
\ .
\end{aligned}
$$
(The integral from the odd function $\sin(\pi z)/(z^2+1)$ vanishes on the real line.)
This post is rather a longer story, showing the "psychological" part of the exams.
Sometimes, the examiner has his own known traps and (s)he will share them or show them in "special cases". There is first a discussion, then the solution. If the discussion feels annoying, please skip and go straightforward to the solution.
So let us fix some "big" $R>0$.
Consider the contour $\gamma(R) =\gamma'(R)\cup\gamma''(R)$, where $\gamma'(R)$ is (the parametrization $z\to z$ of) the real interval from $-R$ to $R$, and $\gamma''(R)$ is
the semicircle parametrization $[0,\pi]\to\Bbb C$, $t\to Re^{it}$.
We (try to) compute the following related integral $K$:
$$
\begin{aligned}
K
&=
\int_{\Bbb R}
\underbrace{\frac{z\; e^{i\pi z}}{z^2+1}}_{=:f(z)} \;dz
\\
&=\lim_{R\to\infty}
\int_{-R}^R 
f(z)\;dz
\\
&=
\lim_{R\to\infty}
\int_{\gamma(R)} 
f(z) \;dz
-
\lim_{R\to\infty}
\int_{\gamma''(R)} 
f(z)\;dz
\ .
\end{aligned}
$$
The first integral is taken on the closed contour $\gamma(R)$, and can be computed using the Residue Theorem, the pole in $i$ only contributes, and
$$
\int_{\gamma(R)} 
f(z) \;dz
=2\pi i
\operatorname {Res}_{z=i}f(z)
=
2\pi i
\operatorname {Res}_{z=i}\frac{ze^{i\pi z}}{(z-i)(z+i))}
=
2\pi i
\operatorname {Value}_{z=i}\frac{ze^{i\pi z}}{(z+i))}
=
\pi i\; e^{-\pi}
\ .
$$
It remains to control in limit the integral on $\gamma''(R)$.
The purely polynomial part $(z\; dz)/(z^2+1)$ is in modulus of the shape
$O(R^2/R^2)=O(1)$, and the exponential part has to be computed explicitly, it leads to convergence to zero for $R\to \infty$.
