232232$$
233233
234234There 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.
236236This process might be easier if you swap some rows around first and can be performed for each pivot.
237237
238238After 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:
314314{% sample lang="c" %}
315315[ import:5-13, lang:"c_cpp"] ( code/c/gaussian_elimination.c )
316316[ 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 )
317320{% sample lang="hs" %}
318321[ import:10-17, lang:"haskell"] ( code/haskell/gaussianElimination.hs )
319322[ import:44-46, lang:"haskell"] ( code/haskell/gaussianElimination.hs )
367370\left[
368371\begin{array}{ccc|c}
3693723 & -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}}
371374\\
3723752 & 3 & 4 & 6
373376\end{array}
@@ -384,6 +387,8 @@ Here is what it might look like in code:
384387[ import:32-40, lang:"java"] ( code/java/GaussianElimination.java )
385388{% sample lang="c" %}
386389[ 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 )
387392{% sample lang="hs" %}
388393[ import:19-33, lang:"haskell"] ( code/haskell/gaussianElimination.hs )
389394[ import:42-42, lang:"haskell"] ( code/haskell/gaussianElimination.hs )
@@ -403,6 +408,8 @@ When we put everything together, it looks like this:
403408[ import:1-45, lang:"julia"] ( code/julia/gaussian_elimination.jl )
404409{% sample lang="c" %}
405410[ 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 )
406413{% sample lang="rs" %}
407414[ import:41-78, lang:"rust"] ( code/rust/gaussian_elimination.rs )
408415{% sample lang="hs" %}
@@ -440,6 +447,8 @@ Here it is in code:
440447[ import:67-93, lang:"julia"] ( code/julia/gaussian_elimination.jl )
441448{% sample lang="c" %}
442449[ 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 )
443452{% sample lang="rs" %}
444453This code does not exist yet in rust, so here's Julia code (sorry for the inconvenience)
445454[ import:67-93, lang:"julia"] ( code/julia/gaussian_elimination.jl )
@@ -481,6 +490,8 @@ In code, it looks like this:
481490[ import:47-64, lang:"julia"] ( code/julia/gaussian_elimination.jl )
482491{% sample lang="c" %}
483492[ 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 )
484495{% sample lang="rs" %}
485496[ import:79-94, lang:"rust"] ( code/rust/gaussian_elimination.rs )
486497{% sample lang="hs" %}
@@ -495,7 +506,7 @@ In code, it looks like this:
495506
496507## Visual Representation
497508
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.
499510For 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 $$ .
500511Similarly, 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 $$ .
501512
@@ -536,6 +547,8 @@ There are also plenty of other solvers that do similar things that we will get t
536547[ import, lang:"julia"] ( code/julia/gaussian_elimination.jl )
537548{% sample lang="c" %}
538549[ import, lang:"c_cpp"] ( code/c/gaussian_elimination.c )
550+ {% sample lang="cpp" %}
551+ [ import, lang:"c_cpp"] ( code/c++/gaussian_elimination.cpp )
539552{% sample lang="rs" %}
540553[ import, lang:"rust"] ( code/rust/gaussian_elimination.rs )
541554{% sample lang="hs" %}
0 commit comments