# Fourier series of function $f(x)=0$ if $-\pi<x<0$ and $f(x)=\sin(x)$ if $0<x<\pi$

$$f(x) = \begin{cases}0 & \text{if }-\pi<x<0, \\ \sin(x) & \text{if }0<x<\pi. \end{cases}$$

My attempt:

I went the route of expanding this function with a complex Fourier series.

$$f(x) = \sum_{n=-\infty}^{+\infty} C_{n}e^{inx}$$

$$C_{n} = \frac {1}{2\pi} \int_{0}^{\pi} \frac {e^{ix}-e^{-ix}}{2i} e^{-inx} \,\mathrm dx = \frac {1}{\pi}\left(\frac {1}{1-n^2}\right)$$

because only even $n$ terms survive, odd $n$ are 0

$$C_0 = \frac {1}{2\pi} \int_{0}^{\pi} \sin(x)\, \mathrm dx = \frac {1}{\pi}$$

so

$$f(x) = \frac{1}{\pi} + \frac {1}{\pi} \left(\frac {e^{i2x}}{1-2^2} + \frac {e^{i4x}}{1-4^2}+\frac {e^{i6x}}{1-6^2}+\cdots\right) + \frac {1}{\pi} \left(\frac {e^{-i2x}}{1-2^2} + \frac {e^{-i4x}}{1-4^2}+\frac {e^{-i6x}}{1-6^2}+\cdots\right)$$

In sine and cosine terms,

$$f(x) = \frac{1}{\pi} + \frac {2}{\pi} \left(\frac {\cos(2x)}{1-2^2} + \frac {\cos(4x)}{1-4^2}+\frac {\cos(6x)}{1-6^2}+\cdots\right)$$

But the answer in my book is given as

$$f(x) = \frac{1}{\pi} + \frac{1}{2} \sin(x)+ \frac {2}{\pi} \left(\frac {\cos(2x)}{2^2-1} + \frac {\cos(4x)}{4^2-1}+\frac {\cos(6x)}{6^2-1}+\dotsb\right)$$

I don’t understand how there is a sine term and the denominator of the cosines has $-1$.

#### Solutions Collecting From Web of "Fourier series of function $f(x)=0$ if $-\pi<x<0$ and $f(x)=\sin(x)$ if $0<x<\pi$"

The $\sin$ term comes form $n=1$ you can’t devide by zero.

mh I calculated again, your $\cos(x)$ terms are right, there shouldn’t be a $-$ in the denominator

For $$\int_0^\pi \sin(x) e^{inx}\, \mathrm{d} x = \frac{1+ e^{i \pi n}}{1-n^2}$$
we have to check the case $n=1$ seperate as we can’t devide by zero.

The case $n=1$ give
$$\int_0^\pi \sin(x) \exp(x)\, \mathrm{d}x=\frac{i \pi }{2}$$

Note that, $C_1$ is a special case and you need to handle separately as

$$C_1 = \frac {1}{2\pi} \int_{0}^{\pi} \sin(x) e^{-ix} dx \neq 0.$$

Since the function $\phi(t)$ is defined on $-L=-\pi<t<\pi=L$ , the Fourier series can be expressed as shown below :

The numerical tests of the formula are well consistent with a good accuracy.

On the figure below, small values of $m$ are taken in order to make clear the deviations in case of series limited to not enough terms.