Fourier Series Representation for piecewise function I've been posed the following question:


$$
f(x)=
\begin{cases}
1-x^2, & 0 \leqslant|x|<1,\\
0, & 1\leqslant|x|<2\\
\end{cases}
$$

I'm trying to find the Fourier series representation but I am having trouble with $ a_n$ and $b_n$ coefficients.
For reference, I obtained $a_0 = \frac{4}{3}$ and I'm pretty sure this is correct.
For $a_n$, I have tried solving the following 
$$\frac{1}{2} \int_{-2}^{2} (1-x^2)\cos \left(\frac{\pi m x}{2} \right) dx$$
to obtain 
$$\frac{16}{\pi^2 m^2} \cos(2 \pi m) \cos \left(\frac{\pi n x}{2} \right)$$
but am fairly certain I did not obtain the correct answer.
For $b_n$, the function $1-x^2$ is even and hence $b_n = 0$. However, I'm not sure if this is right either.
Any help will be much appreciated!
 A: As you said $a_0=\dfrac43$ and $b_n=0$. Also integrating by parts shows
$$a_n=\dfrac{1}{2}\int_{-2}^{2} (1-x^2)\cos\dfrac{m\pi x}{2}\ dx
= \dfrac{1}{2}
\left[
(1-x^2)\left(\dfrac{2}{m\pi}\right)\sin\dfrac{m\pi x}{2}
-2x\left(\dfrac{2}{m\pi}\right)^2\cos\dfrac{m\pi x}{2}
+2\left(\dfrac{2}{m\pi}\right)^3\sin\dfrac{m\pi x}{2}
\right]_{-1}^{1}
= \dfrac{1}{2}
\left[
-2\left(\dfrac{2}{m\pi}\right)^2\cos\dfrac{m\pi}{2}
-2\left(\dfrac{2}{m\pi}\right)^2\cos\dfrac{m\pi}{2}
+2\left(\dfrac{2}{m\pi}\right)^3\sin\dfrac{m\pi}{2}
+2\left(\dfrac{2}{m\pi}\right)^3\sin\dfrac{m\pi}{2}
\right]
= \color{blue}{
-2\left(\dfrac{2}{m\pi}\right)^2\cos\dfrac{m\pi}{2}
+2\left(\dfrac{2}{m\pi}\right)^3\sin\dfrac{m\pi}{2}
}
$$
A: All the odd terms disappear. 
Note that $f$ doesn't take value of $1-x^2$ from $1$ to $2$.
\begin{align}
\frac12 \int_{-2}^2 f(x) \cos \left( \frac{m\pi x}{2}\right) \, dx &= \int_0^1 (1-x^2) \cos \left( \frac{m\pi x}{2}\right) \, dx\\
&= \frac{2}{m \pi}\sin \left( \frac{m \pi x}{2} \right)(1-x^2)\big|_0^1 +\frac{4}{m \pi} \int_0^1 x\sin \left(\frac{m \pi x}2 \right) \, dx \\
&= \frac{4}{m \pi} \int_0^1 x\sin \left(\frac{m \pi x}2 \right) \, dx \\
&=\frac4{m \pi} \left[-\frac{2x}{m \pi} \cos \left( \frac{m \pi x}2\right)\big|_0^1 + \int_0^1 \, \frac2{m \pi}\cos \left(\frac{m \pi x}2 \right) dx\right]\\
&=\frac4{m \pi} \left[\frac{-2}{m \pi}\cos\left(\frac{m \pi}{2} \right)  + \int_0^1 \, \frac2{m \pi}\cos \left(\frac{m \pi x}2 \right) dx\right]\\
&= \frac4{m \pi} \left[\frac{-2}{m \pi}\cos\left(\frac{m \pi}{2} \right)  +  \left(\frac2{m \pi}\right)^2\sin \left(\frac{m \pi }2 \right) \right]\\
&=\begin{cases}  
\frac{16}{((4k-3)\pi)^3} & ,m=4k-3\\
\frac{8}{((4k-2)\pi)^2}& ,m = 4k-2\\
-\frac{16}{((4k-3)\pi)^3}& , m = 4k-1\\
 -\frac{8}{(4k\pi)^2} & ,m=4k 
\end{cases}
\end{align}
Also, 
$$a_0 = \frac12 \int_{-1}^1 1-x^2\, dx = \int_0^11-x^2 \, dx =1-\frac13=\frac23$$
The fourier series is 
\begin{align}\frac13 + \sum_{k=1}^\infty&\left[\frac{16}{((4k-3)\pi)^3} \cos\left( \frac{(4k-3)\pi x}{2}\right) + \frac{8}{((4k-2)\pi)^2} \cos\left( \frac{(4k-2)\pi x}{2}\right)\right. \\&\left.-\frac{16}{((4k-3)\pi)^3}\cos\left( \frac{(4k-1)\pi x}{2}\right)-\frac{8}{(4k\pi)^2}\cos\left( \frac{(4k)\pi x}{2}\right) \right] \end{align}
Here is a second order approximation:

