# fourier series for g(x)=x between -pi and pi

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?

I belive that your value of $a_n$ is correct, and that the expression in problem (b) is incorrect. For your value of $a_n$, if $n=2m$ is even you get $a_{2m}=0$, and if $n=2m-1$ is odd you get $a_{2m-1}=-\frac{4}{\pi(2m-1)^2}$, giving the Fourier cosine series $$g(x) = \frac{\pi}{2}-\frac{1}{\pi}\sum_{n=1}^\infty\frac{4}{(2n-1)^2}\cos((2n-1)x).$$
If you instead would have had $a_n = \frac{2}{\pi n^2}((-1)^{n+1}-1)$, you would end up with the expression in (b), but this is incorrect.