Where did I go wrong evaluating this integral? I wanted to see if complex analysis could help me evaluate the following integral:
$$I=\int_{0}^{\infty} \cos(x) e^{−x} dx $$
It definitely converges due to the exponentially decaying function.
I began by substituting $\cos(x)$ with $\frac{e^{ix}+ e^{−ix}}{2}$:
$$=\int_{0}^{\infty} \frac{e^{ix}+ e^{−ix}}{2} e^{−x} dx $$
Factor the $\frac{1}{2}$:
$$=\frac{1}{2}\int_{0}^{\infty} (e^{ix}+ e^{−ix}) e^{−x} dx $$
Distribute $e^{-x}$:
$$= \frac{1}{2} \int_{0}^{\infty}e^{ix}e^{-x} + e^{-ix}e^{-x} dx $$
Use the exponents rule:
$$= \frac{1}{2} \int_{0}^{\infty}e^{ix-x} + e^{-ix-x} dx $$
Factor:
$$= \frac{1}{2} \int_{0}^{\infty}e^{x(i-1)} + e^{-x(i+1)} dx$$
Using a simple u-substitution we evaluate the integral to be:
$$= \frac{1}{2}\left [\frac{e^{ix-x}}{i-1} + \frac{e^{-ix-x}}{i+1}\right ]_{0}^{\infty}$$
Factor out $e^{-x}$:
$$= \frac{1}{2}\left [\left (\frac{e^{ix}}{i-1} + \frac{e^{-ix}}{i+1}  \right ) e^{-x}\right ]_{0}^{\infty}$$
Combine fractions:
$$= \frac{1}{2}\left [\left (\frac{(i+1)e^{ix}+(i-1)e^{-ix}}{-2}  \right ) e^{-x}\right ]_{0}^{\infty}$$
Expand: 
$$= \frac{1}{2}\left [\left (\frac{ie^{ix}+e^{ix}+ie^{-ix}-e^{-ix}}{-2}  \right ) e^{-x}\right ]_{0}^{\infty}$$
Combine terms with an $i$ coefficient:
$$= \frac{1}{2}\left [\left (\frac{(ie^{ix}+ie^{-ix})+(e^{ix}-e^{-ix})}{-2}  \right ) e^{-x}\right ]_{0}^{\infty}$$
Factor out an $i$:
$$= \frac{1}{2}\left [\left (\frac{i(e^{ix}+e^{-ix})+(e^{ix}-e^{-ix})}{-2}  \right ) e^{-x}\right ]_{0}^{\infty}$$
Split the fraction:
$$= \frac{1}{2}\left [\left (\frac{i(e^{ix}+e^{-ix})}{-2}+\frac{(e^{ix}-e^{-ix})}{-2}  \right ) e^{-x}\right ]_{0}^{\infty}$$
Factor the negative:
$$= -\frac{1}{2}\left [\left (i\frac{e^{ix}+e^{-ix}}{2}+\frac{e^{ix}-e^{-ix}}{2}  \right ) e^{-x}\right ]_{0}^{\infty}$$
The exponential definition of the cosine function is:
$$\cos(x)=\frac{e^{ix}+e^{-ix}}{2}$$
Multiply by $i$:
$$i\cos(x)=i\frac{e^{ix}+e^{-ix}}{2}$$
The exponential definition of the sine function is:
$$\sin(x)=\frac{e^{ix}-e^{-ix}}{2i}$$
Multiply by $i$:
$$i\sin(x)=\frac{e^{ix}-e^{-ix}}{2}$$
We can substitute these back into our problem and get:
$$= -\frac{1}{2}\left [\left ( i\cos(x)+i\sin(x)  \right ) e^{-x}\right ]_{0}^{\infty}$$
Factor put the $i$:
$$= -\frac{i}{2}\left [\left ( \cos(x)+\sin(x)  \right ) e^{-x}\right ]_{0}^{\infty}$$
Let:
$$A=\lim_{x \rightarrow \infty}(\cos(x)+\sin(x))$$
Since $-1 \le \sin(x) \le 1$ for $-\infty \le x \le \infty$ and $-1 \le \sin(x) \le 1$ for $-\infty \le x \le \infty$:
$$-2 \leq \cos(x)+\sin(x) \leq 2$$
This implies:
$$-2 \leq A \leq 2$$
As $x$ goes to infinity $e^{-x}$ goes to $0$
Evaluate bounds of integration:
$$= -\frac{i}{2}\left [A \cdot e^{-\infty} -(\cos(0)+\sin(0))\cdot e^0\right ]$$
$$= -\frac{i}{2}\left [A \cdot 0 -(1 + 0)\cdot 1\right ]$$
$$= -\frac{i}{2}\left [0 - 1\right ]$$
$$= -\frac{i}{2}(- 1)$$
$$= -\frac{i}{2}$$
So:
$$\int_{0}^{\infty} \cos(x) e^{−x} dx = \frac{i}{2}$$
It's obvious that I went wrong somewhere, I just cant figure out where!
 A: You look fine up to here
$\frac{1}{2}\left [\left (\frac{i(e^{ix}-e^{-ix})}{-2}+\frac{(e^{ix}+e^{-ix})}{-2}  \right ) e^{-x}\right ]_{0}^{\infty}$
At this point, I would say:
$\frac{1}{2}\left [\left (\frac{i(e^{ix}-e^{-ix})}{2i^2} - \frac{(e^{ix}+e^{-ix})}{2}  \right ) e^{-x}\right ]_{0}^{\infty}\\
\frac{1}{2}\left [\left (\frac{(e^{ix}-e^{-ix})}{2i} - \frac{(e^{ix}+e^{-ix})}{2}  \right ) e^{-x}\right ]_{0}^{\infty}$
Move back to trig functions.
It looks like you added an extra $i$ factor at this step.
$\frac{(e^{ix}-e^{-ix})}{2i} = \sin x, \frac{(e^{ix}+e^{-ix})}{2} = \cos x\\
\frac{1}{2}[(\sin x - \cos x ) e^{-x}]_{0}^{\infty}\\
$
and evaluate.
$-\frac{1}{2}[(\sin 0 - \cos 0 ) = \frac {1}{2}$
Alternatively, at a much earlier step
$\frac{1}{2}\left [\frac{e^{(ix-x}}{-1+i} + \frac{e^{-ix-x}}{-1-i}\right ]_{0}^{\infty}\\
\frac{1}{2}\left [\frac{e^{-x}(\cos x + i\sin x)}{-1+i} + \frac{e^{-x}(\cos x -i\sin x)}{-1-i}\right ]_{0}^{\infty}\\
\frac{1}{2}e^{-x}\left [\frac{(-1-i)(\cos x + i\sin x) + (-1+i)(\cos x -i\sin x)}{(-1+i)(-1-i)}\right ]_{0}^{\infty}\\
\frac{1}{2}e^{-x}\left [\frac{-\cos x -i\sin x - i\cos x + \sin x -\cos x + i\sin x + i\cos x + \sin x}{2}\right ]_{0}^{\infty}\\
\frac{1}{2}e^{-x}\left [-\cos x + \sin x\right ]_{0}^{\infty}\\
$
A: Hint.
Why not integrating instead
$$
\mathcal{Re}\left(\int_0^{\infty}e^{ix}e^{-x} dx\right)
$$
Easily we find
$$
\int_0^{\infty}e^{ix}e^{-x} dx = \left.\frac{1}{i-1}e^{(i-1)x}\right]_0^{\infty} = \frac{1}{1-i} = \frac{1}{2}+\frac i2
$$
