diff --git a/exp-224.ipynb b/exp-224.ipynb index 2d8fc2ce3e08d2b34968d6546e93b85856f8ab2c..da57ca4141745afc81d74378447cc5486b1fb806 100644 --- a/exp-224.ipynb +++ b/exp-224.ipynb @@ -14,21 +14,24 @@ "%matplotlib inline\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", - "from IPython.display import set_matplotlib_formats, display, Math\n", - "set_matplotlib_formats('svg')\n", + "from matplotlib_inline.backend_inline import set_matplotlib_formats\n", + "from IPython.display import display, Math\n", + "\n", + "set_matplotlib_formats(\"svg\")\n", "\n", "n = 40\n", - "h = 1/n\n", + "h = 1 / n\n", "\n", - "display(Math(r'''A = h \\begin{pmatrix} 1 & & & \\\\ 1 & 1 & &0 \\\\ \\vdots &\\vdots & \\ddots & \\\\ 1 & 1& \\dots & 1 \\end{pmatrix}'''))\n", - "A = h*np.tril(np.ones((n, n), dtype=int), 0)\n", + "display(Math(r\"\\text{Setting from Section 1.2:}\"))\n", + "display(Math(r\"A = h \\begin{pmatrix} 1 & & & \\\\ 1 & 1 & &0 \\\\ \\vdots &\\vdots & \\ddots & \\\\ 1 & 1& \\dots & 1 \\end{pmatrix}\\text{ (discrete integration matrix)}\"))\n", + "A = h * np.tril(np.ones((n, n), dtype=int), 0)\n", "\n", - "display(Math(r'''y= \\frac{1}{n}(1,1,\\ldots,1)^T'''))\n", - "y = np.ones(n)/n\n", - "display(Math(r'''\\delta y = \\frac{1}{n}(1,-1,1,-1, \\ldots)^T'''))\n", + "display(Math(r\"y= \\frac{1}{n}(1,1,\\ldots,1)^T\\text{ (low frequency input)}\"))\n", + "y = np.ones(n) / n\n", + "display(Math(r\"\\delta y = \\frac{1}{n}(1,-1,1,-1, \\ldots)^T\\text{ (high frequency pertubation)}\"))\n", "delta_y = y.copy()\n", - "delta_y[1::2] = -1/n\n", - "display(Math(r'''\\Rightarrow \\|y\\|_2= \\|\\delta y\\|_2= \\frac{1}{\\sqrt{n}}'''))" + "delta_y[1::2] = -1 / n\n", + "display(Math(r\"\\Rightarrow \\|y\\|_2= \\|\\delta y\\|_2= \\frac{1}{\\sqrt{n}}\"))" ], "outputs": [], "execution_count": null @@ -37,15 +40,15 @@ "cell_type": "code", "metadata": {}, "source": [ - "display(Math(r'U^TAV=\\Sigma'))\n", + "display(Math(r\"U^TAV=\\Sigma\"))\n", "U, sigma, VT = np.linalg.svd(A)\n", "\n", - "display(Math(r'\\hat y=U^Ty'))\n", + "display(Math(r\"\\hat y=U^Ty\"))\n", "y_hat = np.matmul(U.T, y)\n", - "display(Math(r'\\hat{\\delta y}:= U^T \\delta y'))\n", + "display(Math(r\"\\hat{\\delta y}:= U^T \\delta y\"))\n", "delta_y_hat = np.matmul(U.T, delta_y)\n", "\n", - "sigma_inv = 1/sigma\n", + "sigma_inv = 1 / sigma\n", "j = np.arange(1, 41)" ], "outputs": [], @@ -55,9 +58,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "plt.yscale('log')\n", - "plt.plot(j, np.abs(y_hat), '.', label=r'$|(U^Ty)_j|$')\n", - "plt.plot(j, np.abs(delta_y_hat), '+', label=r'$|(U^T \\delta y)_j|$')\n", + "plt.yscale(\"log\")\n", + "plt.plot(j, np.abs(y_hat), \".\", label=r\"$|(U^Ty)_j|$\")\n", + "plt.plot(j, np.abs(delta_y_hat), \"+\", label=r\"$|(U^T \\delta y)_j|$\")\n", "plt.legend()\n", "plt.show()" ], @@ -69,8 +72,8 @@ "metadata": {}, "source": [ "plt.close()\n", - "plt.yscale('log')\n", - "plt.plot(j, sigma_inv, '*', label=r'$\\sigma_j^{-1}$')\n", + "plt.yscale(\"log\")\n", + "plt.plot(j, sigma_inv, \"*\", label=r\"$\\sigma_j^{-1}$\")\n", "plt.legend()\n", "plt.show()" ], @@ -82,15 +85,22 @@ "metadata": {}, "source": [ "plt.close()\n", - "plt.yscale('log')\n", - "plt.plot(j, sigma_inv*np.abs(y_hat), '.', label=r'$\\sigma_j^{-1}|(U^Ty)_j|$')\n", - "plt.plot(j, sigma_inv*np.abs(delta_y_hat), '+', label=r'$\\sigma_j^{-1}|(U^T \\delta y)_j|$')\n", + "plt.yscale(\"log\")\n", + "plt.plot(j, sigma_inv * np.abs(y_hat), \".\", label=r\"$\\sigma_j^{-1}|(U^Ty)_j|$\")\n", + "plt.plot(j, sigma_inv * np.abs(delta_y_hat), \"+\", label=r\"$\\sigma_j^{-1}|(U^T \\delta y)_j|$\")\n", "plt.legend()\n", "plt.show()\n", - "display(Math(r'''\\Rightarrow\\ \\|A^{-1} y\\|_2 = \\|\\Sigma^{-1} \\hat{y}\\|_2 \\ll \\|A^{-1} \\delta y\\|_2= \\|\\Sigma^{-1} \\hat{\\delta y}\\|_2\\ \\Rightarrow\\ Q(y,\\delta y) \\gg 1'''))\n" + "display(Math(r\"\\Rightarrow\\ \\|A^{-1} y\\|_2 = \\|\\Sigma^{-1} \\hat{y}\\|_2 \\ll \\|A^{-1} \\delta y\\|_2= \\|\\Sigma^{-1} \\hat{\\delta y}\\|_2\\ \\Rightarrow\\ Q(y,\\delta y) \\gg 1\"))" ], "outputs": [], "execution_count": null + }, + { + "cell_type": "code", + "metadata": {}, + "source": [], + "outputs": [], + "execution_count": null } ], "metadata": { @@ -114,5 +124,5 @@ } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 } \ No newline at end of file