I'm learning about Fourier series at the moment and there is an example in the literature that I have trouble following. (I'm sorry if I wrote a misleading title for the problem, I was not sure what the best title would be...)
So $u$ is a $2\pi$-periodic function given by $u(x) = x^2$ when $-\pi \leq x \leq \pi$ and for $n \neq 0$ the Fourier coefficient can be found by partial integration.
$$ 2\pi c_n = \int_{-\pi}^{\pi} x^2 e^{-inx} dx $$
$$= \Bigg[ x^2 \frac{e^{-inx}}{-in} \Bigg]_{-\pi}^{\pi} + \frac{2}{in} \int_{-\pi}^{\pi} xe^{-inx} dx $$
$$= \frac{2}{in} \Bigg[ x \frac{e^{-inx}}{-in} \Bigg]_{-\pi}^{\pi} - \frac{2}{n^2} \int_{-\pi}^{\pi} e^{-inx} dx \space \space \space \space \space \space \space (1) $$
$$= \frac{2}{n^2} (\pi e^{-in\pi} + \pi e^{in\pi}) \space \space \space \space \space \space \space (2)$$
$$= (-1)^n \frac{4\pi}{n^2} $$
The problem I having is going from $(1)$ to $(2)$ and particularly knowing where $\pi e^{-in\pi} + \pi e^{in\pi}$ comes from. I would have written the last term in $(1)$ as
$$- \frac{2}{n^2} \left( \frac{e^{in\pi}-e^{-in\pi}}{in} \right) $$
but I guess that is either wrong or that it could be rewritten once more to reach $(2)$?
The term you derived was correct. But it equals zero by Euler's formula.
$$ \frac{2}{in} \Bigg[ x \frac{e^{-inx}}{-in} \Bigg]_{-\pi}^{\pi} - \frac{2}{n^2} \int_{-\pi}^{\pi} e^{-inx} dx \space \space \space \space \space \space \space\\ =\frac{2}{n^2}\Bigg[xe^{-inx}\Bigg]^{\pi}_{-\pi}\\ =\frac{2}{n^2}(\pi e^{-in\pi}+\pi e^{in\pi})$$
in which I dropped that term you derived. So it is the correct result.