232
232
$$
233
233
234
234
There are plenty of different strategies you could use to do this, and no one strategy is better than the rest.
235
- One method is to subtract a multiple of the top row from subsequent rows below it such that all values beneath the pivot value are zero.
235
+ One method is to subtract a multiple of the top row from subsequent rows below it such that all values beneath the pivot value are zero.
236
236
This process might be easier if you swap some rows around first and can be performed for each pivot.
237
237
238
238
After you get a row echelon matrix, the next step is to find the reduced row echelon form. In other words, we do the following:
@@ -314,6 +314,9 @@ In code, this process might look like this:
314
314
{% sample lang="c" %}
315
315
[ import:5-13, lang:"c_cpp"] ( code/c/gaussian_elimination.c )
316
316
[ import:19-34, lang:"c_cpp"] ( code/c/gaussian_elimination.c )
317
+ {% sample lang="cpp" %}
318
+ [ import:22-29, lang:"c_cpp"] ( code/c++/gaussian_elimination.cpp )
319
+ [ import:37-51, lang:"c_cpp"] ( code/c++/gaussian_elimination.cpp )
317
320
{% sample lang="hs" %}
318
321
[ import:10-17, lang:"haskell"] ( code/haskell/gaussianElimination.hs )
319
322
[ import:44-46, lang:"haskell"] ( code/haskell/gaussianElimination.hs )
367
370
\left[
368
371
\begin{array}{ccc|c}
369
372
3 & -4 & 0 & 10 \\
370
- 0 & \mathbf{\frac{10}{3}} & \mathbf{3} & \mathbf{\frac{2}{3}}
373
+ 0 & \mathbf{\frac{10}{3}} & \mathbf{3} & \mathbf{\frac{2}{3}}
371
374
\\
372
375
2 & 3 & 4 & 6
373
376
\end{array}
@@ -384,6 +387,8 @@ Here is what it might look like in code:
384
387
[ import:32-40, lang:"java"] ( code/java/GaussianElimination.java )
385
388
{% sample lang="c" %}
386
389
[ import:36-41, lang:"c_cpp"] ( code/c/gaussian_elimination.c )
390
+ {% sample lang="cpp" %}
391
+ [ import:11-19, lang:"c_cpp"] ( code/c++/gaussian_elimination.cpp )
387
392
{% sample lang="hs" %}
388
393
[ import:19-33, lang:"haskell"] ( code/haskell/gaussianElimination.hs )
389
394
[ import:42-42, lang:"haskell"] ( code/haskell/gaussianElimination.hs )
@@ -403,6 +408,8 @@ When we put everything together, it looks like this:
403
408
[ import:1-45, lang:"julia"] ( code/julia/gaussian_elimination.jl )
404
409
{% sample lang="c" %}
405
410
[ import:15-48, lang:"c_cpp"] ( code/c/gaussian_elimination.c )
411
+ {% sample lang="cpp" %}
412
+ [ import:11-67, lang:"c_cpp"] ( code/c++/gaussian_elimination.cpp )
406
413
{% sample lang="rs" %}
407
414
[ import:41-78, lang:"rust"] ( code/rust/gaussian_elimination.rs )
408
415
{% sample lang="hs" %}
@@ -440,6 +447,8 @@ Here it is in code:
440
447
[ import:67-93, lang:"julia"] ( code/julia/gaussian_elimination.jl )
441
448
{% sample lang="c" %}
442
449
[ import:64-82, lang:"c_cpp"] ( code/c/gaussian_elimination.c )
450
+ {% sample lang="cpp" %}
451
+ [ import:70-83, lang:"c_cpp"] ( code/c++/gaussian_elimination.cpp )
443
452
{% sample lang="rs" %}
444
453
This code does not exist yet in rust, so here's Julia code (sorry for the inconvenience)
445
454
[ import:67-93, lang:"julia"] ( code/julia/gaussian_elimination.jl )
@@ -481,6 +490,8 @@ In code, it looks like this:
481
490
[ import:47-64, lang:"julia"] ( code/julia/gaussian_elimination.jl )
482
491
{% sample lang="c" %}
483
492
[ import:50-62, lang:"c_cpp"] ( code/c/gaussian_elimination.c )
493
+ {% sample lang="cpp" %}
494
+ [ import:86-99, lang:"c_cpp"] ( code/c++/gaussian_elimination.cpp )
484
495
{% sample lang="rs" %}
485
496
[ import:79-94, lang:"rust"] ( code/rust/gaussian_elimination.rs )
486
497
{% sample lang="hs" %}
@@ -495,7 +506,7 @@ In code, it looks like this:
495
506
496
507
## Visual Representation
497
508
498
- We have thus far used Gaussian elimination as a method to solve a system of equations; however, there is often a much easier way to find a similar solution simply by plotting each row in our matrix.
509
+ We have thus far used Gaussian elimination as a method to solve a system of equations; however, there is often a much easier way to find a similar solution simply by plotting each row in our matrix.
499
510
For the case of 2 equations and 2 unknowns, we would plot the two lines corresponding to each equation and the $$ (x, y) $$ location of their point of intersection would be the solution for $$ x $$ and $$ y $$ .
500
511
Similarly, for the case of 3 equations and 3 unknowns, we would plot 3 planes and the $$ (x, y, z) $$ location of their point of intersection would be the solution for $$ x $$ , $$ y $$ , and $$ z $$ .
501
512
@@ -536,6 +547,8 @@ There are also plenty of other solvers that do similar things that we will get t
536
547
[ import, lang:"julia"] ( code/julia/gaussian_elimination.jl )
537
548
{% sample lang="c" %}
538
549
[ import, lang:"c_cpp"] ( code/c/gaussian_elimination.c )
550
+ {% sample lang="cpp" %}
551
+ [ import, lang:"c_cpp"] ( code/c++/gaussian_elimination.cpp )
539
552
{% sample lang="rs" %}
540
553
[ import, lang:"rust"] ( code/rust/gaussian_elimination.rs )
541
554
{% sample lang="hs" %}
0 commit comments