Skip to content

Commit

Permalink
Tweaks to the text.
Browse files Browse the repository at this point in the history
  • Loading branch information
cuihantao committed Oct 5, 2024
1 parent 428153b commit e4ed315
Showing 1 changed file with 44 additions and 30 deletions.
74 changes: 44 additions & 30 deletions pct/modules/04/linear-equations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -106,7 +106,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -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": [
{
Expand Down Expand Up @@ -195,7 +200,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -251,7 +256,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -290,7 +295,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -362,7 +367,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -394,7 +399,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -441,7 +446,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -511,7 +516,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -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"
]
}
Expand Down Expand Up @@ -593,7 +598,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -621,7 +626,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand All @@ -631,7 +636,7 @@
"\twith 154958 stored elements and shape (19928, 19928)>"
]
},
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -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"
]
}
],
Expand All @@ -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"
]
}
],
Expand Down Expand Up @@ -747,7 +752,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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"
]
}
],
Expand All @@ -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"
]
}
],
Expand All @@ -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": {},
Expand Down

0 comments on commit e4ed315

Please sign in to comment.