# 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$.

• I've improved the LaTeX formatting on your question; apologies if I changed your intended meaning in any way. You can find some good starting points on how to format mathematics on the site here. This AMS reference is very useful. Commented Mar 7, 2013 at 22:05
• Commented Mar 7, 2013 at 22:11
• @karanveersingh what's the book name? Commented Nov 16, 2017 at 12:46
• my teacher asked me to prove $π/4=1/2+1/1*3−1/3*5+1/5*7−1/7*9$ when $n=1$ for this same problem. But I can't yet. Commented Nov 16, 2017 at 17:01
• This is solved. When $x=π/2$. Commented Nov 16, 2017 at 17:02

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}$$

• How do I introduce a sine term for n = 1 case? Is my answer incomplete or am I just missing simplification? Commented Mar 7, 2013 at 22:18
• @KaranveerSingh your work was incomplete Commented Mar 7, 2013 at 22:25
• When computing the result with the real fourier series, how did you integrate $\frac {1}{\pi} sin(x)cos(nx)dx$ from 0 to $\pi$ Commented Mar 7, 2013 at 22:29
• with the good old trigonometric theorems, $2 \sin(\alpha)\cdot \cos(\beta)= \sin(\alpha+\beta) + \sin(\alpha-\beta)$ Commented Mar 7, 2013 at 22:31
• AH! I keep forgetting those. Commented Mar 7, 2013 at 22:33

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.$$

• wouldn't it be $e^{-inx}dx$? Commented Mar 7, 2013 at 22:20
• @KaranveerSingh: I copied your formula. Yes it should be $e^{-inx}$. Commented Mar 7, 2013 at 22:25
• Oh, there was supposed to be one there. Sorry for that. Commented Mar 7, 2013 at 22:27
• @KaranveerSingh: No problem. Anyways, as I said $C_1$ is a special case. That means you have to handle it separtly. Commented Mar 7, 2013 at 22:29

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.

• Which software you use to plot that? @JJacquelin. Commented Nov 19, 2021 at 19:36
• @WhyMeasureTheory. Software implemented with "Delphi" from Borland. Commented Nov 21, 2021 at 21:02