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

Theorem
Let $f \left({x}\right)$ be the real function defined on $\left({0 \,.\,.\, 4}\right)$ as:


 * $f \left({x}\right) = \begin{cases}

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

Then its Fourier series can be expressed as:


 * $f \left({x}\right) \sim \displaystyle 1 + \frac 4 \pi \sum_{n \mathop = 1}^\infty \frac {\left({-1}\right)^{r - 1} } {2 r - 1} \left({1 + \frac {4 \left({-1}\right)^r} {\left({2 r - 1}\right) \pi} }\right) x \cos \frac {\left({2 r - 1}\right) \pi x} 4$

Proof
Let $f \left({x}\right)$ be the function defined as:
 * $\forall x \in \left({0 \,.\,.\, 4}\right): \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:


 * $\displaystyle f \left({x}\right) \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}$:
 * $a_n = \displaystyle \frac 2 l \int_0^l f \left({x}\right) \cos \frac {n \pi x} l \, \mathrm d 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: