Preface


This section gives a collection of Fourier series for which closed forms are known.

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the first course APMA0330
Return to Mathematica tutorial for the second course APMA0340
Return to the main page for the first course APMA0330
Return to the main page for the second course APMA0340
Return to Part V of the course APMA0340
Introduction to Linear Algebra with Mathematica

 

Examples of Fourier Series


This section is a collection of Fourier series expansions for different functions.

Theorem: If a periodic function of period \( 2\ell \) is square-integrable on any finite interval, then the Fourier series converges to the function at almost every point:

\[ f(x) \,\sim \, \frac{a_0}{2} + \sum_{k\ge 0} \left[ a_k \cos \frac{k \pi x}{\ell} + b_k \sin \frac{k \pi x}{\ell} \right] , \]
where its coefficients are determined via Euler--Fourier formulas:
\[ \begin{split} a_k &= \frac{1}{\ell} \, \int_{-\ell}^{\ell} f(x)\,\cos \frac{k \pi x}{\ell} \, {\text d} x , \quad k=0,1,2,\ldots , \\ b_k &= \frac{1}{\ell} \, \int_{-\ell}^{\ell} f(x)\,\sin \frac{k \pi x}{\ell} \, {\text d} x , \quad k=1,2,\ldots . \end{split} \qquad\qquad ■ \]

Some examples:

\begin{eqnarray*} \sum_{n\ge 1} \frac{1}{n} \, \cos n x &=& -\frac{1}{2} \, \ln \left[ 2 \left( 1 - \cos x \right) \right] , \qquad \mbox{on interval } \ 0 < x < 2\pi ; \\ \sum_{n\ge 1} \frac{1}{n} \, \sin n x &=& \begin{cases} \frac{\pi -x}{2} , & \ \mbox{for } 0< x , \\ - \frac{\pi +x}{2} , & \ \mbox{for } x<0 , \end{cases} \qquad \mbox{on interval } \ -\pi < x < \pi . \\ \sum_{n\ge 1} \frac{1}{n} \, \sin \frac{n\pi x}{\ell} &=& \frac{\ell-x}{2\ell} . \\ \sum_{n\ge 1} \frac{(-1)^{n+1}}{n} \, \cos n x &=& \ln \left( 2 \, \cos \frac{x}{2} \right) , \qquad \mbox{on interval } \ |x| < \pi ; \\ \sum_{n\ge 1} \frac{(-1)^{n+1}}{n} \, \sin n x &=& \frac{x}{2} , \qquad \mbox{on interval } \ |x| < \pi . \end{eqnarray*}
\begin{eqnarray*} \sum_{n\ge 1} \frac{1}{2n-1} \, \cos (2n-1) x &=& \frac{1}{2}\,\ln \cot \frac{x}{2} \qquad \mbox{on interval } \ 0 < x < \pi . \\ \sum_{n\ge 1} \frac{1}{2n-1} \, \sin (2n-1) x &=& \frac{\pi}{4} \times \begin{cases} 1 , & \ \mbox{for } 0< x , \\ - 1 , & \ \mbox{for } x<0 , \end{cases} \qquad \mbox{on interval } \ -\pi < x < \pi . \\ \frac{4}{\pi}\,\sum_{n\ge 1} \frac{1}{2n-1} \, \sin \frac{(2n-1)\pi x}{\ell} &=& 2 \left[ H\left( \frac{x}{\ell} \right) - H\left( \frac{x}{\ell} -1 \right) \right] -1 . \\ \sum_{n\ge 1} \frac{(-1)^{n+1}}{2n-1} \, \cos (2n-1) x &=& \begin{cases} \frac{\pi}{4} , & \ \mbox{for } |x|< \frac{\pi}{2} , \\ -\frac{\pi}{4} , & \ \mbox{for } |x|> \frac{\pi}{2} , \end{cases} \qquad \mbox{on interval } \ -\pi < x < \pi . \\ \sum_{n\ge 1} \frac{(-1)^{n+1}}{2n-1} \, \sin (2n-1) x &=& \frac{x}{2} , \qquad \mbox{on interval } \ -\pi < x < \pi . \end{eqnarray*}
\begin{eqnarray*} \frac{1}{2} + \sum_{n\ge 0} \frac{(-1)^n}{1+n^2} \left( \cos nx -n\,\sin nx \right) &=& \frac{\pi}{2\,\sinh \pi}\, e^x , \qquad \mbox{on interval } \ |x|< \pi . \\ \frac{2}{\pi} - \frac{4}{\pi} \,\sum_{n\ge 1} \frac{1}{4n^2 -1} \, \cos 2nx &=& \sin x , \qquad \mbox{on interval } \ 0\le x < \pi . \\ \frac{\pi^2}{12} + \sum_{n\ge 1} \frac{(-1)^{n+1}}{n^2} \, \cos n x &=& x^2 , \qquad \mbox{on interval } \ |x| < \pi . \\ \sum_{n\ge 1} \frac{(-1)^{n+1}}{n^2} \, \sin n x &=& ?? , \qquad \mbox{on interval } \ |x| < \pi . \\ \frac{\pi^2}{16} + \sum_{n\ge 1} \frac{1}{n^2} \, \cos n x &=& \frac{x^2}{4} - \frac{\pi x}{4} , \qquad \mbox{on interval } \ 0< x < < 2\pi . \\ \sum_{n\ge 1} \frac{1}{n^2} \, \sin n x &=& ?? , \qquad \mbox{on interval } \ |x| < \pi . \\ \sum_{n\ge 1} \frac{1}{(2n-1)^2} \, \cos (2n-1) x &=& \frac{1}{2} - \frac{\pi |x|}{4} , \qquad \mbox{on interval } \ |x|< < \pi ; \\ \sum_{n\ge 1} \frac{1}{(2n-1)^2} \, \sin (2n-1) x &=& ?? , \qquad \mbox{on interval } \ |x| < \pi . \end{eqnarray*}
\[ \begin{split} \sum_{n\ge 1} \frac{1}{n^3} \, \cos n x &= ?? , \qquad \mbox{on interval } \ 0< x < < 2\pi ; \\ \sum_{n\ge 1} \frac{1}{n^3} \, \sin n x &= \frac{\pi^2 x}{6} - \frac{\pi x^2}{4} + \frac{x^3}{12} , \qquad \mbox{on interval } \ 0 < x < 2\pi . \end{split} \]

