Can you solve this integral with residue theorem How do you compute $$\int_{-\infty}^\infty \frac{\cos x }{e^x + e^{-x}} dx$$
 A: To use the residue theorem, consider
$$\oint_C dz \frac{e^{i z}}{\cosh{z}}$$
where $C$ is a semicircular contour in the upper half plane, along the real axis.  The idea is to show that the integral around the semicircular piece that goes to infinity goes to zero, which in fact it does.  (I leave a proof to the reader.)  What's left is
$$\int_{-\infty}^{\infty} dx \frac{\cos{x}}{\cosh{x}}$$
which is $i 2 \pi$ times the sum of the residues of the poles of the integrand inside $C$.  Note that there are poles at $z=i (n+1/2) \pi \;\; \forall n \ge 1$, $n \in \mathbb{N}$.  The residue at the pole $z=i (n+1/2) \pi$ is $-i (-1)^n e^{-(n+1/2) \pi}$.  Therefore:
$$\int_{-\infty}^{\infty} dx \frac{\cos{x}}{\cosh{x}} = 2 \pi \sum_{n=0}^{\infty} e^{-(n+1/2) \pi} = 2 \pi e^{-\pi/2} \frac{1}{1+e^{-\pi}} = \pi\, \text{sech}{\frac{\pi}{2}} $$
Therefore the stated integral is
$$\int_{-\infty}^\infty dx\: \frac{\cos x }{e^x + e^{-x}} = \frac{\pi}{2} \text{sech}{\frac{\pi}{2}} $$
A: Consider
$$
f(x) := \frac{2 e^{ix}}{e^x + e^{-x}} = \frac{e^{ix}}{\cosh x}
$$
so that half of the integral of the real part of the function is the one in question.
Further consider the contour $C$ which is a rectangle with vertices $-R, R, \frac{i\pi}{2}+R$ and  $i-R$.  Letting $R \to \infty$, the integrals along $R$ to $R+i\pi$ and $i\pi-R$ and $-R$ disappear.  
Then by residue theorem the integral over $C$ equals
$$2 \pi i \operatorname*{Res}_{z=i\frac{\pi}{2}}f(z) = 2\pi i \frac{e^{i(i\frac{\pi}{2})}}{\sinh \left(i\frac{\pi}{2}\right)} = 2\pi e^{-\frac{\pi}{2}}$$
Then solving for the integral by using parametrized representations of the nonzero parts of the contour:
$$
2\pi e^{-\frac{\pi}{2}} = \oint_C f(z)\, dz = \\
\int_{-\infty}^\infty f(z)\, dz - \int_{-\infty}^\infty f (z+i\pi)\, dz = \\
\int_{-\infty}^\infty \frac{e^{ix}}{\cosh x}\, dz + \int_{-\infty}^\infty \frac{e^{i(x+i\pi)}}{\cosh x}\, dz = \\
(1+e^{-\pi})\int_{-\infty}^\infty \frac{e^{ix}}{\cosh x}
$$
Finally
$$
\int_{-\infty}^\infty f(z) = \frac{2\pi e^{-\frac{\pi}{2}}}{1+e^{-\pi}} = \frac{\pi}{\cosh \left(\frac{\pi}{2}\right)}
$$
Divide that answer by two to get your integral.
