Fourier Series of a Sawtooth Wave¶
Consider the $2\pi$-periodic extension of $f(x)=x$ on $-\pi<x<\pi$. Its Fourier series is
$$ f(x)\sim \frac{a_0}{2} +\sum_{k=1}^{\infty}a_k\cos(kx) +\sum_{k=1}^{\infty}b_k\sin(kx). $$
Egison symbolically evaluates the coefficient integrals and builds the first terms of the series.
Symbolic antiderivatives¶
The coefficients use
$$ a_k=\frac1\pi\int_{-\pi}^{\pi}x\cos(kx)\,dx, \qquad b_k=\frac1\pi\int_{-\pi}^{\pi}x\sin(kx)\,dx. $$
Integration by parts gives explicit primitives for $x\cos(kx)$ and $x\sin(kx)$. We define those formulas directly, keeping the notebook independent of optional integration libraries.
declare symbol x, n : MathValue
def f (x : MathValue) : MathValue := x
def cosinePrimitive (k : MathValue) : MathValue :=
x * sin (k * x) / k + cos (k * x) / k^2
def sinePrimitive (k : MathValue) : MathValue :=
(- x) * cos (k * x) / k + sin (k * x) / k^2
sinePrimitive n
Fourier coefficients¶
The sawtooth is odd, so every cosine coefficient is zero. The sine coefficients are $b_k=2(-1)^{k+1}/k$.
def cosineCoefficients : [MathValue] :=
map
(\k ->
let primitive := cosinePrimitive k
in (substitute [(x, π)] primitive - substitute [(x, - π)] primitive) / π)
nats
def sineCoefficients : [MathValue] :=
map
(\k ->
let primitive := sinePrimitive k
in (substitute [(x, π)] primitive - substitute [(x, - π)] primitive) / π)
nats
take 10 cosineCoefficients
take 10 sineCoefficients
Reconstructing the series¶
Multiplying each $b_k$ by $\sin(kx)$ gives the successive Fourier terms.
def fourierTerms : [MathValue] :=
map (\(k, b) -> b * sin (k * x)) (zip nats sineCoefficients)
take 10 fourierTerms
Thus
$$ x=2\sum_{k=1}^{\infty}\frac{(-1)^{k+1}}{k}\sin(kx) \qquad(-\pi<x<\pi). $$
The separate parity and coefficient cells make clear why no cosine terms survive.