Consider the following function defined on a finite interval: $$g(x) = x, 0\leq x\leq \pi $$ (3) (a) Sketch an even periodic extension of g(x).
(b) Show that the Fourier cosine series representation of g(x) is $$g(x)=\frac{\pi}{2}-\frac{1}{\pi}\sum_{n=1}^{\infty}\frac{\cos(2nx)}{n^2}$$
For part (a) I drew something like $$|x| $$ from -pi to pi I had no issue with the first term of g(x). I found it by evaluating the area( the integral) from 0 to pi and dividing by L
I have problems with the second term. I'm trying to find $$a_n=\frac{2}{\pi}\int_{0}^{\pi}x\cos(nx)dx$$
and from this integral I get $$a_n=\frac{2}{ \pi n^2}((-1)^n-1)$$ which looks very wrong to me. I can't proceed after this point and I don't know my mistake. Could you please point my mistake here?