# Preparing for exam and don't understand how to calculate this integral via integrating by parts twice

It seems to be a pretty simple integral but I am blanking out on how to find this integral:

$$\int_0^1 e^{-x}\cos(n\pi x) \;dx$$

I tried Mathematica, but it seems to use some formula instead of integrating by parts.

-

I don't believe it matters which part you integrate and which part you take the derivative of. If you took the derivative of $e^{-x}$ the first time, do it for the second integration by parts as well.

If you have done it correctly, you should have an equation with the same integral on each side, yet they won't cancel out. Simply combine like terms and you should have your answer.

-
Oh, I got it. You need to switch the parts for the second integration. Thank you! – dana May 27 '12 at 7:00
@dana Switch the parts? Sounds like the opposite of what I was saying. What did your equation look like after the second integration by parts? – Mike May 27 '12 at 7:07
ooops, this is not what I actually meant to say. My problem was not seing that after the second integration I had two identical (almost) integrals on the both sides of the equation. I guess it's a good time for me to go to bed. Thanks again! – dana May 27 '12 at 7:19

When you’ve a product of an exponential and a sine or cosine, you can split it either way. I’ll set $u=e^{-x}$ and $dv=\cos n\pi x\,dx$, so that $du=-e^{-x}dx$ and $v=\frac1{n\pi}\sin n\pi x$. Then

\begin{align*} \int_0^1 e^{-x}\cos n\pi x\,dx&=\left[\frac1{n\pi}e^{-x}\sin n\pi x\right]_0^1-\int_0^1\frac1{n\pi}\sin n\pi x(-e^{-x})dx\\ &=\frac1{n\pi}\int_0^1 e^{-x}\sin n\pi x\,dx\;. \end{align*}

Now repeat, making sure to split the new integral the same way: $u=e^{-x}$ and $dv=\sin n\pi x\,dx$, so $du=-e^{-x}dx$, $v=-\frac1{n\pi}\cos n\pi x$, and the integral is

\begin{align*} \frac1{n\pi}\int_0^1 e^{-x}\sin n\pi x\,dx&=\frac1{n\pi}\left(\left[-\frac1{n\pi}e^{-x}\cos n\pi x\right]_0^1-\frac1{n\pi}\int_0^1e^{-x}\cos n\pi x\,dx\right)\\ &=\frac1{n^2\pi^2}\left(\left[e^{-x}\cos n\pi x\right]_0^1-\int_0^1e^{-x}\cos n\pi x\,dx\right)\;. \end{align*}

Call the original integral $I$; then

$$I=\frac1{n^2\pi^2}\left(\left[e^{-x}\cos n\pi x\right]_1^0-I\right)\;,$$

so $$\left(1+\frac1{n^2\pi^2}\right)I=\frac1{n^2\pi^2}\left[e^{-x}\cos n\pi x\right]_1^0=\frac1{n^2\pi^2}\left(1-\frac1e\cos n\pi\right)=\frac1{n^2\pi^2}\left(1-\frac{(-1)^n}e\right)\;,$$ since $\cos n\pi=(-1)^n$. Finally,

$$I=\frac{\dfrac1{n^2\pi^2}\left(1-\dfrac{(-1)^n}e\right)}{1+\dfrac1{n^2\pi^2}}=\frac{e-(-1)^n}{e(n^2\pi^2+1)}\;,$$

barring possible careless errors.

-
Thank you! I think there is a small typo in the final equation: numerator should have $n \pi$ not $n^2\pi^2$. Otherwise I was almost there in my initial solution, I just didn't recognize that the integrals on the both sides were almost identical. Too much studying for today. – dana May 27 '12 at 7:22
@dana: Unless I’m asleep (which is possible), the $n^2\pi^2$ is right: I multiplied the four-story fraction by $\frac{en^2\pi^2}{en^2\pi^2}$. – Brian M. Scott May 27 '12 at 7:28
Actually, in the line where you have combined the $I$'s, the $\frac{1}{\pi^2n^2}$ is missing before $[e^{-x}\cos(n\pi x)]^1_0$. So, both of us were a bit off :) – dana May 27 '12 at 7:37
@dana: You are so right; thanks. – Brian M. Scott May 27 '12 at 7:44

Here is another method that applies if you know some complex numbers.

Recall

$$e^{i \theta} = \cos \theta + i \sin \theta$$

In this case we have a $\cos (n \pi x)$, which is the real part of $e^{i n \pi x}$ $$\mathscr{R}(e^{in \pi x}) = \cos(n \pi x)$$

Then we have $$\int_{0}^1 e^{-x} \cos (n \pi x)dx = \mathscr{R} \int_{0}^1 e^{-x}\cdot e^{i n \pi x}$$

-
Interesting. Thanks for the tip. – dana May 27 '12 at 7:19