Solving Fourier series of $ f(x)=\begin{cases} x+1 ;-1Please take a look at below Fourier series :
$ f(x)=\begin{cases} x+1 &-1<x<0\\ 1-x & 0<x<1 \end{cases} $
I tried to solve it as follows :
$
a_n=\displaystyle \dfrac{1}{1}\int_{-1}^1f(x)\cos (n\pi x) dx=2\int_{0}^{1} (1-x)\cos( n\pi x) dx
$
solving $a_n$ comes to :
$
a_n=2\left[\dfrac{(-1)^{n}}{n^2\pi^2}+\dfrac{1}{n^2\pi^2}\right]
$
also solving $b_n=0$ then we have Fourier series as below  :
$
\displaystyle f(x)=\sum_{n=1}^{\infty}\left(2\left[\dfrac{(-1)^{n}}{n^2\pi^2}+\dfrac{1}{n^2\pi^2}\right]\cos\frac{n\pi}{1}x\right)
$
I have doubts about my recognition about function if it is odd or even.
(Is my solution right?)
 A: As asked in a comment, I compute the Fourier coefficients :
\begin{align}
a_0(f) & = \int_{-1}^{1}f(x)\mathrm{d}x \\
& =  \int_{-1}^{0}\left(x+1\right)\mathrm{d}x + \int_{0}^{1}\left(1-x\right)\mathrm{d}x \\
& =  \left[\frac{x^2}{2}+x\right]_{-1}^{0} + \left[x-\frac{x^2}{2}\right]_{0}^{1} \\
& =  \left[-\frac{1}{2}+1\right] + \left[1-\frac{1}{2}\right] \\
& = \frac{1}{2} + \frac{1}{2} \\
& = 1.
\end{align}
For all integer $n\geq 1$,
\begin{align}
a_n(f) & = \int_{-1}^{1}f(x)\cos\left(n\pi x\right)\mathrm{d}x \\
& =  \int_{-1}^{0}\left(x+1\right)\cos\left(n\pi x\right)\mathrm{d}x + \int_{0}^{1}\left(1-x\right)\cos\left(n\pi x\right)\mathrm{d}x \\
& =  \left[\left(x+1\right)\frac{\sin\left(n\pi x\right)}{n\pi}\right]_{-1}^{0} - \frac{1}{n\pi}\int_{-1}^{0}\sin\left(n\pi x\right)\mathrm{d}x \\ 
& + \left[\left(1-x\right)\frac{\sin\left(n\pi x\right)}{n\pi}\right]_{0}^{1} + \frac{1}{n\pi}\int_{0}^{1}\sin\left(n\pi x\right)\mathrm{d}x \\
& =  - \frac{1}{n\pi}\int_{-1}^{0}\sin\left(n\pi x\right)\mathrm{d}x + \frac{1}{n\pi}\int_{0}^{1}\sin\left(n\pi x\right)\mathrm{d}x \\
& =  + \frac{1}{n\pi}\left[\frac{\cos\left(n\pi x\right)}{n\pi}\right]_{-1}^{0} - \frac{1}{n\pi}\left[\frac{\cos\left(n\pi x\right)}{n\pi}\right]_{0}^{1} \\
& = \frac{1}{n^2\pi^2}\left[1-(-1)^n\right] - \frac{1}{n^2\pi^2}\left[(-1)^n-1\right] \\
& = \frac{2}{n^2\pi^2}\left(1-(-1)^n\right).
\end{align}
Since $f$ is odd (i.e. $b_n(f)=0$ for all integer $n\geq 1$), the Fourier's series is then formally given by
\begin{align}
S_n(f)(x) & = \frac{a_0(f)}{2} + \sum_{n=1}^{+\infty}a_n(f)\cos\left(n\pi x\right) \\
& = \frac{1}{2} + \sum_{n=1}^{+\infty}\frac{2}{n^2\pi^2}\left(1-(-1)^n\right)\cos\left(n\pi x\right) \\
& = \frac{1}{2} + 4\sum_{p=0}^{+\infty}\frac{\cos\left((2p+1)\pi x\right)}{(2p+1)^2\pi^2}
\end{align}
where the last inequality is due to the fact that $1-(-1)^n=0$ if $n$ is even.
