737 lines
169 KiB
Plaintext
737 lines
169 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "4cc6c96f",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Ćwiczenia 4"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "1276423e",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"***TEMAT:*** szeregi Fouriera"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "377a729f",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Ortogonalność układu trygonometrycznego"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "20c2c5c3",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"#### Zadanie 1\n",
|
||
|
"Pokaż, że:\n",
|
||
|
"\n",
|
||
|
"1.\n",
|
||
|
"\n",
|
||
|
" $$\\int_{-\\pi}^\\pi \\sin(nx)\\sin(mx)dx=\\begin{cases}\\pi, & n=m;\\\\\n",
|
||
|
"0,& n\\not= m;\n",
|
||
|
"\\end{cases}\n",
|
||
|
"$$\n",
|
||
|
"dla każdego $n,m\\geq 1$.\n",
|
||
|
"\n",
|
||
|
"2.\n",
|
||
|
"\n",
|
||
|
"$$\\int_{-\\pi}^\\pi \\cos(nx)\\cos(mx)dx=\\begin{cases}\\pi, & n=m\\not=0;\\\\\n",
|
||
|
"2\\pi, & n=m=0;\\\\\n",
|
||
|
"0,& n\\not= m;\n",
|
||
|
"\\end{cases}\n",
|
||
|
"$$\n",
|
||
|
"dla każdego $n,m\\geq 0$.\n",
|
||
|
"\n",
|
||
|
"3. \n",
|
||
|
"\n",
|
||
|
"$$\\int_{-\\pi}^\\pi \\sin(nx)\\cos(mx)dx=0\n",
|
||
|
"$$\n",
|
||
|
"dla każdego $n,m\\geq 0$.\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"***Uwaga:*** na wykładzie 6 okaże się, że powyższe rachunki oznaczają ortogonalność rodziny funkcji $\\{\\sin(nx),\\cos(mx): n\\geq 1, m\\geq 0\\}$."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "a9fe3612",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"##### Rozwiązanie:\n",
|
||
|
"1. \n",
|
||
|
"Jeśli $n=m$, to z \"jedynki trygonometrycznej\" i wzoru na cosinus podwojonego kąta wynika, że \n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"\\int_{-\\pi}^\\pi \\sin(nx)\\sin(nx)dx=\\frac{1}{2}\\int_{-\\pi}^\\pi 1- \\cos(2nx)dx=\\frac{1}{2}x-\\frac{\\sin(2nx)}{4n}\\biggr|_{-\\pi}^\\pi=\\pi.\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Jeśli $n\\not=m$, to wiadomo że \n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"\\sin(nx)\\sin(mx)=\\frac{1}{2}\\left( \\cos((n-m)x)-\\cos((n+m)x)\\right).\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Zatem\n",
|
||
|
"$$\n",
|
||
|
"\\int_{-\\pi}^\\pi \\sin(nx)\\sin(mx)dx=\\frac{1}{2}\\left(\\frac{\\sin((n-m)x)}{n-m}-\\frac{\\sin((n+m)x)}{n+m}\\right)\\biggr|_{-\\pi}^\\pi=0\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"2. Dowodzi się tego w identyczny sposób jak wzoru w 1. \n",
|
||
|
"\n",
|
||
|
"3. Wystarczy zauważyć, że jak $n=0$, to $\\sin(nx)\\cos(mx)$=0, a dla $n\\geq 1$ funkcja $\\sin(nx)\\cos(mx)$ jest nieparzysta.\n",
|
||
|
"\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "a92c3fcc",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Szereg Fouriera dla funkcji 2$\\pi$ okresowej: postać rzeczywista"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "be2929df",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Rozwijanie funkcji w szereg Fouriera"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "cb209cea",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"***Twierdzenie*** \n",
|
||
|
"\n",
|
||
|
"Jeżeli szereg trygonometryczny \n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"\\frac {\\displaystyle {a_0}}{\\displaystyle 2}+ \\sum_{n=1}^{\\infty}\n",
|
||
|
"(a_n\\cos nx+b_n\\sin nx)\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"jest zbieżny jednostajnie do funkcji $f$ na przedziale $[-\\pi,\\pi]$, to\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"a_0=\\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}f(x)\\; dx,\\quad\n",
|
||
|
"a_n=\\frac {\\displaystyle 1}{\\displaystyle {\\pi}} \\int_{-\\pi}^{\\pi}f(x)\\cos nx\\; dx,\\quad\n",
|
||
|
"b_n=\\frac {\\displaystyle 1}{\\displaystyle {\\pi}} \\int_{-\\pi}^{\\pi}f(x)\\sin nx \\; dx,\n",
|
||
|
"$$ \n",
|
||
|
"\n",
|
||
|
"dla $n=1,2,\\ldots$. "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "cd1dc617",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"***Definicja***\n",
|
||
|
"\n",
|
||
|
"Szereg \n",
|
||
|
"\n",
|
||
|
"$$\\frac {\\displaystyle {a_0}}{\\displaystyle 2}+ \\sum_{n=1}^{\\infty}(a_n\\cos nx+b_n\\sin nx),\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"w którym liczby $a_0,a_1,a_2,\\ldots$, $b_1,b_2,\\ldots$ są takie jak w twierdzeniu powyżej nazywamy szeregiem Fouriera odpowiadającym funkcji $f$."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "08b840ff",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"***Bardzo ważne uwagi:***\n",
|
||
|
">* na razie nic nie powiedzieliśmy o zbieżności szeregu Fouriera odpowiadającego funkcji $f$.\n",
|
||
|
">* jeśli $f$ jest funkcją parzystą, to w jej szeregu Fouriera wszystkie $b_n=0$.\n",
|
||
|
">* jeśli $f$ jest funkcją nieparzystą, to w jej szeregu Fouriera wszystkie $a_n=0$."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "dca41719",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Zbieżność szeregu Fouriera\n",
|
||
|
"\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "fc09b556",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"***Definicja (funkcja kawałkami gładka)***\n",
|
||
|
"\n",
|
||
|
">* Mówimy, że funkcja $f$ ma nieciągłość skokową w punkcie $x_0$, gdy istnieją granice jednostronne\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"f(x_0-):=\\lim_{x\\to x_0^-}f(x),\\quad f(x_0+):=\\lim_{x\\to x_0^+}f(x). \n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
">* Mówimy, że funkcja $f$ jest kawałkami gładka, gdy w dowolnym przedziale $(a,b)$ jest ciągła poza skończoną liczbą punktów przedziału $(a,b)$, jej punkty nieciągłości są nieciągłościami skokowymi, a pochodna funkcji $f$ jest ciągła poza skończoną liczbą punktów przedziału $(a,b)$."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "d7523627",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"***Twierdzenie***\n",
|
||
|
"\n",
|
||
|
"Jeśli $2\\pi$ okresowa funkcja $f$ jest kawałkami gładka na $\\mathbb{R}$, to jej szereg Fouriera jest zbieżny dla dowolnego \n",
|
||
|
"$x$ do wartości $\\frac{f(x-)+f(x+)}{2}$.\n",
|
||
|
"\n",
|
||
|
"***Uwaga:*** jeśli $f$ jest ciągła w punkcie $x$, to $\\frac{f(x-)+f(x+)}{2}=f(x)$."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "fd37d0aa",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"#### Zadanie 2: sygnał prostokątny \n",
|
||
|
"Rozwiniemy w szereg Fouriera funkcję $2\\pi $ okresową $f$ taką, że \n",
|
||
|
"$$\n",
|
||
|
"f(x)=\\begin{cases}\n",
|
||
|
"1, & x\\in[ 0,\\pi];\\\\\n",
|
||
|
"0, & x\\in (-\\pi,0).\n",
|
||
|
"\\end{cases}\n",
|
||
|
"$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"id": "a5896f29",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1EAAAIkCAYAAAD/HaFsAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAABGV0lEQVR4nO3deXxU1f3/8Xf2ECCAEJIAkYBVQBCQWNJQEamBsJQWFwS0soigQuoSv63itxLRalAs0q8/Km6ArTsuaL8iEKOolIgYTFUkIJQdEqAYggSSkJzfH/lmypBJyMkyW17Px2MeMHfOnXvyOffM5D33zk2AMcYIAAAAAFAngZ7uAAAAAAD4EkIUAAAAAFggRAEAAACABUIUAAAAAFggRAEAAACABUIUAAAAAFggRAEAAACABUIUAAAAAFggRAEAAACABUIUAAAAAFggRAEAAACABUIUAPigZcuWKSAgQLt27Wq053zwwQcVEBDQ5NvxNf5egylTpiggIEABAQHq06ePp7vjVRYuXOioTUBAgI4cOeLpLgHwEoQoAH5v48aNSk1NVe/evdWyZUudf/75uv7667Vt27ZG3U7VL9tVt/DwcF100UVKTU1VQUFBo27LF51dnzNv9913n0f7tn79ej344IMqLCz0aD88pUOHDvrb3/6mefPmNcrzbd68WePGjVP37t0VERGhDh066IorrtDf//73Rnl+d21zxIgR+tvf/qarr766EXsKwB8Ee7oDANDUHnvsMf3jH//QuHHj1LdvX+Xn5+v//b//pwEDBujzzz9v9E/fH3roIXXr1k2nTp3SunXr9PTTT2vlypX69ttvFRER0SjbuOmmmzRhwgSFhYU1yvO5cztV9TmTp4+ArF+/XnPnztWUKVPUtm1bp8fcVWtPatmypX7zm9802vPt3r1bx48f1+TJk9WpUycVFxfrrbfe0q9+9Ss988wzmjFjRqNtqym32bNnT/Xs2VPbt2/XO++80+h9BuC7CFEA/F5aWppeeeUVhYaGOpaNHz9el1xyiebNm6eXXnqpUbc3cuRIXXbZZZKkW265Re3bt9eCBQv07rvvauLEiQ167hMnTqhly5YKCgpSUFBQY3S3Vk2xnTPr4wvcVWt/MmrUKI0aNcppWWpqqhISErRgwYImCVGe2CaA5ovT+QD4vUGDBjkFKEm68MIL1bt3b23ZssWxbObMmTWeblZ1q8/3Yn7xi19Iknbu3OlYtn//ft18882Kjo5WWFiYevfurSVLljitV/Udpe+++0433HCD2rVrp8svv1xSzd/T+eqrrzRy5EhFRkaqVatWuuqqq/T5559X69O6dev005/+VOHh4brgggv0zDPPuOy7q+3s379f06ZNU6dOnRQWFqZu3brp9ttvV2lpqXVtzjZlyhTFx8dXW+7q+1pVy7Zv3+44gtSmTRtNnTpVxcXFTm1r6/ODDz6o3/3ud5Kkbt26VRtrVzWoa51t+uiKu7bjDkFBQYqLi3M6ZbKp5lxt23THdgH4P45EAWiWjDEqKChQ7969HcuuvfZa5eTkaM+ePZo/f75jeXp6usLDw/WHP/zB5S/457Jjxw5JUvv27SVJBQUF+tnPfqaAgAClpqYqKipKH3zwgaZNm6aioiLdddddTuuPGzdOF154oR599FEZY2rczubNmzV48GBFRkbq97//vUJCQvTMM8/oyiuv1CeffKLExERJ0jfffKPhw4crKipKDz74oE6fPq309HRFR0ef82c5cOCABg4cqMLCQs2YMUM9e/bU/v379eabb6q4uLhaWHXl2LFj1b6g36FDh3OuV5Prr79e3bp1U0ZGhjZt2qTnn39eHTt21GOPPVanPl9zzTXatm2bXn31VT355JOOvkRFRbncXl3rbNNHT26nKZ04cUInT57UsWPH9N577+mDDz7Q+PHjHY83xZw71zabarsAmhkDAM3Q3/72NyPJvPDCC07L+/fvb0aOHOm0rG3btmbGjBnnfM6lS5caSebDDz80hw8fNnv37jWvvfaaad++vWnRooXZt2+fMcaYadOmmdjYWHPkyBGn9SdMmGDatGljiouLjTHGpKenG0lm4sSJNW5r586djmVjx441oaGhZseOHY5lBw4cMK1btzZXXHGFU7vw8HCze/dux7LvvvvOBAUFmbPfFs7ezqRJk0xgYKDZuHFjtT5VVFTUqT6ublUmT55sunbtWm3dqlq4WnbzzTc7Lb/66qtN+/btHffr0uf58+dXq+fZ/a56rK51tumjK+7aTk01bwy33nqrY4wDAwPNddddZ44ePerUpiFzrr7btN1uVX0PHz5crz4B8D+czgeg2cnLy9OsWbOUlJSkyZMnO5aXl5crLy/P6SIHe/fuVWFhodWFD5KTkxUVFaW4uDhNmDBBrVq10jvvvKPOnTvLGKO33npLY8aMkTFGR44ccdxSUlJ07Ngxbdq0yen5brvttnNus7y8XGvWrNHYsWPVvXt3x/LY2FjdcMMNWrdunYqKilReXq7Vq1dr7NixOv/88x3tevXqpZSUlFq3UVFRoRUrVmjMmDEuv9N09ul2NVm0aJEy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KiBJBw8erPcfOq1rn1u2bClJLgPcmepa54Zy13aaytmnpEpSWVmZ/vrXv6pFixaODzHqMucae5uNvV0AzRNHogD4vXvuuUfvvfeexowZo6NHj1b747q/+c1vJFX+YnX2L1H5+fmKiIhQYWGh2rZt2yj9mTdvnj7++GMlJiZq+vTpuvjii3X06FFt2rRJH374YbXvXNXVH//4R2VmZuryyy/XzJkzFRwcrGeeeUYlJSV6/PHHHe3mzp2rVatWafDgwZo5c6ZOnz6tp556Sr1793YKL648+uijWrNmjYYMGaIZM2aoV69eOnjwoJYvX65169Y1uEYTJkzQvffeq6uvvlp33HGHiouL9fTTT+uiiy6qdsGNuqpLnxMSEiRJ//3f/60
|
||
|
"text/plain": [
|
||
|
"<Figure size 1000x600 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"\n",
|
||
|
"# Define the piecewise function that is 0 on (-pi, 0) and 1 on [0, pi)\n",
|
||
|
"def periodic_piecewise(x):\n",
|
||
|
" # Bring x into the interval [-pi, pi] using modulo\n",
|
||
|
" x_mod = np.mod(x + np.pi, 2 * np.pi) - np.pi\n",
|
||
|
" # Define the piecewise function\n",
|
||
|
" return np.where(x_mod >= 0, 1, 0)\n",
|
||
|
"\n",
|
||
|
"# Generate x values from -3pi to 3pi\n",
|
||
|
"x = np.linspace(-3 * np.pi, 3 * np.pi, 1000)\n",
|
||
|
"y = periodic_piecewise(x)\n",
|
||
|
"\n",
|
||
|
"# Plot the periodic function without vertical lines at discontinuities\n",
|
||
|
"plt.figure(figsize=(10, 6))\n",
|
||
|
"\n",
|
||
|
"# Split the data into segments between -pi and pi to avoid vertical lines\n",
|
||
|
"for n in range(-3, 3):\n",
|
||
|
" x_segment = x[(x >= n * np.pi) & (x < (n + 1) * np.pi)]\n",
|
||
|
" y_segment = y[(x >= n * np.pi) & (x < (n + 1) * np.pi)]\n",
|
||
|
" plt.plot(x_segment, y_segment, color='r',linewidth=4)\n",
|
||
|
"\n",
|
||
|
"# Mark closed and open dots at the ends of intervals\n",
|
||
|
"for n in range(-3,4):\n",
|
||
|
" plt.plot(n * np.pi, 1, 'bo',) # Closed dot for x = n*pi and f(x) = 1\n",
|
||
|
"\n",
|
||
|
"for n in range(-3,4):\n",
|
||
|
" plt.plot(n * np.pi, 0, 'wo', markersize=10, markeredgecolor='b') # Open dot for x = n*pi and f(x) = 1\n",
|
||
|
"\n",
|
||
|
"# Add axis lines\n",
|
||
|
"plt.axhline(0, color='black', linewidth=2)\n",
|
||
|
"plt.axvline(0, color='black', linewidth=1)\n",
|
||
|
"\n",
|
||
|
"# Set labels and title\n",
|
||
|
"plt.title(r'2$\\pi$-Periodic Function on $[-3\\pi, 3\\pi]$')\n",
|
||
|
"plt.xlabel(r'$x$')\n",
|
||
|
"plt.ylabel(r'$f(x)$')\n",
|
||
|
"\n",
|
||
|
"# Add grid \n",
|
||
|
"plt.grid(True)\n",
|
||
|
"\n",
|
||
|
"# Show the plot\n",
|
||
|
"plt.show()\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "32158b3c",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"##### Rozwiązanie:\n",
|
||
|
"Mamy:\n",
|
||
|
"\n",
|
||
|
"1.\n",
|
||
|
"$$\n",
|
||
|
"a_0=\\frac{1}{\\pi}\\int_{-\\pi}^\\pi f(x)dx=\\frac{1}{\\pi}\\int_0^\\pi 1dx=1.\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"2. Dla $n\\geq 1$\n",
|
||
|
"$$\n",
|
||
|
"a_n = \\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) \\cos(nx) \\, dx = \\frac{1}{\\pi} \\int_0^\\pi \\cos(nx) \\, dx = \\frac{\\sin(nx)}{\\pi n} \\bigg|_0^\\pi = 0.\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"3. Dla $n\\geq 1$\n",
|
||
|
"$$\n",
|
||
|
"b_n = \\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) \\sin(nx) \\, dx = \\frac{1}{\\pi} \\int_{0}^{\\pi} \\sin(nx) \\, dx = -\\frac{\\cos(nx)}{\\pi n} \\bigg|_{0}^{\\pi} = -\\frac{(-1)^n - 1}{\\pi n}=\\frac{1-(-1)^n}{\\pi n}.\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Ostatecznie szereg Foueriera naszej funkcji, to szereg\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"\\frac{1}{2}+\\sum_{n=1}^\\infty\\frac{1-(-1)^n}{\\pi n}\\sin(nx).\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Zgodnie z twierdzeniem powyżej, dla $x$ będących całkowitymi wielokrotnościami $\\pi$ jest on zbieżny do $1/2$, dla pozostałych \n",
|
||
|
"$x$ jest on zbieżny do $f(x)$."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"id": "adb272c0",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1EAAAIlCAYAAAA0QXLJAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAACtNElEQVR4nOzdd3gU1foH8O9uskkIkAASegeldyGCFJUeLlYUxCvFLuBVudfCvQpiw65XfyjqFbBgw14i0kUEkRbpIB3pNQlJSDbZ+f1xnOwm2d3MbLbMOfv9PE+e3WxmZyez85457zlnztg0TdNAREREREREhtgjvQFEREREREQyYRJFRERERERkApMoIiIiIiIiE5hEERERERERmcAkio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3uzsbNx3331o0qQJ4uPjUatWLQwYMADr16/3+//p5s6di+rVq2Po0KEYPnw45s6dW2YZfdu3b9+OG264AUlJSbjgggtw77334vz58wEtW953Ut5xlZeXh1atWqFVq1bIy8srfv306dOoW7cuevbsiaKiIp/7V//8nTt34u9//zuSk5ORkpKCRx99FJqm4eDBg7jqqquQlJSEOnXq4MUXXyzxf+7fvx/jx49Hy5YtUalSJVxwwQW4/vrry3zGAw88AABo2rRp8XAxfRlv22Uknjy3f9euXRg7diyqVauG5ORkjBs3Drm5uWWWL81o3Pbt2xcAcP3118Nms+Gyyy7zuU4jMVPePgHMxZORYzJQgZRbRr+PQ4cO4dZbb0W9evUQHx+Ppk2b4u6770ZBQYHffeSrrDDyfVb0mAnn54RaTEwMGjZsWGa45Pjx430O8/R2rFr9M4kqgj1RRBWUmZlZ5gJWfQjBli1b0Lt3byQlJeHBBx+Ew+HAm2++icsuuww//fRTha6xuf7663HhhRfi6aefhq9RuceOHcMll1wCm82GiRMnIiUlBT/88ANuvfVWZGVl4b777jO9Tl3jxo2xatUqbN682e/FzaHaBqPrveuuu/DZZ59h4sSJaNOmDU6dOoUVK1Zg27Zt6NKli9//ERBJ1LXXXou4uDjceOONeOONN7BmzRp069atzLI33HADmjRpgunTp+PXX3/Fq6++ijNnzuC9994LeFlv+8PIcVWpUiW8++67uPTSS/Gf//wHL730EgBgwoQJyMzMxJw5cwy12I8YMQKtW7fGM888g++//x5PPvkkatSogTfffBNXXHEFnn32WcydOxf/+te/0K1bN/Tp0weAmGxh5cqVGDlyJBo0aIB9+/bhjTfewGWXXYatW7ciMTER1157LXbu3ImPPvoIL7/8cnHcpKSkeN2WQOLphhtuQNOmTTF9+nSsX78e//vf/1CrVi08++yzPv9no59z5513on79+nj66afxj3/8A926dUPt2rV9rtdIzJS3T8zGk5lj0ht/5VsgjHwfhw8fRvfu3XH27FnccccdaNWqFQ4dOoTPPvsMubm5IT9uAjlmwvk5oZKTk4O8vDxkZmbim2++wQ8//IARI0aUW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FDhqCoqAgFBQVl/s/t27eX6Ek9ePAgzp49G9B065H4TKJg4XA+ogrq3r2715P9iRMnkJubi5YtW5b5W+vWreFyuXDw4EG0bds2oM8tPWOWt88/e/Ys3nrrLbz11ltelyl9MXt56yytW7du+OKLL1BQUIDff/8dX375JV5++WUMHz4cGRkZqFmzZki2wcz/9txzz2HMmDFo2LAhunbtirS0NIwePbpERceboqIifPzxx7j88suxd+/e4tdTU1Px4osvYvHixRg4cGCJ91x44YUlfm/evDnsdrvX8fpGly29P8weV3FxcZg1axa6deu
|
||
|
"text/plain": [
|
||
|
"<Figure size 1000x600 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"\n",
|
||
|
"# Function to compute the Fourier series approximation\n",
|
||
|
"def fourier_series_step_function(x, n_terms):\n",
|
||
|
" result = 0.5 # a_0 / 2 term\n",
|
||
|
" for n in range(1, n_terms + 1, 2): # Only odd terms contribute\n",
|
||
|
" result += (2 / (n * np.pi)) * np.sin(n * x)\n",
|
||
|
" return result\n",
|
||
|
"\n",
|
||
|
"# Generate x values from -3pi to 3pi\n",
|
||
|
"x = np.linspace(-3 * np.pi, 3 * np.pi, 1000)\n",
|
||
|
"\n",
|
||
|
"# Compute Fourier series approximation with a certain number of terms\n",
|
||
|
"n_terms = 10 # You can increase this for a better approximation\n",
|
||
|
"y = fourier_series_step_function(x, n_terms)\n",
|
||
|
"\n",
|
||
|
"# Plot the Fourier series\n",
|
||
|
"plt.figure(figsize=(10, 6))\n",
|
||
|
"plt.plot(x, y, color='b')\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"# Add axis lines\n",
|
||
|
"plt.axhline(0, color='black', linewidth=2)\n",
|
||
|
"plt.axhline(0.5, color='red', linewidth=0.5)\n",
|
||
|
"plt.axvline(0, color='black', linewidth=2)\n",
|
||
|
"\n",
|
||
|
"# Set labels and title\n",
|
||
|
"plt.title(r'Fourier Series Approximation of Step Function on $[-3\\pi, 3\\pi]$')\n",
|
||
|
"plt.xlabel(r'$x$')\n",
|
||
|
"plt.ylabel(r'$f(x)$')\n",
|
||
|
"\n",
|
||
|
"# Add grid, legend, and show the plot\n",
|
||
|
"plt.grid(True)\n",
|
||
|
"\n",
|
||
|
"plt.show()\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "c5696a45-314e-475f-8aae-ffdf77d1834d",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"***Zadanie domowe:***\n",
|
||
|
"Zapoznaj się z materiałem znajdującym się tutaj: https://en.wikipedia.org/wiki/Gibbs_phenomenon."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "9bc09abd",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"#### Zadanie 3: sygnał trójkątny\n",
|
||
|
"\n",
|
||
|
"Rozwiniemy w szereg Fouriera funkcję $2\\pi $ okresową $f$ taką, że \n",
|
||
|
"$f(x)=|x|$ dla $x\\in[-\\pi,\\pi]$."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "11e821aa",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"##### Rozwiązanie\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"1. Obliczamy $a_0$:\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"a_0 = \\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) \\, dx = \\frac{2}{\\pi} \\int_{0}^{\\pi} x \\, dx = \\pi.\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"2. Obliczamy $a_n$:\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"a_n = \\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) \\cos(nx) \\, dx = \\frac{2}{\\pi} \\int_{0}^{\\pi} x \\cos(nx) \\, dx=\n",
|
||
|
"\\frac{2}{\\pi}\\left( \\frac{x \\sin(nx)}{n} + \\frac{\\cos(nx)}{n^2} \\right) \\bigg|_{0}^{\\pi}=\n",
|
||
|
"2\\frac{(-1)^n-1}{\\pi n^2}\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"3. Wszystkie współczynniki $b_n$ są równe 0, bo funkcja jest parzysta.\n",
|
||
|
"\n",
|
||
|
"Ostatecznie, szereg Fouriera funkcji $f(x) = |x|$ to\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"\\frac{\\pi}{2} + \\sum_{n=1}^{\\infty} 2\\frac{(-1)^n-1}{\\pi n^2} \\cos(nx).\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Dla każdego $x$ jest on zbieżny do $f(x)$.\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"id": "38bcc701",
|
||
|
"metadata": {
|
||
|
"scrolled": true
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1EAAAIlCAYAAAA0QXLJAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAADIhUlEQVR4nOzdeXhbZ5k+/vtot2xL8m7Hu2Nnb/bN2bukG5Qp0EKBfrsApdAW6HSGznSYgRYoZehA4ce+TFuWFphC2wGmLQlNs9rZ99XxEttxvNtabNlaz+8P6ch2YieWLekcSffnunJdjSpLj0/0Hp3nPc/zvoIoiiKIiIiIiIhoUlRyB0BERERERBRPmEQRERERERGFgUkUERERERFRGJhEERERERERhYFJFBERERERURiYRBEREREREYWBSRQREREREVEYmEQRERERERGFgUkUERERERFRGJhEERERERERhYFJFBERERERURiYRBGR7F5++WUIgoALFy7IHUpEJervpRRKPb5KjetyBw4cwJo1a5CamgpBEHD06NEJn1tWVoann356Su8znZ+NhgceeACCIEAQBCxYsEDucBTje9/7Xui4CIKAnp4euUMiUjQmUURJRrrAG+/Pv/7rv8odXkycOHECd911F0pLS2EwGFBYWIjNmzfjBz/4gdyhRdSPf/xjCIKAVatWyR1KwqmpqcHTTz8Nq9UqdyhT4vF4cPfdd6Ovrw8vvPACfvOb36C0tFTusGImOzsbv/nNb/Ctb31r2q916tQp3H333aioqIDRaER2djY2bNiAv/zlLxGINHbve+utt+I3v/kNPvjBD0Y4UqLEpJE7ACKSx9e+9jWUl5ePeUyuWdn/9//+H+655x7o9fqov1dNTQ2uv/56lJSU4KGHHkJ+fj5aW1uxd+9efP/738fnP//5iL1XLH+v8bzyyisoKyvD/v37UV9fj8rKSlniiBY5j29NTQ2eeeYZPPDAA7BYLIqJa7IaGhrQ3NyMX/ziF/j0pz8tdzgxl5qainvvvTcir9Xc3AyHw4H7778fM2bMgNPpxJ/+9Cd84AMfwM9+9jN85jOficj7RPt958yZgzlz5qC+vh5vvPFGVGImSiRMooiS1G233Ybly5fLGsPg4CBSU1OhVquhVqsj+poTefbZZ2E2m3HgwIErLn67uroiGkMkf69wNTU1oaamBq+//joefvhhvPLKK/jqV78qSyzX+jeZKjmP79UoNa7RpM/65WOAwnf77bfj9ttvH/PYY489hmXLluG73/1u1JIoud6XiAJYzkdE4zpy5Ahuu+02mEwmpKWl4cYbb8TevXvHPOeBBx5AWVnZFT/79NNPQxCEcR87ffo0Pv7xjyMjIwPr1q0DMH4PSVtbGz75yU8iLy8Per0e8+fPx4svvjjp15xIQ0MD5s+fP+7FY25u7pi/TzeGiXpjJvO6DocDjz/+OMrKyqDX65Gbm4vNmzfj8OHDV/39JK+88goyMjLwvve9D3fddRdeeeWVK54jxX727Fl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bZ3y+16+IuDluru7YbVa8fOf/xw5OTlj/jz44IMArlwA4lqvebkVK1bg9ddfR39/P/bv34+nnnoKDocDd911F06fPh21GMJ53W9/+9s4efIkiouLsXLlSjz99NNjLvYn4vP58Pvf/x7XX389mpqaUF9fj/r6eqxatQqdnZ149913r/iZqqqqMX+fOXMmVCrVuH0Sk33u5ccj3M+VTqfDiy++iKamJjgcDrz00ktX9NldTUlJyZi/m81mGAyGUOnd6Mf7+/tDfx8aGsJXvvIVFBcXQ6/XIzs7Gzk5ObBarbDZbJN+f8lUx9Pl8WdkZADAmFgj8T7T9c///M9
|
||
|
"text/plain": [
|
||
|
"<Figure size 1000x600 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"\n",
|
||
|
"# Function to compute the Fourier series of |x|\n",
|
||
|
"def fourier_series_abs_x(x, n_terms):\n",
|
||
|
" # Start with the a_0 term which is pi/2\n",
|
||
|
" result = np.pi / 2\n",
|
||
|
" for n in range(1, n_terms + 1):\n",
|
||
|
" # Add the cosine terms with alternating signs\n",
|
||
|
" result += (2 / np.pi) * (((-1)**n -1)/ n**2) * np.cos(n * x)\n",
|
||
|
" return result\n",
|
||
|
"\n",
|
||
|
"# Generate x values from -3pi to 3pi\n",
|
||
|
"x = np.linspace(-3 * np.pi, 3 * np.pi, 1000)\n",
|
||
|
"\n",
|
||
|
"# Compute Fourier series approximation for |x|\n",
|
||
|
"n_terms = 10 # Number of terms in the series\n",
|
||
|
"y = fourier_series_abs_x(x, n_terms)\n",
|
||
|
"\n",
|
||
|
"# Plot the Fourier series\n",
|
||
|
"plt.figure(figsize=(10, 6))\n",
|
||
|
"plt.plot(x, y, label=f'Fourier series approximation with {n_terms} terms')\n",
|
||
|
"plt.axhline(0, color='black',linewidth=0.5)\n",
|
||
|
"plt.axvline(0, color='black',linewidth=0.5)\n",
|
||
|
"plt.title(r'Fourier Series Approximation of $|x|$ on $[-3\\pi, 3\\pi]$')\n",
|
||
|
"plt.xlabel(r'$x$')\n",
|
||
|
"plt.ylabel(r'$f(x)$')\n",
|
||
|
"plt.grid(True)\n",
|
||
|
"plt.legend()\n",
|
||
|
"plt.show()\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "bd160a96-1974-4b77-a4cc-28426c86492d",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Szereg Fouriera dla funkcji 2$\\pi$ okresowej: postać zespolona"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "f3c90b20",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"#### Zadanie 4\n",
|
||
|
"\n",
|
||
|
"Wyprowadzimy zespoloną postać szeregu Fouriera."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "f884eb58",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"##### Rozwiązanie:\n",
|
||
|
"Wiemy, że\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"e^{ix}=\\cos x +i\\sin x\\quad\\text{oraz}\\quad e^{-ix}=\\cos x -i\\sin x. \n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Stąd\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"\\cos x=\\frac{e^{ix}+e^{-ix}}{2}\\quad\\text{i}\\quad\\sin x=-i\\frac{e^{ix}-e^{-ix}}{2}.\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Zatem\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"\\begin{align}\n",
|
||
|
"\\frac{a_0}{2}+\\sum_{n=1}^\\infty\\left( a_n\\cos(nx)+b_n\\sin(nx)\\right)=&\\frac{a_0}{2}+\n",
|
||
|
"\\sum_{n=1}^\\infty \\left(a_n\\frac{e^{inx}+e^{-inx}}{2}-ib_n\\frac{e^{inx}-e^{-inx}}{2}\\right)\\\\\n",
|
||
|
"=&\\frac{a_0}{2}+\\sum_{n=1}^\\infty\\left(\\frac{a_n-ib_n}{2}e^{inx}+\\frac{a_n+ib_n}{2}e^{-inx}\\right)\\\\\n",
|
||
|
"=& \\sum_{n=-\\infty}^\\infty c_ne^{inx},\n",
|
||
|
"\\end{align}\n",
|
||
|
"$$\n",
|
||
|
"gdzie \n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"c_0=\\frac{a_0}{2},\\quad c_n=\\begin{cases}\n",
|
||
|
"\\frac{a_n-ib_n}{2}, & n>0;\\\\\n",
|
||
|
"\\frac{a_{-n}+ib_{-n}}{2},& n<0.\n",
|
||
|
"\\end{cases}\n",
|
||
|
"$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "7161cd41-8b0a-4ebf-86db-2b65f458a7f8",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"***Uwaga:***\n",
|
||
|
"\n",
|
||
|
"Można sprawdzić, że dla każdego $n\\in\\mathbb{Z}$ mamy:\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"c_n=\\frac{1}{2\\pi}\\int_{-\\pi}^\\pi f(x)e^{-inx}dx.\n",
|
||
|
"$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "ca4bdcd9",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"#### Zadanie 5: sygnał prostokątny po raz drugi\n",
|
||
|
"Rozwiniemy w zespolony szereg Fouriera funkcję $2\\pi$ okresową $f$ taką, że \n",
|
||
|
"$$\n",
|
||
|
"f(x)=\\begin{cases}\n",
|
||
|
"1, & x\\in[ 0,\\pi];\\\\\n",
|
||
|
"0, & x\\in (-\\pi,0).\n",
|
||
|
"\\end{cases}\n",
|
||
|
"$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "c375f201-b97b-4c4b-a8a3-92789821a471",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"##### Rozwiązanie I\n",
|
||
|
"Wiemy już, że:\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"a_0=1 \\text{ oraz } a_n = 0, b_n =\\frac{1-(-1)^n}{\\pi n} \\text{ dla }n\\geq 1.\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Zatem \n",
|
||
|
"$$\n",
|
||
|
"c_0=\\frac{1}{2}\n",
|
||
|
"$$\n",
|
||
|
"oraz\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"c_n=\\begin{cases}\n",
|
||
|
"i\\frac{(-1)^n-1}{2\\pi n}, & n>0\\\\\n",
|
||
|
"i\\frac{(-1)^n-1}{2\\pi n}, & n<0\n",
|
||
|
"\\end{cases}\n",
|
||
|
"$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "81b0a878-4faa-479b-bb85-842fcd0870b1",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"##### Rozwiązanie II\n",
|
||
|
"Mamy\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"c_0=\\frac{1}{2\\pi}\\int_{-\\pi}^\\pi f(x)dx=\\frac{1}{2\\pi}\\int_{0}^\\pi1dx=\\frac{1}{2}.\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Dla całkowitych $n\\not=0$ mamy\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"c_n=\\frac{1}{2\\pi}\\int_{-\\pi}^\\pi f(x)e^{-inx}dx=\\frac{1}{2\\pi}\\int_{0}^\\pi e^{-inx}dx=\n",
|
||
|
"\\frac{e^{-inx}}{-2in\\pi}\\big|_0^\\pi=\\frac{(-1)^n-1}{-2in\\pi}=i\\frac{(-1)^n-1}{2n\\pi}.\n",
|
||
|
"$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "0e920dd6",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Zastosowanie: sumowanie pewnych szeregów"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "1bb51ff4",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"#### Zadanie 6\n",
|
||
|
"Rozwiniemy w szereg Fouriera $2\\pi$ okresową funkcję $f$ taką, że $f(x)=x^2$ dla $x\\in[-\\pi,\\pi]$.\n",
|
||
|
"Następnie na dwa sposoby policzymy wartość tej funkcji dla $x=\\pi$. Na końcu sprawdzimy co dla tej funkcji oznacza tożsamość Parservala."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "25e6e515-f309-45fd-b285-28cdfe99dbfe",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"##### Rozwiązanie:\n",
|
||
|
" Wszystkie współczynniki $b_n=0$, bo funkcja $f$ jest parzysta.\n",
|
||
|
"Łatwo jest policzyć, że \n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"a_0=\\frac{2}{3}\\pi^2.\n",
|
||
|
"$$\n",
|
||
|
"Ponadto dwukrotne całkowanie przez części daje, że dla $n\\geq 1$ mamy\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"a_n=4\\frac{(-1)^n}{n^2}.\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Stąd \n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"f(x)=\\frac{\\pi^2}{3}+4\\sum_{n=1}^\\infty \\frac{(-1)^n}{n^2}\\cos(nx).\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Podstawiając $x=\\pi$\n",
|
||
|
"otrzymujemy, że \n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"\\pi^2=\\frac{\\pi^2}{3}+4\\sum_{n=1}^\\infty\\frac{1}{n^2}.\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Stąd\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"\\sum_{n=1}^\\infty\\frac{1}{n^2}=\\frac{\\pi^2}{6}.\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Przypomnijmy teraz, że tożsamość Parservala mówi, że dla odpowiednio \"dobrych\" funkcji mamy:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "cbfb72bc-39e7-44b4-acca-455deebea3fd",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"***Twierdzenie***\n",
|
||
|
"$$\n",
|
||
|
"\\frac{a_0^2}{2}+\\sum_{n=1}^{\\infty}(a_n^2+b_n^2)=\\frac{1}{\\pi}\\Vert f \\Vert_2^2.\n",
|
||
|
"$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "d7e4ffb0-afe2-499c-9f11-160ec7b5967f",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Mamy\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"\\frac{1}{\\pi}\\Vert f \\Vert_2^2=\\frac{1}{\\pi}\\int_{-\\pi}^\\pi x^4dx=\\frac{2\\pi^4}{5}.\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Podstawiając to do wzoru otrzymujemy po prostych przekształceniach, że \n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"\\sum_{n=1}^\\infty\\frac{1}{n^4}=\\frac{\\pi^4}{90}.\n",
|
||
|
"$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "e6763551-2bc9-46c4-9fb0-29efd59afb86",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3 (ipykernel)",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
},
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"nbconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": "3.12.4"
|
||
|
},
|
||
|
"toc": {
|
||
|
"base_numbering": 1,
|
||
|
"nav_menu": {},
|
||
|
"number_sections": false,
|
||
|
"sideBar": true,
|
||
|
"skip_h1_title": false,
|
||
|
"title_cell": "Table of Contents",
|
||
|
"title_sidebar": "Contents",
|
||
|
"toc_cell": false,
|
||
|
"toc_position": {},
|
||
|
"toc_section_display": true,
|
||
|
"toc_window_display": true
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 5
|
||
|
}
|