Undefined term in Fourier series

I'm trying to find the Fourier series for $f(\theta) = |\sin\theta|$. The function is even, so $b_n = 0 \space\forall n$. Doing the integration for $a_n$ yields

$$a_n = \frac{2}{\pi}\left(\frac{1+(-1)^n}{1-n^2}\right)$$

Then, calculating $a_0$ to be $\frac{4}{\pi}$ and plugging into the Fourier series formula gives

$$f(\theta) = \frac{2}{\pi} + \frac{2}{\pi} \sum_{n=1}^\infty \frac{1+(-1)^n}{1-n^2} \cos(n\theta)$$

I then tried graphing this function to check my answer, and realised that the first term of the series is undefined as it involves a division by $0$. I then tried starting the series from $n=2$ instead of $n=1$, and the graph looked correct. How do we deal with Fourier terms that are undefined? Can we always just ignore them?

EDIT: Formula for $a_n$:

$$a_n = \frac{1}{\pi} \int_{-\pi}^\pi f(\theta) \cos(n\theta)d\theta = \frac{2}{\pi} \int_{0}^\pi \sin\theta \cos(n\theta)d\theta$$

Solving:

Let $$I = \int_{0}^\pi \sin\theta \cos(n\theta)d\theta$$

By parts:

$$I = \Bigl[-\cos\theta \cos(n\theta)\Bigr]_0^{\pi}-n\int_0^\pi\cos\theta \sin(n\theta)d\theta$$ $$=(1+(-1)^n)-n\Bigl(\Bigl[\sin\theta\sin(n\theta)\Bigr]_0^\pi-n\int_0^{\pi}\sin\theta\cos(n\theta)d\theta\Bigr)$$ $$=1+(-1)^n+n^2I$$ $$\implies I = \frac{1+(-1)^n}{1-n^2}$$ $$\therefore a_n = \frac{2}{\pi}\left(\frac{1+(-1)^n}{1-n^2}\right)$$

• If that's really true, then your integration for $a_n$ is not valid for $n=1$. You should compute $a_1$ separately. Try writing out that specific case and you will probably find you have to handle it differently.
– MPW
Oct 26 '17 at 21:18
• @MPW Doing it manually gives $a_1 = 0$, so I can ignore it here. Do we always need to compute them manually? Oct 26 '17 at 21:34
• Can you write out the formula so I can see it (for $a_n$)? You probably have a step which isn't valid if $n=1$. Just as a dumb example, the formula $\int x^n\; dx = \frac{x^{n+1}}{n+1}+C$ is not valid for $n=-1$. You just have to inspect your formula for invalid cases and handle them separately, if there are any (there needn't be any).
– MPW
Oct 26 '17 at 21:42
• @MPW Added the calculations in for $a_n$ Oct 26 '17 at 21:54
• Indeed. The equation reduces to $I=1-1+I$, that is, $I=I$, when $n=1$. So another approach is needed. But it's easy since $\int\sin t\cos t \;dt = \int \frac12\sin 2t \; dt$ which can be computed directly.
– MPW
Oct 26 '17 at 21:57

You cannot always ignore the indeterminate forms. Consider that if $f(\theta) = 1$, then $$\int_{-\pi}^\pi \cos n \theta \,d\theta = \frac {2 \sin \pi n} n.$$ $a_0$ is non-zero, but it cannot be found by computing the integral for general $n$ and then substituting $n = 0$.
If $f$ is bounded, then $a_n$ can be obtained by treating $n$ as a continuous variable and taking the limit: $$a_n = \frac 2 \pi \int_0^\pi \sin \theta \cos n \theta \,d\theta = \frac {2(1 + \cos \pi n)} {\pi(1 - n^2)}, \\ a_1 = \lim_{n \to 1} a_n = 0.$$