# Fourier series of f(x)

I want to find the Fourier series of $f(x)$ defined by $f(x)=\begin{cases} 1 , -L\le x<0\\ 0, 0\le x<L. \end{cases}$

Well, to find $a_0$ I do this integral: $$a_0=1/L \int _{-L}^0 dx +1/L \int _0^L0 \, dx=1.$$

Calculating the others:

$a_n=0$.

$$b_n=1/L \int _{-L}^0 \sin\frac{\pi n x }L \, dx=-\frac{1}{\pi n}(1-\cos(\pi n))=-\frac{1}{\pi n}(1-(-1)^n)).$$

Now the answer in the book is this:

$$f(x)=\frac{1}{2}-\frac{2}{\pi}\sum_{n=0}^\infty \frac{\sin{[(2n-1)\frac{\pi n}{L}]}}{2n-1}$$

Why my $a_0$ is wrong? And what about the $\cos (\pi n)$ term? Thank you very much for your help!

-
I prefer the complex form as it avoids this silly ${1 \over 2}$ business with $a_0$. – copper.hat Aug 17 '14 at 19:28
For the $\cos(\pi n)$ term, compare what happens when $n$ is even versus odd. – Semiclassical Aug 17 '14 at 19:50

$$a_0 = \frac{1}{2L}\int_{-L}^{L} \dots$$