Fourier Series/x over 0 to 2, x-2 over 2 to 4

Theorem
Let $\map f x$ be the real function defined on $\openint 0 4$ as:


 * $\map f x = \begin{cases}

x & : 0 < x \le 2 \\ x - 2 & : 2 < x < 4 \end{cases}$

Then its Fourier series can be expressed as:


 * $\ds \map f x \sim 1 + \frac 4 \pi \sum_{n \mathop = 1}^\infty \frac {\paren {-1}^{r - 1} } {2 r - 1} \paren {1 + \frac {4 \paren {-1}^r} {\paren {2 r - 1} \pi} } \cos \frac {\paren {2 r - 1} \pi x} 4$

Proof
Let $\map f x$ be the function defined as:
 * $\forall x \in \openint 0 4: \begin{cases}

x & : 0 < x \le 2 \\ x - 2 & : 2 < x < 4 \end{cases}$

Let $f$ be expressed by a half-range Fourier cosine series:


 * $\ds \map f x \sim \frac {a_0} 2 + \sum_{n \mathop = 1}^\infty a_n \cos \frac {n \pi x} 4$

where for all $n \in \Z_{> 0}$:
 * $\ds a_n = \frac 2 l \int_0^l \map f x \cos \frac {n \pi x} l \rd x $

In this context, $l = 4$ and so this can be expressed as:

First the case when $n = 0$:

When $n \ne 0$:

Splitting it up into two:

On the other hand:

The above expression is $0$ when $n$ is even, by Sine of Multiple of Pi.

Thus we may substitute $n = 2 r - 1$. Then:

Combining the results,