Fourier series of given function I need to find the fourier series for the folowing function:
$f(x)=x+1, -1\leq x <0\\ \hspace{1.4cm} 1-x, 0\leq x <1$
I end up with just the first coefficient $a_0$ being 1/2 and $a_m=0$ and $b_m=0$. This answer is wrong according to the solutions, but I can't figure out what I did wrong. Could someone help me with this problem?
My try to solving the problem

$f(x) = 1-|x|, x \in [-1,1]$ and $0$ elsewhere
$f(x) = \frac 12 a_0 + \sum a_n \cos n\pi x + b_n \sin n\pi x$
$a_0 = \int_{-1}^1 f(x) \;dx = 1$ which you have already found
$a_n =$$\int_{-1}^{1} f(x) \cos n\pi x \;dx \\ 
\int_{-1}^1 \cos n\pi x \; dx + \int_{-1}^0 x\cos n\pi x\;dx  + \int_{0}^1 -x\cos n\pi x \;dx\\
\frac {sin n\pi x}{n\pi} |_{-1}^{1} + (\frac {x \sin n\pi x}{n\pi} + \frac {\cos n\pi x}{n^2\pi^2})|_{-1}^0 - (\frac {x \sin n\pi x}{n} + \frac {\cos n\pi x}{n^2})|_{0}^1$
Evaluating this, it is worth noting the following:
$\sin n\pi=0$
if $n$ is even $\cos n\pi = cos 0$
if $n$ is odd $\cos n\pi = -1$
Using this information, it falls into place that:
$a_n = 0$ if $n$ is even.
$a_n = \frac {4}{n^2\pi^2}$ if $n$ is odd.
$b_n =$$\int_{-1}^{1} f(x) \sin n\pi x \;dx$
$b_n = 0$  Now I could go through all of the integration and it would look not entirely dissimilar to the how we found $a_n.$  However, $f(x)$ is an even function.  The Fourier series will be the sum of a set of even functions.
