|
9 | 9 | },
|
10 | 10 | {
|
11 | 11 | "cell_type": "code",
|
12 |
| - "execution_count": null, |
| 12 | + "execution_count": 7, |
13 | 13 | "metadata": {},
|
14 | 14 | "outputs": [],
|
15 | 15 | "source": [
|
16 | 16 | "import numpy as np\n",
|
17 | 17 | "import matplotlib.pyplot as plt\n",
|
| 18 | + "from ipywidgets import widgets\n", |
18 | 19 | "from ipywidgets.widgets import interact, interactive\n",
|
19 | 20 | "\n",
|
20 | 21 | "%matplotlib inline\n",
|
|
30 | 31 | },
|
31 | 32 | {
|
32 | 33 | "cell_type": "code",
|
33 |
| - "execution_count": null, |
| 34 | + "execution_count": 2, |
34 | 35 | "metadata": {},
|
35 | 36 | "outputs": [],
|
36 | 37 | "source": [
|
|
61 | 62 | },
|
62 | 63 | {
|
63 | 64 | "cell_type": "code",
|
64 |
| - "execution_count": null, |
| 65 | + "execution_count": 3, |
65 | 66 | "metadata": {},
|
66 |
| - "outputs": [], |
| 67 | + "outputs": [ |
| 68 | + { |
| 69 | + "data": { |
| 70 | + "application/vnd.jupyter.widget-view+json": { |
| 71 | + "model_id": "39110dcd05c146da84f09e1e72557dc1", |
| 72 | + "version_major": 2, |
| 73 | + "version_minor": 0 |
| 74 | + }, |
| 75 | + "text/plain": [ |
| 76 | + "interactive(children=(IntSlider(value=0, description='x', max=10, min=-10), IntSlider(value=0, description='y'…" |
| 77 | + ] |
| 78 | + }, |
| 79 | + "metadata": {}, |
| 80 | + "output_type": "display_data" |
| 81 | + }, |
| 82 | + { |
| 83 | + "data": { |
| 84 | + "text/plain": [ |
| 85 | + "<function __main__.plot_vector(x, y)>" |
| 86 | + ] |
| 87 | + }, |
| 88 | + "execution_count": 3, |
| 89 | + "metadata": {}, |
| 90 | + "output_type": "execute_result" |
| 91 | + } |
| 92 | + ], |
67 | 93 | "source": [
|
68 | 94 | "def plot_vector(x, y):\n",
|
69 | 95 | "\n",
|
|
91 | 117 | },
|
92 | 118 | {
|
93 | 119 | "cell_type": "code",
|
94 |
| - "execution_count": null, |
| 120 | + "execution_count": 4, |
95 | 121 | "metadata": {},
|
96 | 122 | "outputs": [],
|
97 | 123 | "source": [
|
|
112 | 138 | },
|
113 | 139 | {
|
114 | 140 | "cell_type": "code",
|
115 |
| - "execution_count": null, |
116 |
| - "metadata": {}, |
117 |
| - "outputs": [], |
118 |
| - "source": [] |
119 |
| - }, |
120 |
| - { |
121 |
| - "cell_type": "code", |
122 |
| - "execution_count": 3, |
| 141 | + "execution_count": 8, |
123 | 142 | "metadata": {},
|
124 |
| - "outputs": [], |
| 143 | + "outputs": [ |
| 144 | + { |
| 145 | + "data": { |
| 146 | + "application/vnd.jupyter.widget-view+json": { |
| 147 | + "model_id": "175112b533e3462e956b0409b0cc3002", |
| 148 | + "version_major": 2, |
| 149 | + "version_minor": 0 |
| 150 | + }, |
| 151 | + "text/plain": [ |
| 152 | + "interactive(children=(IntSlider(value=1, description='a', max=5, min=-5), IntSlider(value=0, description='b', …" |
| 153 | + ] |
| 154 | + }, |
| 155 | + "metadata": {}, |
| 156 | + "output_type": "display_data" |
| 157 | + }, |
| 158 | + { |
| 159 | + "data": { |
| 160 | + "text/plain": [ |
| 161 | + "<function __main__.matrix_transform(a=1, b=0, c=0, d=1)>" |
| 162 | + ] |
| 163 | + }, |
| 164 | + "execution_count": 8, |
| 165 | + "metadata": {}, |
| 166 | + "output_type": "execute_result" |
| 167 | + } |
| 168 | + ], |
125 | 169 | "source": [
|
126 | 170 | "def matrix_transform(a=1, b=0, c=0, d=1):\n",
|
127 | 171 | " matrix = np.array([[a, b], [c, d]])\n",
|
|
152 | 196 | " d=widgets.IntSlider(min=-5, max=5, value=1, description=\"d\"))\n"
|
153 | 197 | ]
|
154 | 198 | },
|
| 199 | + { |
| 200 | + "cell_type": "markdown", |
| 201 | + "metadata": {}, |
| 202 | + "source": [ |
| 203 | + "### Solve linear euqation by matrix inversion" |
| 204 | + ] |
| 205 | + }, |
| 206 | + { |
| 207 | + "cell_type": "code", |
| 208 | + "execution_count": 9, |
| 209 | + "metadata": {}, |
| 210 | + "outputs": [ |
| 211 | + { |
| 212 | + "name": "stdout", |
| 213 | + "output_type": "stream", |
| 214 | + "text": [ |
| 215 | + "Solution using matrix inversion:\n", |
| 216 | + "x = [2.42857143 0.71428571]\n" |
| 217 | + ] |
| 218 | + } |
| 219 | + ], |
| 220 | + "source": [ |
| 221 | + "# Define the coefficients matrix A and the right-hand side vector b\n", |
| 222 | + "A = np.array([[2, 3],\n", |
| 223 | + " [1, -2]])\n", |
| 224 | + "\n", |
| 225 | + "b = np.array([7, 1])\n", |
| 226 | + "\n", |
| 227 | + "# Calculate the inverse of matrix A\n", |
| 228 | + "A_inv = np.linalg.inv(A)\n", |
| 229 | + "\n", |
| 230 | + "# Solve for the unknown vector x using matrix inversion: x = A_inv * b\n", |
| 231 | + "x = np.dot(A_inv, b)\n", |
| 232 | + "\n", |
| 233 | + "print(\"Solution using matrix inversion:\")\n", |
| 234 | + "print(\"x =\", x)" |
| 235 | + ] |
| 236 | + }, |
| 237 | + { |
| 238 | + "cell_type": "markdown", |
| 239 | + "metadata": {}, |
| 240 | + "source": [ |
| 241 | + "### Compute eigenvalues and eigenvectors" |
| 242 | + ] |
| 243 | + }, |
| 244 | + { |
| 245 | + "cell_type": "code", |
| 246 | + "execution_count": 21, |
| 247 | + "metadata": {}, |
| 248 | + "outputs": [ |
| 249 | + { |
| 250 | + "name": "stdout", |
| 251 | + "output_type": "stream", |
| 252 | + "text": [ |
| 253 | + "eigvals:\n", |
| 254 | + "[-0.5+0.8660254j -0.5-0.8660254j]\n", |
| 255 | + "eigvecs:\n", |
| 256 | + "[[0.8660254+0.j 0.8660254-0.j ]\n", |
| 257 | + " [0.4330127-0.25j 0.4330127+0.25j]]\n" |
| 258 | + ] |
| 259 | + } |
| 260 | + ], |
| 261 | + "source": [ |
| 262 | + "# Define the coefficients matrix A and the right-hand side vector b\n", |
| 263 | + "# vary coeficients\n", |
| 264 | + "A = np.array([[1, -3],\n", |
| 265 | + " [1, -2]])\n", |
| 266 | + "\n", |
| 267 | + "# Calculate the eigenvalues and eigenvectors of A\n", |
| 268 | + "eigenvalues, eigenvectors = np.linalg.eig(A)\n", |
| 269 | + "print('eigvals:')\n", |
| 270 | + "print(eigenvalues)\n", |
| 271 | + "print('eigvecs:')\n", |
| 272 | + "print(eigenvectors)" |
| 273 | + ] |
| 274 | + }, |
155 | 275 | {
|
156 | 276 | "cell_type": "code",
|
157 | 277 | "execution_count": null,
|
|
0 commit comments