|
22 | 22 | "source":[ |
23 | 23 | "# let's start by importing the required libraries\n", |
24 | 24 | "\n", |
25 | | - "import numpy as np\n", |
26 | | - "import copy" |
| 25 | + "import numpy as np" |
27 | 26 | ], |
28 | | - "execution_count":11, |
| 27 | + "execution_count":3, |
29 | 28 | "outputs":[ |
30 | 29 |
|
31 | 30 | ], |
|
58 | 57 | "print(f\"Equation Matrix: \\n {eq_arr} \\n\")\n", |
59 | 58 | "print(f\"Result Matrix: \\n {res_arr} \\n\")" |
60 | 59 | ], |
61 | | - "execution_count":3, |
| 60 | + "execution_count":4, |
62 | 61 | "outputs":[ |
63 | 62 | { |
64 | 63 | "name":"stdout", |
|
168 | 167 | "\n", |
169 | 168 | "print(f\"Determinant of the linear equation is: {det_arr:0.2f}\")" |
170 | 169 | ], |
171 | | - "execution_count":8, |
| 170 | + "execution_count":7, |
172 | 171 | "outputs":[ |
173 | 172 | { |
174 | 173 | "name":"stdout", |
|
196 | 195 | "\n", |
197 | 196 | "print(f\"Restacked array is: {stck_eq_arr}\")\n" |
198 | 197 | ], |
199 | | - "execution_count":10, |
| 198 | + "execution_count":8, |
200 | 199 | "outputs":[ |
201 | 200 | { |
202 | 201 | "name":"stdout", |
|
229 | 228 | " cp_orig_arr[row_index] = orig_arr[row_index] * multiple_scalar\n", |
230 | 229 | " return cp_orig_arr" |
231 | 230 | ], |
232 | | - "execution_count":27, |
| 231 | + "execution_count":9, |
233 | 232 | "outputs":[ |
234 | 233 |
|
235 | 234 | ], |
|
251 | 250 | "mod_eq_arr = multiply_row(stck_eq_arr, 1, 2)\n", |
252 | 251 | "print(f\"Modified array after change is: \\n {mod_eq_arr} \\n\")" |
253 | 252 | ], |
254 | | - "execution_count":28, |
| 253 | + "execution_count":10, |
255 | 254 | "outputs":[ |
256 | 255 | { |
257 | 256 | "name":"stdout", |
|
289 | 288 | " cp_orig_arr[row_index_2] = multiple_scalar * orig_arr[row_index_1] + orig_arr[row_index_2]\n", |
290 | 289 | " return cp_orig_arr" |
291 | 290 | ], |
292 | | - "execution_count":29, |
| 291 | + "execution_count":11, |
293 | 292 | "outputs":[ |
294 | 293 |
|
295 | 294 | ], |
|
311 | 310 | "mod_eq_arr = add_rows(stck_eq_arr, 2, 1, 2)\n", |
312 | 311 | "print(f\"Modified array after change is: \\n {mod_eq_arr} \\n\")" |
313 | 312 | ], |
314 | | - "execution_count":30, |
| 313 | + "execution_count":12, |
315 | 314 | "outputs":[ |
316 | 315 | { |
317 | 316 | "name":"stdout", |
|
349 | 348 | " cp_orig_arr[[row_index_1,row_index_2]] = cp_orig_arr[[row_index_2,row_index_1]]\n", |
350 | 349 | " return cp_orig_arr" |
351 | 350 | ], |
352 | | - "execution_count":31, |
| 351 | + "execution_count":13, |
353 | 352 | "outputs":[ |
354 | 353 |
|
355 | 354 | ], |
|
371 | 370 | "mod_eq_arr = swap_rows(stck_eq_arr, 2, 1)\n", |
372 | 371 | "print(f\"Modified array after change is: \\n {mod_eq_arr} \\n\")" |
373 | 372 | ], |
374 | | - "execution_count":32, |
| 373 | + "execution_count":14, |
375 | 374 | "outputs":[ |
376 | 375 | { |
377 | 376 | "name":"stdout", |
|
399 | 398 | } |
400 | 399 | } |
401 | 400 | }, |
| 401 | + { |
| 402 | + "cell_type":"code", |
| 403 | + "source":[ |
| 404 | + "# now to further perform reduced row echelon, let use above defined functions\n", |
| 405 | + "\n", |
| 406 | + "red_row_eq_arr = swap_rows(stck_eq_arr, 0, 2)\n", |
| 407 | + "\n", |
| 408 | + "red_row_eq_arr = add_rows(red_row_eq_arr,0,1,2)\n", |
| 409 | + "\n", |
| 410 | + "red_row_eq_arr = add_rows(red_row_eq_arr,0,2,4)\n", |
| 411 | + "\n", |
| 412 | + "red_row_eq_arr = add_rows(red_row_eq_arr,1,2,-1)\n", |
| 413 | + "\n", |
| 414 | + "red_row_eq_arr = multiply_row(red_row_eq_arr,2,-1\/12)\n", |
| 415 | + "\n", |
| 416 | + "print(f\"Modified reduced row equation is: \\n {red_row_eq_arr} \\n\")\n", |
| 417 | + "\n" |
| 418 | + ], |
| 419 | + "execution_count":15, |
| 420 | + "outputs":[ |
| 421 | + { |
| 422 | + "name":"stdout", |
| 423 | + "text":[ |
| 424 | + "Modified reduced row equation is: \n", |
| 425 | + " [[-1. 2. -5. 17.]\n", |
| 426 | + " [ 0. 5. -7. 34.]\n", |
| 427 | + " [-0. -0. 1. -2.]] \n", |
| 428 | + "\n" |
| 429 | + ], |
| 430 | + "output_type":"stream" |
| 431 | + } |
| 432 | + ], |
| 433 | + "metadata":{ |
| 434 | + "datalore":{ |
| 435 | + "node_id":"6pj2ZoXJretXm179iDVcUX", |
| 436 | + "type":"CODE", |
| 437 | + "hide_input_from_viewers":true, |
| 438 | + "hide_output_from_viewers":true |
| 439 | + } |
| 440 | + } |
| 441 | + }, |
| 442 | + { |
| 443 | + "cell_type":"code", |
| 444 | + "source":[ |
| 445 | + "# now let's try and find values of x1, x2, and x3\n", |
| 446 | + "\n", |
| 447 | + "x_3 = -2 # as per above equation derivation\n", |
| 448 | + "x_2 = (red_row_eq_arr[1,3] - red_row_eq_arr[1,2] * x_3) \/ red_row_eq_arr[1,1]\n", |
| 449 | + "x_1 = (red_row_eq_arr[0,3] - red_row_eq_arr[0,2] * x_3 - red_row_eq_arr[0,1] * x_2) \/ red_row_eq_arr[0,0]\n", |
| 450 | + "\n", |
| 451 | + "print(x_1, x_2, x_3)" |
| 452 | + ], |
| 453 | + "execution_count":17, |
| 454 | + "outputs":[ |
| 455 | + { |
| 456 | + "name":"stdout", |
| 457 | + "text":[ |
| 458 | + "1.0 4.0 -2\n" |
| 459 | + ], |
| 460 | + "output_type":"stream" |
| 461 | + } |
| 462 | + ], |
| 463 | + "metadata":{ |
| 464 | + "datalore":{ |
| 465 | + "node_id":"ZRLebFtwF9w2m4dpTAWEbS", |
| 466 | + "type":"CODE", |
| 467 | + "hide_input_from_viewers":true, |
| 468 | + "hide_output_from_viewers":true |
| 469 | + } |
| 470 | + } |
| 471 | + }, |
402 | 472 | { |
403 | 473 | "cell_type":"code", |
404 | 474 | "source":[ |
|
410 | 480 | ], |
411 | 481 | "metadata":{ |
412 | 482 | "datalore":{ |
413 | | - "node_id":"6pj2ZoXJretXm179iDVcUX", |
| 483 | + "node_id":"RgvqEXHh6ZdOBqiZNg3h73", |
414 | 484 | "type":"CODE", |
415 | 485 | "hide_input_from_viewers":true, |
416 | 486 | "hide_output_from_viewers":true |
|
0 commit comments