# Fourier Series/Cosine Series for x over 0 to Pi

## Theorem

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

$f \left({x}\right) = x$

Then its Fourier series can be expressed as:

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

## Proof

By definition of half-range Fourier cosine series:

$\displaystyle f \left({x}\right) \sim \frac {a_0} 2 + \sum_{n \mathop = 1}^\infty a_n \cos n x$

where for all $n \in \Z_{> 0}$:

$a_n = \displaystyle \frac 2 \pi \int_0^\pi f \left({x}\right) \cos n x \rd x$

Thus by definition of $f$:

 $\displaystyle a_0$ $=$ $\displaystyle \frac 2 \pi \int_0^\pi f \left({x}\right) \rd x$ Cosine of Zero is One $\displaystyle$ $=$ $\displaystyle \frac 2 \pi \int_0^\pi x \rd x$ Definition of $f$ $\displaystyle$ $=$ $\displaystyle \frac 2 \pi \left[{\frac {x^2} 2}\right]_0^\pi$ Primitive of Power $\displaystyle$ $=$ $\displaystyle \frac 2 \pi \left({\frac {\pi^2} 2 - \frac {0^2} 2}\right)$ $\displaystyle$ $=$ $\displaystyle \pi$ simplification

$\Box$

For $n > 0$:

 $\displaystyle a_n$ $=$ $\displaystyle \frac 2 \pi \int_0^\pi f \left({x}\right) \cos n x \rd x$ $\displaystyle$ $=$ $\displaystyle \frac 2 \pi \int_0^\pi x \cos n x \rd x$ Definition of $f$ $\displaystyle$ $=$ $\displaystyle \frac 2 \pi \left[{\frac {\cos n x} {n^2} + \frac {x \sin n x} n}\right]_0^\pi$ Primitive of $x \cos n x$ $\displaystyle$ $=$ $\displaystyle \frac 2 \pi \left({\left({\frac {\cos n \pi} {n^2} + \frac {\pi \sin \pi x} n}\right) - \left({\frac {\cos 0 x} {n^2} + \frac {0 \sin 0} n}\right)}\right)$ $\displaystyle$ $=$ $\displaystyle \frac 2 \pi \left({\frac {\cos n \pi} {n^2} - \frac {\cos 0} {n^2} }\right)$ Sine of Multiple of Pi and simplification $\displaystyle$ $=$ $\displaystyle \frac 2 \pi \left({\frac {\left({-1}\right)^n} {n^2} - \frac 1 {n^2} }\right)$ Cosine of Multiple of Pi

When $n$ is even, $\left({-1}\right)^n = 1$.

We can express $n = 2 r$ for $r \ge 1$.

Hence in that case:

 $\displaystyle a_{2 r}$ $=$ $\displaystyle \frac 2 \pi \left({\frac {\left({-1}\right)^n} {n^2} - \frac 1 {n^2} }\right)$ $\displaystyle$ $=$ $\displaystyle \frac 2 \pi \left({\frac 1 {n^2} - \frac 1 {n^2} }\right)$ $\displaystyle$ $=$ $\displaystyle 0$

When $n$ is odd, $\left({-1}\right)^n = -1$.

We can express $n = 2 r - 1$ for $r \ge 1$.

Hence in that case:

 $\displaystyle a_{2 r - 1}$ $=$ $\displaystyle \frac 2 \pi \left({\frac {-1} {\left({2 r - 1}\right)^2} - \frac 1 {\left({2 r - 1}\right)^2} }\right)$ $\displaystyle$ $=$ $\displaystyle -\frac 4 \pi \left({\frac 1 {\left({2 r - 1}\right)^2} }\right)$ simplifying

Finally:

 $\displaystyle f \left({x}\right)$ $\sim$ $\displaystyle \frac {a_0} 2 + \sum_{n \mathop = 1}^\infty a_n \cos n x$ $\displaystyle$ $=$ $\displaystyle \frac \pi 2 - 4 \pi \sum_{r \mathop = 1}^\infty \frac 1 {\left({2 r - 1}\right)^2} \cos \left({2 r - 1}\right) x$ substituting for $a_0$ and $a_n$ from above $\displaystyle$ $=$ $\displaystyle \frac \pi 2 - 4 \pi \sum_{n \mathop = 1}^\infty \frac {\cos \left({2 n - 1}\right) x} {\left({2 n - 1}\right)^2}$ changing the name of the variable and rearranging

$\blacksquare$