Example 1: Consider the following square wave functions on interval \( (0, 2\ell ) : \)

\begin{align*} f(x) &= 2 \left[ H(x/\ell ) - H(x/\ell -1) \right] -1 = \begin{cases} 1, & \ 0< x< \ell , \\ -1, & \ \ell < x < 2\ell ; \end{cases} \\ g(x) &= H(x/\ell ) - H(x/\ell -1) = \begin{cases} 1, & \ 0< x< \ell , \\ 0, & \ \ell < x < 2\ell ; \end{cases} \\ h(x) &= H(x/\ell -1) - H(x/\ell -2) = \begin{cases} 0, & \ 0< x< \ell , \\ 1, & \ \ell < x< 2\ell ; \end{cases} \end{align*}
where H(t) is the Heaviside function. Since the function g is an odd function, all coefficients ak are zeroes and we get sine Fourier series (setting \( \ell =1 \) for simplicity):
\[ b_k = \int_0^2 f(x) \,\sin \left( k\pi x \right) {\text d}x = - \frac{4}{k\pi} \,(-1)^k \sin^2 \frac{k\pi}{2} = \frac{4}{k\pi} \times \begin{cases} 1 , & \ \mbox{if $k$ is odd}, \\ 0, & \ \mbox{if $k$ is even}. \end{cases}. \]
Therefore, we get the following Fourier series for f(x):
\[ f(x) = \frac{4\,\ell}{\pi}\, \sum_{n\ge 0} \,\frac{1}{2n+1} \, \sin \left( \frac{(2n+1)\pi x}{\ell} \right) . \]
Using Mathematica,
g[x_,L_]=HeavisideTheta[x/L] - HeavisideTheta[-1 + x/L]
ak = Assuming[L > 0, Integrate[g[x, L]*Cos[k*Pi*x/L], {x, 0, 2*L}]]
bk = Assuming[L > 0, Integrate[g[x, L]*Sin[k*Pi*x/L], {x, 0, 2*L}]]
h[x_, L_] = -HeavisideTheta[-2 + x/L] + HeavisideTheta[-1 + x/L]
ak = Assuming[L > 0, Integrate[h[x, L]*Cos[k*Pi*x/L], {x, 0, 2*L}]]
a0 = Assuming[L > 0, Integrate[h[x, L]*Cos[0*Pi*x/L], {x, 0, 2*L}]]
bk = Assuming[L > 0, Integrate[h[x, L]*Sin[k*Pi*x/L], {x, 0, 2*L}]]
we find other Fourier series:
\begin{align*} g(x) &= \frac{\ell}{2} + \frac{2\ell}{\pi} \sum_{n\ge 0} \frac{1}{2n+1}\, \sin \frac{(2n+1)\,\pi x}{\ell} , \\ h(x) &= \frac{\ell}{2} - \frac{2\ell}{\pi} \sum_{n\ge 0} \frac{1}{2n+1}\, \sin \frac{(2n+1)\,\pi x}{\ell} . \end{align*}
Then we plot partial sums with 10 terms (for simplicity setting \( \ell =1 \) ):
ff[x_] = Sum[4/Pi/(2*n + 1)*Sin[(2*n + 1)*Pi*x], {n, 0, 10}]
Plot[ff[x], {x, -2, 2}, PlotStyle -> Thick]
gg[x_] = 1/2 + 2/Pi*Sum[1/(2*n+1)*Sin[(2*n+1)*Pi*x],{n,0,10}]
hh[x_] = 1/2 - 2/Pi*Sum[1/(2*n+1)*Sin[(2*n+1)*Pi*x],{n,0,10}]
Plot[gg[x], {x, -2, 2}, PlotStyle -> Thick]

The Fourier series for the characteristic function is

\[ \frac{b-a}{??} + \sum_{n\ne 0} = \chi_{a,b} = \begin{cases} 1, & \ \mbox{ for }\ x \in [a,b] , \\ 0, & \ \mbox{ otherwise.} \end{cases} \]
   ■

Example 2:

\[ |x| = \]
\[ = \begin{cases} \frac{\ell - x}{2} , & \ \mbox{ for } \ 0 < x < \ell , \\ \frac{-\ell - x}{2} , & \ \mbox{ for } \ -\ell < x < 0 . \end{cases} \]

On the interval [-ℓ, ℓ], consider the function

\[ f(x) = \begin{cases} 1 - |x|/\delta , & \ \mbox{ if } \ |x| \le \delta , \\ 0, & \ \mbox{ if } \ |x| > \delta . \end{cases} \]
   ■

 

Return to Mathematica page
Return to the main page (APMA0340)
Return to the Part 1 Matrix Algebra
Return to the Part 2 Linear Systems of Ordinary Differential Equations
Return to the Part 3 Non-linear Systems of Ordinary Differential Equations
Return to the Part 4 Numerical Methods
Return to the Part 5 Fourier Series
Return to the Part 6 Partial Differential Equations
Return to the Part 7 Special Functions