For the function $f(x)= \begin{cases}1, & \text{for } -2For the function $f(x)= \begin{cases}1, & \text{for } -2<x<0 \\ x , & \text{for } 0<x < 2, \end {cases}$ find the Fourier series of $f(x)$.
Here, $f(-x)=-f(x)$. So $f(x)$ is Odd function, hence $a_n=0$ and the Fourier series looks like $ f(x) \sim \sum b_n \sin \frac{n \pi x} 2$. But after calculation I see that $ a_0 \neq 0 $ , also some $ a_n \neq 0 $. What is the wrong here? Because we know that if a function is Odd , then it contains only $ \sin $ term but here $a_n$ contains also. Please help me. Is it the function is odd 
 A: Define problem
Piecewise function: Resolve $f(x)$ into a left and right piece
$$
\begin{align}
  %
  l(x) &= 1, \quad -2 \le x < 0 \\
  %
  r(x) &= x, \quad \ \ \ 0 \le x \le 2
  %
\end{align}
$$
Find the Fourier expansion
$$ 
  f(x) = \frac{1}{2}a_{0} +
\sum_{k=1}^{\infty} \left(
  a_{k} \cos \left( \frac{k \pi x}{2} \right) +
  b_{k} \sin \left( \frac{k \pi x}{2} \right)
\right)
$$
where the amplitudes are given by
$$
\begin{align}
  %
  a_{0} &= \frac{1}{2} \int_{-2}^{2} f(x) dx \\
  %
  a_{k} &= \frac{1}{2} \int_{-2}^{2} f(x) \cos \left( \frac{k \pi x}{2} \right) dx \\
  %
  b_{k} &= \frac{1}{2} \int_{-2}^{2} f(x) \sin \left( \frac{k \pi x}{2} \right) dx \\
  %
\end{align}
$$
Basic integrals
Left hand piece
$$
\begin{align}
  %
  \int_{-2}^{0} l(x) dx &= 2 \\
  %
  \int_{-2}^{0} l(x) \cos \left( \frac{k \pi x}{2} \right) dx &= 0 \\
  %
  \int_{-2}^{0} l(x) \sin \left( \frac{k \pi x}{2} \right) dx &= \frac{2 \left((-1)^k-1\right)}{\pi  k} \\
\end{align}
$$
Right hand piece
$$
\begin{align}
  %
  \int_{0}^{2} r(x) dx &= 2 \\
  %
  \int_{0}^{2} r(x) \cos \left( \frac{k \pi x}{2} \right) dx &= \frac{4 \left((-1)^k-1\right)}{\pi ^2 k^2} \\
  %
  \int_{0}^{2} r(x) \sin \left( \frac{k \pi x}{2} \right) dx &= -\frac{4 (-1)^k}{\pi  k}
  %
\end{align}
$$
Results
$$
\begin{align}
  %
    a_{0} & = 2 \\
  %
    a_{k} &= \frac{4 \left((-1)^k-1\right)}{\pi ^2 k^2} \\[2pt]
  %
    b_{k} &= -\frac{4 \left(\pi  (-1)^k k+(-1)^{k+1}+1\right)}{\pi ^2 k^2}
  %
  %
\end{align}
$$
The first terms of each series:
$$
\begin{align}
%
\left\{ k, a_{k} \right\} &=
\left\{ 
\left( 1 , -\frac{8}{\pi ^2} \right),
\left( 2 , 0 \right),
\left( 3 , -\frac{8}{9\pi ^2} \right),
\left( 4 , 0 \right),
\left( 5 , -\frac{8}{25\pi ^2} \right), \dots
\right\} \\[5pt]
%
\left\{ k, b_{k} \right\} &=
\left\{ 
\left( 1 , -\frac{4 (2-\pi )}{\pi ^2} \right),
\left( 2 , -\frac{2}{\pi } \right),
\left( 3 , -\frac{4 (2-3 \pi )}{9 \pi ^2} \right),
\left( 4 , -\frac{1}{\pi } \right),
\left( 5 , -\frac{4 (2-5 \pi )}{25 \pi ^2} \right), \dots
\right\}
%
\end{align}
$$
Approximation sequence
$$
 g_{n}(x) = 1 + 
 \sum_{k=1}^{n} \left(
 -\frac{8}{((2 k-1)\pi)^2} \cos \frac{2(k-1) \pi x}{2}  -\frac{2}{ (2 k-1) \pi } \sin \frac{(2k-1) \pi x}{2} \\
 -\frac{4 \left((-1)^{2 k+1}+\pi  (-1)^{2 k} (2 k)+1\right)}{\pi ^2 (2 k)^2} \sin \frac{2k \pi x}{2}
\right)
$$




