# Fourier Series/Square of x minus pi, Square of pi

## Theorem

Let $\map f x$ be the real function defined on $\openint 0 {2 \pi}$ as:

$\map f x = \begin{cases} \paren {x - \pi}^2 & : 0 < x \le \pi \\ \pi^2 & : \pi < x < 2 \pi \end{cases}$

Then its Fourier series can be expressed as:

$\map f x \sim \displaystyle \frac {2 \pi^2} 3 + \sum_{n \mathop = 1}^\infty \paren {\frac {2 \cos n x} {n^2} + \paren {\frac {\paren {-1}^n \pi} n + \frac {2 \paren {\paren {-1}^n - 1} } {\pi n^3} } \sin n x}$

## Proof

By definition of Fourier series:

$\displaystyle \map f x \sim \frac {a_0} 2 + \sum_{n \mathop = 1}^\infty \paren {a_n \cos n x + b_n \sin n x}$

where:

 $\displaystyle a_n$ $=$ $\displaystyle \dfrac 1 \pi \int_0^{2 \pi} \map f x \cos n x \rd x$ $\displaystyle b_n$ $=$ $\displaystyle \dfrac 1 \pi \int_0^{2 \pi} \map f x \sin n x \rd x$

for all $n \in \Z_{>0}$.

Thus:

 $\displaystyle a_0$ $=$ $\displaystyle \frac 1 \pi \int_0^{2 \pi} \map f x \rd x$ Cosine of Zero is One $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \int_0^\pi \paren {x - \pi}^2 \rd x + \frac 1 \pi \int_\pi^{2 \pi} \pi^2 \rd x$ $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \int_0^\pi \paren {x^2 + 2 \pi x - \pi^2} \rd x + \frac 1 \pi \bigintlimits {\pi^2 x} \pi {2 \pi}$ Primitive of Constant $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \intlimits {\frac {x^3} 3 + \pi x^2 - \pi^2 x} 0 \pi + \frac 1 \pi \bigintlimits {\pi^2 x} \pi {2 \pi}$ Primitive of Power $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \paren {\paren {\frac {\pi^3} 3 + \pi^3 - \pi^3} - \paren {\frac {0^3} 3 + \pi \times 0^2 - \pi^2 \times 0} + \paren {\pi^2 \times 2 \pi} - \paren {\pi^3} }$ $\displaystyle$ $=$ $\displaystyle \frac {\pi^2} 3 + 2 \pi^2 - \pi^2$ $\displaystyle$ $=$ $\displaystyle \frac {4 \pi^2} 3$

$\Box$

For $n > 0$:

 $\displaystyle a_n$ $=$ $\displaystyle \frac 1 \pi \int_0^{2 \pi} \map f x \cos n x \rd x$ $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \int_0^\pi \paren {x - \pi}^2 \cos n x \rd x + \frac 1 \pi \int_\pi^{2 \pi} \pi^2 \cos n x \rd x$ Definition of $f$ $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \int_0^\pi \paren {x^2 - 2 \pi x + \pi^2} \cos n x \rd x + \frac 1 \pi \int_\pi^{2 \pi} \pi^2 \cos n x \rd x$ $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \int_0^\pi x^2 \cos n x \rd x - 2 \int_0^\pi x \cos n x \rd x + \pi \int_0^\pi \cos n x \rd x + \pi \int_\pi^{2 \pi} \cos n x \rd x$ Linear Combination of Integrals

Splitting this up into bits:

 $\displaystyle$  $\displaystyle \pi \int_0^\pi \cos n x \rd x + \pi \int_\pi^{2 \pi} \cos n x \rd x$ $\displaystyle$ $=$ $\displaystyle \pi \int_0^{2 \pi} \cos n x \rd x$ Sum of Integrals on Adjacent Intervals for Continuous Functions $\displaystyle$ $=$ $\displaystyle 0$ Integral over $2 \pi$ of $\cos n x$

 $\displaystyle$  $\displaystyle 2 \int_0^\pi x \cos n x \rd x$ $\displaystyle$ $=$ $\displaystyle 2 \intlimits {\frac {\cos n x} {n^2} + \frac {x \sin n x} n} 0 \pi$ Primitive of $x \cos n x$ $\displaystyle$ $=$ $\displaystyle 2 \paren {\frac {\cos n \pi} {n^2} + \frac {\pi \sin n \pi} n} - 2 \paren {\frac {\cos 0} {n^2} + \frac {0 \sin 0} n}$ $\displaystyle$ $=$ $\displaystyle \frac {2 \cos n \pi} {n^2} - \frac {2 \cos 0} {n^2}$ Sine of Multiple of Pi $\displaystyle$ $=$ $\displaystyle \paren {-1}^n \frac 2 {n^2} - \frac 2 {n^2}$ Cosine of Multiple of Pi

 $\displaystyle$  $\displaystyle \frac 1 \pi \int_0^\pi x^2 \cos n x \rd x$ $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \intlimits {\frac {2 x \cos n x} {n^2} + \paren {\frac {x^2} n - \frac 2 {n^3} } \sin n x} 0 \pi$ Primitive of $x^2 \cos n x$ $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \paren {\frac {2 \pi \cos n \pi} {n^2} + \paren {\frac {\pi^2} n - \frac 2 {n^3} } \sin n \pi} - \frac 1 \pi \paren {\frac {0 \cos 0} {n^2} + \paren {\frac 0 n - \frac 2 {n^3} } \sin 0}$ $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \frac {2 \pi \cos n \pi} {n^2}$ Sine of Multiple of Pi and removal of vanishing terms $\displaystyle$ $=$ $\displaystyle \paren {-1}^n \frac 2 {n^2}$ Cosine of Multiple of Pi

