# Is my Fourier Series computation done correctly?

See my fourier series calculation of this function if you please!

$f(t)=\left\{\begin{array}{ll} 0, & \text{for } \ -\pi<t<0 \\ 1, & \text{for } \ 0 < t < \pi\end{array}\right. .$

I start by calculation of the coefficient $a_0,a_k,b_k$: $$a_0=\frac{1}{\pi} \int\limits_{0}^{\pi}1\mathrm dt=1 ;$$ $$a_k=\frac{1}{\pi}\int\limits_{0}^{\pi}\sin(kt)\mathrm dt=\frac{1-\cos(\pi k)}{\pi k} = \frac{1-(-1)^{k}}{\pi k};$$ $$b_k= \frac{1}{\pi}\int\limits_{0}^{\pi}\cos(kt)\mathrm dt = \frac{\sin(\pi t)}{k} = 0$$

We will get: $f(t) \sim \frac{1}{2} + \sum\limits_{k=0}^{\infty}\frac{1-(-1)^{k}}{\pi k}\sin(kt) = \frac{1}{2} + \sum\limits_{n=0}^{\infty}\frac{2}{\pi (2n+1)}\sin((2n+1)t)$

How we can find relationship : $\sum\limits_{n=0}^{\infty}\frac{(-1)^n}{2n+1}=\frac{\pi}{4}$ from this fourier series ?

-
Do you mean $$f(t)=\left\{\begin{array}{ll} 0, & for \ -\pi<t<0 \\ 1, & for \ 0 < t < \pi\end{array}\right.$$ –  Américo Tavares Feb 2 at 14:14
Hi , I just copy from paper, it is like I wrote in beginning... But I also think it is strange because I don't know how to make a fourier series of a function which give two value.... So is very likely it is a mistake in typing. –  booth Feb 2 at 14:20
You forgot to divide your coefficients by $\pi$: en.wikipedia.org/wiki/Fourier_series. Also, in $a_k$, the numerator should be $-\cos(\pi k)+\cos (0)=1-(-1)^k$. –  julien Feb 2 at 14:29
I correct it thank you )) –  booth Feb 2 at 14:40
Note also that with the formula you took for $a_0$, it should be $a_0/2$ in the Fourier series of $f$. And your $a_k$ should be called $b_k$ and vice versa. –  julien Feb 2 at 14:44
show 1 more comment

$$\begin{equation*} % a_0 f(t)=\begin{cases}0,&-\pi<t<0\\1,&0<t<\pi \end{cases} \end{equation*}$$

$$\begin{equation*}S(t)=\frac{a_0}2+\sum\limits_{k=1}^\infty a_k\cos\left(\frac{k\pi x}l\right)+b_k\sin\left(\frac{k\pi t}l\right)\\ \\ a_0=\frac1l\int\limits_{a}^{a+2l}f(t)\mathrm dt\qquad a_k=\frac1l\int\limits_{a}^{a+2l}f(t)\cos(t)\mathrm dt\qquad b_k=\frac1l\int\limits_{a}^{a+2l}f(t)\sin(t)\mathrm dt\\ \\\end{equation*}$$

\begin{align*} % a_0 a_0&=\frac1\pi\int\limits_{-\pi}^\pi f(t)\,\text dt\\ &=\frac1\pi\int\limits_{0}^\pi\,\text dt\\ &=\frac t\pi \Big|_0^\pi\\ &=\frac{\pi-0}\pi\\ &=1\\ \end{align*}

\begin{align*} %a_k a_k&=\frac1\pi\int\limits_{-\pi}^\pi f(t)\cos(kt)\,\text dt\\ &=\frac1\pi\int\limits_{0}^\pi \cos(kt)\,\text dt\\ &=\frac1\pi\frac{\sin(kt)}k\Big|_0^\pi\\ &=\frac{\sin(k\pi)}{\pi k}\\ &=0 \end{align*}

\begin{align*} % b_k b_k&=\frac1\pi\int\limits_{-\pi}^\pi f(t)\sin(kt)\,\text dt\\ &=\frac1\pi\int\limits_{0}^\pi\sin(kt)\,\text dt\\ &=\frac{-\cos(kt)}{\pi k}\Big|_0^\pi\\ &=\frac{\cos(0)-\cos(k\pi)}{k\pi }\\ &=\frac{1-(-1)^k}{k\pi }\\ &=\frac{1+(-1)^{k+1}}{k\pi }\\ \end{align*}

\begin{align*} % S(t) S(t)&=\frac{1}2+\sum\limits_{k=1}^\infty \frac{1+(-1)^{k+1}}{k\pi }\sin\left({k t}\right)\\ &=\frac{1}2+\frac2\pi\sum\limits_{k=1,3,5,\dots}^\infty\frac{\sin({k t})}k\\ &=\frac{1}2+\frac2\pi\sum\limits_{r=1}^\infty\frac{\sin\big((2r-1)t\big)}{2r-1}\\ \\ &=\frac12+\frac2\pi\left(\sin(t)+\frac{\sin(3t)}3+\frac{\sin(5t)}5+\dots\right) \end{align*}

\begin{align*} % S(t) S(t) &=\frac{1}2+\frac2\pi\sum\limits_{r=1}^\infty\frac{\sin\big((2r-1)t\big)}{2r-1}\\ \\ \\% S(π/2) S\left(\tfrac\pi2\right) &=\frac{1}2+\frac2\pi\sum\limits_{r=1}^\infty\frac{\sin(\pi r-\tfrac\pi2)}{2r-1}\\ 1&=\frac{1}2+\frac2\pi\sum\limits_{r=1}^\infty\frac{(-1)^{r-1}}{2r-1}\\ \frac\pi4&=\sum\limits_{r=1}^\infty\frac{(-1)^{r-1}}{2r-1}\\ \\ \end{align*}

-
You might want to justify the convergence at $\pi/2$. –  julien Feb 2 at 15:18
waw, thank a lot unklerhaukus ) –  booth Feb 2 at 15:49
The Fourier series of $f$ is: $$\frac{1}{2}+\sum_{k=1}^{+\infty} \frac{1-(-1)^k}{k\pi}\sin(kt)=\frac{1}{2}+\sum_{n=0}^{+\infty}\frac{2}{(2n+1)\pi}\sin((2n+1)t).$$
Now the function $f$ is differentiable at $t=\pi/2$. By Dirichlet Theorem, we have convergence of the Fourier series to $f$ at this point: $$1=\frac{1}{2}+\sum_{n=0}^{+\infty}\frac{2}{(2n+1)\pi}\sin((2n+1)\pi/2)=\frac{1}{2}+\sum_{n=0}^{+\infty}\frac{2}{(2n+1)\pi}(-1)^n.$$ This yields the required formula.
@booth You're welcome. Since you chose to accept the other answer, note nevertheless that it is important in such an exercise to justify the convegence of the Fourier series to $f$ at $\pi/2$. This is not automatic. –  julien Feb 2 at 15:50