diff --git a/exp-233.ipynb b/exp-233.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..65bc6fbb7b690d768fd26fd08e8ed450a3f09271 --- /dev/null +++ b/exp-233.ipynb @@ -0,0 +1,104 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### IPython notebook for Example 2.3.3 from the lecture" + ] + }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "import numpy as np\n", + "from IPython.display import display, Math\n", + "\n", + "display(Math(r'A \\in \\mathbb{R}^{6 \\times 3}, A_1 \\in \\mathbb{R}^{6 \\times 4}\\text{ from Example 1.1.1}'))\n", + "delta_t = 0.15\n", + "n = 6\n", + "t = np.arange(1, n+1) * delta_t\n", + "A_1 = np.stack((t, np.exp(t), t**3, np.sin(t)), axis=1)\n", + "A = A_1[:, :-1]\n", + "print(\"A_1 = \")\n", + "print(A_1)\n", + "print(\"A = \")\n", + "print(A)" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "display(Math(r'U^TAV=\\Sigma'))\n", + "U, sigma, VT = np.linalg.svd(A)\n", + "np.set_printoptions(precision=4, suppress=True)\n", + "print(\"sigma(A) =\", sigma)\n", + "print(\"kappa(A) = {:.1f}\".format(sigma[0]/sigma[-1]))" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "display(Math(r'U_1^TA_1V_1=\\Sigma_1'))\n", + "U_1, sigma_1, VT_1 = np.linalg.svd(A_1)\n", + "np.set_printoptions(precision=5)\n", + "print(\"sigma(A_1) =\", sigma_1)\n", + "print(\"kappa(A_1) = {:.1e}\".format(sigma_1[0]/sigma_1[-1]))" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "display(Math(r'\\delta y^1=10^{-2} \\begin{pmatrix} 1 & 0 & -1 & -1 & -0.5 & 1 \\end{pmatrix}^T'))\n", + "delta_y1 = 1e-2*np.array([1, 0, -1, -1, -0.5, 1])\n", + "display(Math(r'\\delta y^2=10^{-2}\\begin{pmatrix} -1 & 1 & 1 & -0.5 & -2 & 1 \\end{pmatrix}^T'))\n", + "delta_y2 = 1e-2*np.array([-1, 1, 1, -0.5, -2, 1])" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "np.set_printoptions(precision=4)\n", + "print(\"U_1^T\\delta y^1 =\", np.matmul(U_1.T, delta_y1))\n", + "print(\"U_1^T\\delta y^2 =\", np.matmul(U_1.T, delta_y2))\n", + "display(Math(r'\\Rightarrow\\ \\delta y^1\\text{ is dominated by }u_3, \\delta y^2\\text{ dominated by }u_4'))\n" + ], + "outputs": [], + "execution_count": null + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python 3", + "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.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} \ No newline at end of file