This is a follow-up from this thread:
Compute the Fourier series for $f(x)=x$ over the interval $-\pi\leq x \leq\pi$
$$b_n=\frac{1}{\pi}\int_{-\pi}^\pi f(x)\sin(nx)dx=\frac{1}{\pi}\int_{-\pi}^\pi x\sin(nx)dx$$.
This integral for evaluation is $${ -\dfrac{x\cos(nx)}{n}+\dfrac{\sin(nx)}{n^2}} \Big|_\pi^\pi$$
For $$x=\pm\pi, \dfrac{\sin(nx)}{n^2}=0$$ But what about coefficient $-\dfrac{2}{n}\cos(nx)=-\dfrac{2}{n}(-1)^{n+1}$? How do you obtain this coefficient from the integral? To be more precise, I am stuck at the number $2$ there.
I am just tracing steps from here: http://www.sosmath.com/fourier/fourier1/fourier1.html
When you're doing Fourier series, it's good to know that $\sin n\pi = 0$ and $\cos n\pi = (-1)^n$ when $n$ is an integer. So you have
$$\left.-\frac{x\cos nx}{n}\right|_{-\pi}^{\pi} = -\frac{\pi\cos n\pi}{n} -\left(- \frac{-\pi\cos(-n\pi)}{n}\right)$$
$$= -\frac{\pi(-1)^n}{n} - \frac{\pi(-1)^{-n}}{n} = -2\frac{\pi(-1)^n}{n} = \frac{2\pi(-1)^{n+1}}{n}.$$
(I think you have a minus sign error in your final coefficient.)