How to write the fourier series for this piecewise defined function

fourier series

I am given a $2 \pi$ periodic function $f$:

$$ f(x) =
\begin{cases}
x+\pi, & -\pi \le x < -\frac{\pi}{2} \\
\frac{\pi}{2}, & -\frac{\pi}{2} \le x <\frac{\pi}{2} \\ x-\pi, & \frac{\pi}{2} \le x <\pi
\end{cases}$$

I want to determine the fourier series:

$$\frac{a_0}{2}+\sum_{n=0}^\infty a_n \cos{(nx)}+\sum_{n=1}^\infty b_n \sin{(nx)}$$

where $a_n=\frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\cos{(nx)}dx$ and $b_n=\frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\sin{(nx)}dx$.

Since $f$ is even and $[-\pi,\pi]$ is a symmetric interval, all the $b_n$ will be zero. I tried to calculate $a_n$ by integrating piecewise over the interval and (without writing out all the calculations) I got:

$$a_n=\frac{2 \sin{(\frac{n\pi}{2})}}{n}$$

I have two problems now:

  1. $a_0 $ seems to be undefined according to this definition
  2. I know that for $n \space \text{even}$ $a_n=0$. However, I can't really find a nice expression for $n \space \text{odd}$. Is there anyway I can rewrite it (maybe eliminate the $\sin{nx}$ from the term)?

Best Answer

If $a_{n} = \frac{2\sin(\frac{n \pi}{2})}{n}$ then note that

$$ \sin(\frac{n \pi}{2}) = 1, -1,1, \cdots $$ for odd n. So the first few expressions are

$$ a_{1} = \frac{2}{1} = 2 , a_{3} = \frac{-2}{3} , a_{5} = \frac{2}{5}$$

Note that $a_{0}$ is given by the following equation for that interval

$$ a_{0} = \frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \textrm{d}x $$

Alternatively, you can see that

$$ a_{n} = \frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \cos(n x) \textrm{d}x $$

and $\cos(nx) = 1$ for $n =0$.