I have a periodic function $$ f(x) = \begin{cases} -2x-x^2, & -2 \leq x < 0 \\ 2x-x^2, & 0 \leq x < 2 \\ f(x)=f(x+4) & otherwise \end{cases}$$ and this period is repeated. I have been trying to find the Fourier series for $a_{n}$ and as $f$ is even I don't need to find $b_{n}$. I also know the function has a period of 2 so I have been using $L=1$.
Then using the formula $\displaystyle a_n = \frac{2}{L} \int^{L}_{0} (2x-x^{2})\cos(n \pi x) \, dx $ with $L=1$, I get $a_n = \dfrac{-4}{n^{2} \pi^{2}}$ but I am not sure this is right, as I tried to integrate from $-L$ to $L$ and multiplied by $\dfrac{1}{L}$ instead of $\dfrac{2}{L}$ and got a different answer.
So am I right in having: $\displaystyle f(x)= \frac{2}{3} + \sum^{\infty}_{n=1} \left(\frac{-4}{n^{2}\pi^{2}}\cos(n \pi x)\right)$ as my final answer?
Any help would be appreciated, thank you.