{ "cells": [ { "cell_type": "markdown", "id": "4fe0795e", "metadata": {}, "source": [ "# フーリエ級数から導くライプニッツの公式\n", "\n", "ライプニッツ級数\n", "\n", "$$\n", "\\frac{\\pi}{4}=1-\\frac13+\\frac15-\\frac17+\\cdots\n", "$$\n", "\n", "は、のこぎり波$f(x)=x$のフーリエ級数に$x=\\pi/2$を代入すると\n", "得られます。このNotebookでは、代入する前にフーリエ係数を\n", "記号的に導出します。\n" ] }, { "cell_type": "markdown", "id": "7a46b4a7", "metadata": {}, "source": [ "## のこぎり波とその係数\n", "\n", "$f$は奇関数なので、正弦項だけが現れます。\n", "\n", "$$\n", "x=\\sum_{k=1}^{\\infty}b_k\\sin(kx),\\qquad\n", "b_k=\\frac1\\pi\\int_{-\\pi}^{\\pi}x\\sin(kx)\\,dx.\n", "$$\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "8fe91f34", "metadata": {}, "outputs": [], "source": [ "declare symbol x, n : MathValue\n", "\n", "def f (x : MathValue) : MathValue := x\n", "\n", "def cosinePrimitive (k : MathValue) : MathValue :=\n", " x * sin (k * x) / k + cos (k * x) / k^2\n", "\n", "def sinePrimitive (k : MathValue) : MathValue :=\n", " (- x) * cos (k * x) / k + sin (k * x) / k^2\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "ea1343e8", "metadata": {}, "outputs": [], "source": [ "def cosineCoefficients : [MathValue] :=\n", " map\n", " (\\k ->\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": 3, "id": "81fe69e4", "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": "92a62bbc", "metadata": {}, "source": [ "## フーリエ級数の各項\n", "\n", "次にEgisonで、各係数と対応する基底関数を組み合わせます。\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "d71c6139", "metadata": {}, "outputs": [], "source": [ "def fourierTerms : [MathValue] :=\n", " map (\\(k, b) -> b * sin (k * x)) (zip nats sineCoefficients)\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "64cced3c", "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": "08076199", "metadata": {}, "source": [ "## $x=\\pi/2$での値\n", "\n", "偶数次の調波は0になり、奇数次の調波は符号が交互に変わります。\n", "次の厳密な4周期のパターンを記述します。\n", "\n", "$$\n", "\\sin(k\\pi/2)=1,0,-1,0,\\ldots\n", "$$\n", "\n", "そのうえでフーリエ級数の各項を2で割ります。したがって恒等式\n", "$\\pi/2=2(1-1/3+1/5-\\cdots)$から、求める級数が得られます。\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "fb0deb25", "metadata": {}, "outputs": [], "source": [ "def sinAtHalfPi (k : Integer) : MathValue :=\n", " if isEven k\n", " then 0\n", " else (-1) ^ (i.quotient (k - 1) 2)\n", "\n", "def leibnizTerms : [MathValue] :=\n", " map\n", " (\\(k, b) -> b * sinAtHalfPi k / 2)\n", " (zip nats sineCoefficients)\n" ] }, { "cell_type": "code", "execution_count": 7, "id": "a08d47cd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "$\\{1, 0, \\frac{-1}{3}, 0, \\frac{1}{5}, 0, \\frac{-1}{7}, 0, \\frac{1}{9}, 0\\}$" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "take 10 leibnizTerms\n" ] }, { "cell_type": "markdown", "id": "7ad715af", "metadata": {}, "source": [ "0でない成分を読むと$1,-1/3,1/5,-1/7,\\ldots$が得られ、その\n", "無限和は$\\pi/4$です。間に現れる0は、$\\pi/2$で消える偶数次の\n", "フーリエモードに対応しています。\n" ] } ], "metadata": { "kernelspec": { "display_name": "Egison", "language": "egison", "name": "egison" }, "language_info": { "codemirror_mode": "egison", "file_extension": ".egi", "mimetype": "text/x-egison", "name": "egison" } }, "nbformat": 4, "nbformat_minor": 5 }