[Math] Fourier Sine Series of a Piecewise Smooth Odd Function

fourier series

I am trying to find the Fourier sine series of the following function:

$$
f\left(x\right)=
\begin{cases}
1&x<L/2,\\
0&x>L/2.\tag{1}
\end{cases}
$$

Let $L=1$. Then, this is what $\left(1\right)$ looks like:

                                enter image description here

I know that to find the Fourier sine series of $\left(1\right)$, I first need to find its odd extension $f_o$:

$$
f_o\left(x\right)=
\begin{cases}
1&0<x<L/2,\\
0&L/2<x<L\text{ & }-L<x<L/2,\\
-1&-L/2<x<0.\tag{2}
\end{cases}
$$

Again, letting $L=1$, this is what $\left(2\right)$ looks like:

                                enter image description here

Finally, the Fourier sines series of a piecewise smooth, odd function $f\left(x\right)$ is given by

$$
f\left(x\right)\sim\sum_{n=1}^{\infty}B_n\sin\frac{n\pi x}{L},
$$

where

$$
B_n=\frac{2}{L}\int_{0}^{L}f\left(x\right)\sin\frac{n\pi x}{L}.\tag{3}
$$

Now, I am having a really hard time trying to find $\left(3\right)$ because, for the case where $0<x<L/2$, I get

$$
\frac{2}{n\pi}\left(1-\cos\left(n\pi\right)\right),
$$

and for the case where $-L/2<x<0$, I get

$$
\frac{2}{n\pi}\left(\cos\left(n\pi\right)-1\right).
$$

So, it is piecewise defined, but my book only gives one solution, that is,

$$
\frac{2}{n\pi}\left(1-\cos\frac{n\pi}{2}\right).
$$

What am I missing!?

Best Answer

$$B_n=\frac 2L \int_0^{L/2}\sin(\frac{n\pi}L x) dx$$ $$B_n=-\frac 2L \cos(\frac{n\pi}Lx)\frac{L}{n\pi}\bigg]_0^{L/2}$$ $$B_n=\frac{2}{n\pi}\left(1-\cos(\frac{n\pi}2)\right)$$

I have no idea what you did. Do you see where your derivation looks different from this one? Keep in mind that the first integral you gave is the whole solution. You don't have to do it on both sides.