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!