{ "cells": [ { "cell_type": "markdown", "id": "3afbe59d", "metadata": {}, "source": [ "# Fourier Series of a Sawtooth Wave\n", "\n", "Consider the $2\\pi$-periodic extension of $f(x)=x$ on\n", "$-\\pi\n", " let primitive := cosinePrimitive k\n", " in (substitute [(x, π)] primitive - substitute [(x, - π)] primitive) / π)\n", " nats\n", "\n", "def sineCoefficients : [MathValue] :=\n", " map\n", " (\\k ->\n", " let primitive := sinePrimitive k\n", " in (substitute [(x, π)] primitive - substitute [(x, - π)] primitive) / π)\n", " nats\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "974066ad", "metadata": {}, "outputs": [ { "data": { "text/html": [ "$\\{0, 0, 0, 0, 0, 0, 0, 0, 0, 0\\}$" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "take 10 cosineCoefficients\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "3d203a5c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "$\\{2, -1, \\frac{2}{3}, \\frac{-1}{2}, \\frac{2}{5}, \\frac{-1}{3}, \\frac{2}{7}, \\frac{-1}{4}, \\frac{2}{9}, \\frac{-1}{5}\\}$" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "take 10 sineCoefficients\n" ] }, { "cell_type": "markdown", "id": "a3ef0cbd", "metadata": {}, "source": [ "## Reconstructing the series\n", "\n", "Multiplying each $b_k$ by $\\sin(kx)$ gives the successive Fourier\n", "terms.\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "aeef0488", "metadata": {}, "outputs": [], "source": [ "def fourierTerms : [MathValue] :=\n", " map (\\(k, b) -> b * sin (k * x)) (zip nats sineCoefficients)\n" ] }, { "cell_type": "code", "execution_count": 7, "id": "197ca621", "metadata": {}, "outputs": [ { "data": { "text/html": [ "$\\{2 \\sin(x), -\\sin(2 x), \\frac{2}{3} \\sin(3 x), \\frac{-1}{2} \\sin(4 x), \\frac{2}{5} \\sin(5 x), \\frac{-1}{3} \\sin(6 x), \\frac{2}{7} \\sin(7 x), \\frac{-1}{4} \\sin(8 x), \\frac{2}{9} \\sin(9 x), \\frac{-1}{5} \\sin(10 x)\\}$" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "take 10 fourierTerms\n" ] }, { "cell_type": "markdown", "id": "8f1ad57d", "metadata": {}, "source": [ "Thus\n", "\n", "$$\n", "x=2\\sum_{k=1}^{\\infty}\\frac{(-1)^{k+1}}{k}\\sin(kx)\n", "\\qquad(-\\pi