I had an exam question today that stated something along the lines of the following:
"Let $f$ be an even function given by $f(x)=x$ on $[0,\pi]$ and extend $f$ to $\mathbb{R}$ by $2\pi$-periodicity. Find the Fourier series of $f$"
Now for this reason I took $f$ to be $|x|$ on $[-\pi,\pi]$, and at any rate, took my coefficients for $a_n$ and $b_n$ to be $$a_n=\frac{2}{2\pi}\int_0^\pi x\cos(nx)dx$$ for $n\neq 0$, $$a_0=\frac{1}{\sqrt{2\pi}}\int_0^\pi xdx$$ and $b_n=0$ $\forall n\in\mathbb{N}$, with corresponding Fourier series $$|x|\sim\sum_{n=1}^\infty a_n\cos(nx)+b_n\sin(nx).$$
However, I know from a later part of the question that my answer was wrong. Where did I go wrong here? Many thanks in advance for any help that anyone can offer.