# Evaluating $\frac{1}{\pi}\int^{\pi}_{-\pi} e^{x}\cos (kx) \text{dx}$

I am trying to solve this definite integral. I have tried applying this method,but unfortunately I have encountered a problem when trying to approximate the answer. Using integration by parts.

$$\frac{1}{\pi}\int^{\pi}_{-\pi} e^{x}\cos (kx) \text{dx} \\ \frac{1}{\pi}\int u\; dv = [u\;v]^\pi_{-\pi}-\int_{-\pi}^{\pi} v\;du \\dv=e^x \quad u= \cos(kx) \\ v = e^x \quad du = -k\sin(kx) \\ =\cos(kx)e^x-\left[\int e^x\cdot-k \sin(kx) dx \right] \\ dv = e^x \quad u = -k\sin(kx)) dx \\v = e^x \quad du = -k^2\cos(kx)\\ \cos(kx)e^x-[-k\sin(kx)e^x] - \left[\int e^x\cdot-k^2\cdot \cos(kx)dx\right] \\ \text{Apply Linearity} \\ \int^{\pi}_{-\pi} e^{x}\cos (kx) \text{dx}=e^x\cos(kx)-(-ke^x\sin(kx))+k^2\int e^x\cos(kx) dx \\ L = \int^{\pi}_{-\pi} e^{x}\cos (kx) \text{dx} \\ L=e^x\cos(kx)-(-ke^x\sin(kx))+k^2 \cdot L \\ 1=e^x\cos(kx)-(-ke^x\sin(kx))+k^2 \\ \text{However the answer is supposed to be} \\ a_k = \frac{(-1)^k \cdot (e^\pi-e^{-\pi})}{\pi(1+k^2)}$$

## 2 Answers

You are almost there. First do the indefinite integral, without the limits of integration, and for now don't think about dividing the whole thing by $\pi$. So you wish to evaluate $$L:=\int e^x\cos kx\,dx.$$ Your strategy of using integration by parts twice goes through, until the incorrect line: $$\cos(kx)e^x-[-k\sin(kx)e^x] - \left[\int e^x\cdot-k^2\cdot \cos(kx)dx\right]$$ It's incorrect because you've lost a minus sign, since there are big parentheses around the last two terms: $$\cos(kx)e^x-\left([-k\sin(kx)e^x] - \left[\int e^x\cdot-k^2\cdot \cos(kx)dx\right] \right)$$ With this correction you obtain the result: $$L=\cos(kx)e^x + k\sin(kx)e^x-k^2L,$$ and then you solve for $L$: $$L=\frac{[\cos(kx)+k\sin(kx)]e^x }{1+k^2}\quad{\text{(plus constant of integration)}}$$ Now do the definite integral: plug in the limits of integration and divide the whole thing by $\pi$. Notice that $\sin(k\pi)=\sin(-k\pi)=0$ for all integer $k$. What about $\cos(k\pi)$ and $\cos(-k\pi)$?

• what happened to the $-k^{2}$? Why are you dividing by $1+k^2$ ? – Jon Apr 21 '18 at 2:33
• @Jon Notice $L$ appears in both sides of the equation, so I move $k^2L$ from the RHS to the LHS. – grand_chat Apr 21 '18 at 2:34
• @Jon When I move $k^2L$ to the LHS, the LHS becomes $L +k^2L=(1+k^2)L$ – grand_chat Apr 21 '18 at 2:38
• @Jon Just plug $x=\pi$ into the last expression for $L$, and then plug $x=-\pi$. (You will need to evaluate $\cos(k\pi)$ and $\cos(-k\pi)$.) Then take the difference of these two results, and divide everything by $\pi$. – grand_chat Apr 21 '18 at 2:53
• @Jon Convince yourself that $\cos(k\pi)=(-1)^k$ for all integer $k$, while $\sin(k\pi)=0$ for all integer $k$. – grand_chat Apr 21 '18 at 4:37

Just as a comment.

When you face integrals such as $$I=\int \,e^{ax}\cos(bx)\,dx$$ you can make life simpler avoiding integration by parts rewriting $$I=\frac 12 \int e^{a x}\left(e^{i bx}+e^{-i bx} \right)\,dx=\frac 12 \int \left(e^{(a +i b)x}+e^{(a -i b)x}\right)\,dx$$that is to say $$I=\frac 12\left(\frac{e^{(a +i b)x} } {a+i b }+\frac{e^{(a -i b)x} } {a-i b }\right)=\frac 1{2(a^2+b^2)}\left((a-ib)e^{(a +i b)x}+(a+ib) e^{(a -i b)x} \right)$$ $$(a-ib)e^{(a +i b)x}+(a+ib) e^{(a -i b)x}=$$ $$e^{ax}\left((a-ib)(\cos(bx)+i\sin(bx) +(a+ib)(cos(bx)-i\sin(bx)\right)=$$ $$2( a \cos (b x)+ b \sin (b x))$$ making by the end $$I=\frac {e^{ax}}{(a^2+b^2)}\left( a \cos (b x)+ b \sin (b x)\right)$$

• Hi Claude! I hope you're well. It's even easier to use $I=\text{Re} \int e^{ax} e^{ibx}\,dx$. – Mark Viola Apr 21 '18 at 14:11
• @MarkViola. For sure it is ! But the problem is that I am very old fashioned .... Cheers. – Claude Leibovici Apr 21 '18 at 14:15