How would you approach this question on definite integral? 
$$\int_{\frac \pi 4}^{\frac \pi 2}\left(2\cos\left(\frac x 2\right) - e^{-x}\right)^2dx$$

I have tried expanding it and then do the integral but it leads to $4 cos(\frac{x}{2})e^{-x}$ in the middle term of the expansion. 
Am i missing something? Is there a "trick" to this? If so how would you approach the question? What are the things that i should keep in mind solving this kind of question? PS. the answer to this is $1.41$ 
 A: There are (at least) two ways.  First, 
$$\int e^{ax}\cos bx \; dx$$ is a standard integral done in most calculus texts.  The trick is to integrate by parts twice and then solve the resulting equation for the integral you want.
Second, you can substitute
$$\cos bx = \frac{e^{ibx} + e^{-ibx}}{2}$$
and multiply everything out. You then just have to integrate exponential functions (and deal with the complex numbers.)
A: $$\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}\left(2\cos\left(\frac{x}{2}\right)-e^{-x}\right)^{2}dx=\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}\left(4\cos^{2}\left(\frac{x}{2}\right)+e^{-2x}-4\cos\left(\frac{x}{2}\right)e^{-x}\right)dx$$$$=4\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}\cos^{2}\left(\frac{x}{2}\right)dx+\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}e^{-2x}dx-4\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}\cos\left(\frac{x}{2}\right)e^{-x}dx$$$$=2\color{green}{\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}1+\cos\left(x\right)dx}+\color{blue}{\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}e^{-2x}dx}-4\color{red}{\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}e^{-x}\cos\left(\frac{x}{2}\right)dx}$$
For the red part (where you have a problem with) using integration by parts we have:
$$\text{I}=\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}e^{-x}\cos\left(\frac{x}{2}\right)dx$$$$=-e^{-x}\cos \left(\frac{x}{2}\right)\Big|_\frac{\pi}{4}^\frac{\pi}{2}-\frac{1}{2}\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}e^{-x}\sin\left(\frac{x}{2}\right)dx$$$$=-e^{-x}\cos\left(\frac{x}{2}\right)\Big|_\frac{\pi}{4}^\frac{\pi}{2}-\frac{1}{2}\left[-e^{-x}\sin\left(\frac{x}{2}\right)\Big|_\frac{\pi}{4}^\frac{\pi}{2}+\frac{1}{2}\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}e^{-x}\cos\left(\frac{x}{2}\right)dx\right]$$$$=-e^{-x}\cos\left(\frac{x}{2}\right)\Big|_\frac{\pi}{4}^\frac{\pi}{2}+\frac{1}{2}e^{-x}\sin\left(\frac{x}{2}\right)\Big|_\frac{\pi}{4}^\frac{\pi}{2}-\frac{1}{4}\underbrace{\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}e^{-x}\cos\left(\frac{x}{2}\right)dx}_\textrm{I}$$
Hence 
$$\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}\cos\left(\frac{x}{2}\right)e^{-x}dx=\frac{4}{5}\left(-e^{-x}\cos\left(\frac{x}{2}\right)\Big|_\frac{\pi}{4}^\frac{\pi}{2}+\frac{1}{2}e^{-x}\sin\left(\frac{x}{2}\right)\Big|_\frac{\pi}{4}^\frac{\pi}{2}\right)\simeq \color{red}{{0.208396}
}$$
For the blue part setting $-2x \mapsto u$ follows:
$$\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}e^{-2x}dx=\frac{1}{2}\int_{-\pi}^{-\frac{\pi}{2}}e^{u}du=\frac{1}{2}\left(e^{\left(-\frac{\pi}{2}\right)}-e^{\left(-\pi\right)}\right)\simeq \color{blue}{0.0823328290435}$$
For the green part using some elementary integrals follows:
$$\int_{\frac{\pi}{4}}^{\frac{\pi}{2}}1+\cos\left(x\right)dx=\frac{\pi}{2}-\frac{\pi}{4}+\sin\left(\frac{\pi}{2}\right)-\sin\left(\frac{\pi}{4}\right)\simeq \color{green}{1.07829138221}$$
Summing the results gives the final answer:
$$2\left(1.07829138221\right)+\left(0.0823328290435\right)-4\left({0.208396}
\right)=1.4053315934635
$$
Which is the the answer you mentioned.
A: $$\int e^{ax}\cos(bx)dx = \frac{e^{ax}}{a^2+b^2}\left(a\cos bx+b\sin bx\right)$$
Here $a = -1, b = \frac12$
A: Hint:
Integrate $$\int \cos\left(\frac x2\right)\exp(-x)\,\mathrm dx$$ by parts twice. The first time, let $f = \cos\left(\dfrac x2\right)$ and $g' = \exp(-x)$. The second time, let $f = -\sin\left(\dfrac x2\right)$ and $g' = \dfrac{\exp(-x)}4$.
