I have a function where
$f(x) = \begin{cases} -1 &\mbox{if } -1<x<=0 \\ 1 & \mbox{if }\; 0<x\le 1 \end{cases} $
So I assume that I have a period of 2. So I try to work out $a_0, a_n$ and $b_n$ as follows:
$ a_n = \frac{1}{L} \int_{-L}^{L} f(x) \cos(\frac{n\pi x}{L})\,dx $
because 2L = 2 so L = 1, I do:
$ a_n = \int_{-1}^{1} f(x) \cos(n\pi x)dx $
$ a_n = \int_{-1}^{0} - \cos(n\pi x)dx + \int_{0}^{1} \cos(n\pi x)dx $
This integration gives me $ a_n = 0 $
I do the same for $ a_0 = \frac{1}{2L} \int_{-L}^{L} f(x)\,dx $ and $ b_n = \frac{1}{L} \int_{-L}^{L} f(x) \sin(\frac{n\pi x}{L})\,dx $
Both of these integrals give me $ a_0 = 0 $ and $ b_n = 0$
This would result in my Fourier series just being $ f(x) = 0 $.
I feel like this probably isn't correct. Have I messed up anywhere in my working out?
We are given
$$f(x) = \begin{cases} -1, &\mbox{if } -1<x\le0 \\ 1, & \mbox{if }\; 0<x\le 1 \end{cases} $$
The function $f(x)$ is piecewise continuous on the interval $[-1,1]$. The Fourier series of $f$ is the trigonometric series
$$f(x)=\frac{a_0}{2}+\sum_{n=1}^{\infty}a_n\cos(n\pi x)+\sum_{n=1}^{\infty}b_n\sin(n\pi x) $$
where the coefficients $a_n$ and $b_n$ are given by
$$ a_n=\int_{-1}^{1}f(x)\cos(n\pi x)\,dx,\quad n=0,1,2,3,\dots$$ $$ b_n=\int_{-1}^{1}f(x)\sin(n\pi x)\,dx,\quad n=0,1,2,3,\dots$$
Now, $f$ is an odd function. Since the product of an odd function and an even function is odd, $f(x)\cos(n\pi x)$ is also an odd function. This implies
$$ a_n=\int_{-1}^{1}f(x)\cos(n\pi x)\,dx=0,\quad n=0,1,2,3,\dots$$
Furthermore, $f(x)\sin(n\pi x)$ is the product of two odd functions and therefore is an even function, so
\begin{align} b_n&=\int_{-1}^{1}f(x)\sin(n\pi x)\,dx\\&= 2\int_0^1\sin(n\pi x)\,dx\\&= 2\left(\frac{-\cos(n\pi x)}{n\pi}\right)\Bigg|_0^1\\&= \frac{2}{n\pi}\Big(1-(-1)^n\Big)\\&= \begin{cases} 0, & \text{n is even} \\ \large{\frac{4}{n\pi}}, & \text{n is odd} \end{cases} \end{align}
therefore the Fourier series of $f$ is given by
$$f(x)=\frac{2}{\pi}\sum_{n=1}^{\infty}\frac{\big[1-(-1)^n\big]}{n}\,\sin(n\pi x)$$