# Error finding Fourier series

I want to find the Fourier series for

$f(x)=\left\{\begin{array}{rcl} 0 & \mbox{ if } & -\pi \leq x \leq 0 \\ \sin x & \mbox{ if } & 0 < x < \pi \end{array}\right.$

The Fourier series is given by $F=a_0+\sum (a_n\cos nx + b_n \sin nx)$

My problem is that both $a_n$ and $b_n$ vanish when I try to calculate them.

$$a_0=\frac{1}{2\pi}\int_{0}^{\pi}\sin x = -\frac{1}{2\pi}(\cos \pi - cos 0)= \frac{1}{\pi}$$

$$a_n=\frac{1}{\pi}\int_{0}^{\pi}\sin x\cos nx dx = \frac{1}{\pi}\left(-\cos x \cos nx - \frac{1}{n}\int \sin nx \cos x dx\right)$$ $$=\frac{1}{\pi}\left(-\cos x\cos nx- \frac{1}{n} \left( - \frac{1}{n}\cos x\cos nx -\frac{1}{n}\int \sin x \cos nx dx \right)\right)$$ $$=\frac{1}{\pi}\left(-\cos x\cos nx+\frac{1}{n^2}\cos x \cos nx + \frac{1}{n^2}\int_{0}^{\pi}\sin x\cos nx dx\right)$$ $$\Rightarrow \frac{1}{\pi}\int_{0}^{\pi}\sin x\cos nx dx = \frac{1}{\pi}\frac{(1/n^2-1)\cos x \cos nx}{1-1/n^2}|^\pi_0$$ $$=-\frac{1}{\pi}\cos x \cos nx |^\pi_0 =0$$

$$b_n=\frac{1}{\pi}\int_0^\pi \sin x \sin nx=\frac{1}{\pi}\frac{(1/n^2)\cos x\sin nx - (1/n)\sin x \cos nx}{1-1/n^2}|_0^\pi=0$$

• Note $\cos \pi \cos (n\pi) = (-1)^{n+1}$, $\cos 0 \cos (n0) = 1$. – Daniel Fischer Nov 29 '16 at 13:59
• You have the wrong basis elements: you should be working with $\sin \left ( \frac{n \pi(x+\pi)}{2\pi} \right )$, and its $\cos$ counterpart (that can be simplified, but still). Also, you definitely should not find that $\int_0^\pi (\sin(x))^2 dx = 0$. In particular, your very last equation involves a division by $0$ when $n=1$. – Ian Nov 29 '16 at 14:06
• In line 9 when you integrate by parts, there is $+\frac{1}{n}\int \sin(nx)\cos(x)$ – hamam_Abdallah Nov 29 '16 at 14:35

$a_0=\frac{1}{\pi}\quad$ : OK.

$a_1=\frac{1}{\pi}\int_{0}^{\pi}\sin(x)\cos(x) dx = 0$

$a_n=-\frac{1}{\pi}\int_{0}^{\pi}\sin(x)\cos(nx) dx = -\frac{1}{\pi}\frac{1+\cos(n\pi)}{n^2-1}= -\frac{1}{\pi}\:\frac{1+(-1)^n}{n^2-1}\qquad \qquad n\geq 2$

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

$b_n=\frac{1}{\pi}\int_{0}^{\pi}\sin(x)\sin(nx) dx =0\qquad \qquad n\neq 1$

$$F(x)=\frac{1}{\pi}+\frac{1}{2}\sin(x)-\frac{1}{\pi}\sum_{n=2}^\infty \frac{1+(-1)^n}{n^2-1}\cos(nx)$$

$$F(x)=\frac{1}{\pi}+\frac{1}{2}\sin(x)-\frac{2}{\pi}\sum_{k=1}^\infty \frac{1}{4\:k^2-1}\cos(2kx)$$

Graphs of incomplete Fourier series :

• why is $a_0=1/2$? how did you get rid of the $\pi$ value? – Cure Nov 29 '16 at 22:54
• This was a typo. $a_0=\frac{1}{\pi}$ in agreement with your answer. – JJacquelin Nov 30 '16 at 6:48