Reassembling $a_n$ from the remaining non-vanishing terms:

 $\displaystyle a_n$ $=$ $\displaystyle \paren {-1}^n \frac 2 {n^2} - \paren {-1}^n \frac 2 {n^2} + \frac 2 {n^2}$ $\displaystyle$ $=$ $\displaystyle \frac 2 {n^2}$

$\Box$

Now for the $\sin n x$ terms:

 $\displaystyle b_n$ $=$ $\displaystyle \frac 1 \pi \int_0^{2 \pi} \map f x \sin n x \rd x$ $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \int_0^\pi \paren {x - \pi}^2 \sin n x \rd x + \frac 1 \pi \int_\pi^{2 \pi} \pi^2 \sin n x \rd x$ Definition of $f$ $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \int_0^\pi \paren {x^2 - 2 \pi x + \pi^2} \sin n x \rd x + \frac 1 \pi \int_\pi^{2 \pi} \pi^2 \sin n x \rd x$ $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \int_0^\pi x^2 \sin n x \rd x - 2 \int_0^\pi x \sin n x \rd x + \pi \int_0^\pi \sin n x \rd x + \pi \int_\pi^{2 \pi} \sin n x \rd x$ Linear Combination of Integrals

Splitting this up into bits:

 $\displaystyle$  $\displaystyle \pi \int_0^\pi \sin n x \rd x + \pi \int_\pi^{2 \pi} \sin n x \rd x$ $\displaystyle$ $=$ $\displaystyle \pi \int_0^{2 \pi} \sin n x \rd x$ Sum of Integrals on Adjacent Intervals for Continuous Functions $\displaystyle$ $=$ $\displaystyle 0$ Integral over $2 \pi$ of $\sin n x$

 $\displaystyle$  $\displaystyle 2 \int_0^\pi x \sin n x \rd x$ $\displaystyle$ $=$ $\displaystyle 2 \intlimits {\frac {\sin n x} {n^2} - \frac {x \cos n x} n} 0 \pi$ Primitive of $x \sin n x$ $\displaystyle$ $=$ $\displaystyle 2 \paren {\frac {\sin n \pi} {n^2} - \frac {\pi \cos n \pi} n} - 2 \paren {\frac {\sin 0} {n^2} - \frac {0 \cos 0} n}$ $\displaystyle$ $=$ $\displaystyle -\frac {2 \pi \cos n \pi} n$ Sine of Multiple of Pi and removal of vanishing terms

 $\displaystyle$  $\displaystyle \frac 1 \pi \int_0^\pi x^2 \sin n x \rd x$ $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \intlimits {\frac {2 x \sin n x} {n^2} + \paren {\frac 2 {n^3} - \frac {x^2} n} \cos n x} 0 \pi$ Primitive of $x^2 \sin n x$ $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \paren {\frac {2 \pi \sin n \pi} {n^2} + \paren {\frac 2 {n^3} - \frac {\pi^2} n} \cos n \pi} - \frac 1 \pi \paren {\frac {0 \sin 0} {n^2} + \paren {\frac 2 {n^3} - \frac {0^2} n} \cos 0}$ $\displaystyle$ $=$ $\displaystyle \frac 1 \pi \paren {\paren {\frac 2 {n^3} - \frac {\pi^2} n} \cos n \pi} - \frac 1 \pi \paren {\frac 2 {n^3} \cos 0}$ Sine of Multiple of Pi and removal of vanishing terms $\displaystyle$ $=$ $\displaystyle \frac 2 {\pi n^3} \paren {\cos n \pi - 1} - \frac \pi n \cos n \pi$ Cosine of Zero is One and simplifying

Reassembling $b_n$ from the remaining non-vanishing terms:

 $\displaystyle b_n$ $=$ $\displaystyle \frac 2 {\pi n^3} \paren {\cos n \pi - 1} - \frac \pi n \cos n \pi - \paren {- \frac {2 \pi \cos n \pi} n}$ $\displaystyle$ $=$ $\displaystyle \frac 2 {\pi n^3} \paren {\cos n \pi - 1} + \frac \pi n \cos n \pi$ simplifying $\displaystyle$ $=$ $\displaystyle \frac 2 {\pi n^3} \paren {\paren {-1}^n - 1} + \frac {\paren {-1}^n \pi} n$ Cosine of Multiple of Pi

$\Box$

Finally:

 $\displaystyle \map f x$ $\sim$ $\displaystyle \frac {a_0} 2 + \sum_{n \mathop = 1}^\infty \paren {a_n \cos n x + b_n \sin n x}$ $\displaystyle$ $=$ $\displaystyle \dfrac 1 2 \paren {\frac {4 \pi^2} 3} + \sum_{n \mathop = 1}^\infty \paren {\frac 2 {n^2} \cos n x + \paren {\frac 2 {\pi n^3} \paren {\paren {-1}^n - 1} + \frac {\paren {-1}^n \pi} n} \sin n x}$ substituting for $a_0$, $a_n$ and $b_n$ from above $\displaystyle$ $=$ $\displaystyle \frac {2 \pi^2} 3 + \sum_{n \mathop = 1}^\infty \paren {\frac {2 \cos n x} {n^2} + \paren {\frac {\paren {-1}^n \pi} n + \frac {2 \paren {\paren {-1}^n - 1} } {\pi n^3} } \sin n x}$ rearranging

$\blacksquare$