diff --git a/pct/modules/04/linear-equations.ipynb b/pct/modules/04/linear-equations.ipynb index 294a3e2..48d043d 100644 --- a/pct/modules/04/linear-equations.ipynb +++ b/pct/modules/04/linear-equations.ipynb @@ -69,7 +69,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -106,7 +106,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -144,21 +144,26 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Non-Inversion Method\n", - "\n", - "\n", - "But it is never a good idea to use the inverse of a matrix to solve the linear equations, because it can be \n", + "But it is **never a good idea** to use matrix inverse to solve the linear equations, because it can be\n", "- numerically unstable\n", "- computationally expensive\n", "\n", - "For interested readers, here's a good writeup on [why one should never invert a matrix for Ax=b](https://gregorygundersen.com/blog/2020/12/09/matrix-inversion/).\n", + "For interested readers, here's a good writeup on [why one should never invert a matrix for Ax=b](https://gregorygundersen.com/blog/2020/12/09/matrix-inversion/).\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Non-Inversion Method\n", + "\n", "\n", - "In Python, we can use the `np.linalg.solve` function to solve the linear equations.\n" + "Instead, we can use the `np.linalg.solve` function to solve the linear equations.\n" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -195,7 +200,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -251,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -290,7 +295,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -362,7 +367,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -394,7 +399,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -441,7 +446,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -511,7 +516,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -545,14 +550,14 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "File downloaded and saved to /tmp/tmpeno7e_rq.m\n", + "File downloaded and saved to /tmp/tmpgjvea826.m\n", "File size: 1530051 bytes\n" ] } @@ -593,7 +598,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -621,7 +626,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -631,7 +636,7 @@ "\twith 154958 stored elements and shape (19928, 19928)>" ] }, - "execution_count": 12, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -642,14 +647,14 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "27.2 ms ± 594 μs per loop (mean ± std. dev. of 5 runs, 20 loops each)\n" + "27 ms ± 560 μs per loop (mean ± std. dev. of 5 runs, 20 loops each)\n" ] } ], @@ -674,14 +679,14 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "40.2 ms ± 3.57 ms per loop (mean ± std. dev. of 5 runs, 20 loops each)\n" + "36.6 ms ± 1.13 ms per loop (mean ± std. dev. of 5 runs, 20 loops each)\n" ] } ], @@ -747,7 +752,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -769,14 +774,14 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "41.8 ms ± 3.52 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" + "37.4 ms ± 578 μs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" ] } ], @@ -799,14 +804,14 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "10.2 ms ± 52.4 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n" + "10 ms ± 57.9 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n" ] } ], @@ -830,6 +835,15 @@ "\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In addition, sparse LU factorization results can be reused for different\n", + "right-hand sides, just like in the dense canse. This will be discussed in\n", + "the section for acceleration techniques." + ] + }, { "cell_type": "markdown", "metadata": {},