Integration for Fourier coefficients of $x$ To compute the Fourier coefficients of $x$, I was trying to integrate $$\int_{-\pi}^\pi xe^{-inx}dx$$ How to integrate this? (I already did it, and I'm posting my answer just to keep the records and possibly help others in the future.)

So I used integration by parts.  $$\int_{-\pi}^\pi xe^{-inx}dx=x\frac{e^{-inx}}{-in}-\int_{-\pi}^\pi\frac{e^{-inx}}{-in}dx$$
The first term is $\dfrac{i}{n}(\pi(\cos(-n\pi)+i\sin(-n\pi)+\pi(\cos(n\pi)+i\sin(n\pi))=\dfrac{2\pi i}{n}\cos(n\pi)$
The  second term is $-\dfrac{1}{n^2}(\cos(-n\pi)+i\sin(-n\pi)-\cos(n\pi)-i\sin(-n\pi))=\dfrac{2i}{n^2}\sin(n\pi)$
EDIT: As N.S. helpfully pointed out, when $n=0$ this should be done separately. So it's $\int_{-\pi}^\pi xdx=0$. Also, for other $n$ the answer is $\dfrac{2\pi i}{n}\cos(n\pi)-\dfrac{2i}{n}\sin(n\pi)=\dfrac{2\pi i(-1)^n}{n}$
