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)}$$
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)$?