es
Gaussian Elimination

# Motivation

To understand the idea of Gaussian elimination algorithm, we consider a series of examples, starting with a two dimensional case.

Example 1: Consider the system of algebraic equations
\begin{align*} x -2\, y &= 1 , \\ 3\,x + 4\,y &= 13 . \end{align*}
If we multiply the first equation by -3 and add to the last one (which does not change a solution), we get
${\bf Before: } \quad \begin{split} x -2\, y &= 1 , \\ 3\,x + 4\,y &= 13 ; \end{split} \qquad {\bf After: } \quad \begin{split} x -2\, y &= 1 , \\ \qquad\qquad 10\,y &= 10 ; \end{split} \qquad \begin{split} \mbox{(multiply by 3 and subtract)} \\ (x\mbox{ has been eliminated)} \end{split}$
The first stage we accomplished is called forward elimination because it deleted one variable from consideration. Forward elimination produces an upper triangular system, which can be seen with matrix notation (which is called the augmented matrix)
${\bf Before: } \qquad \begin{bmatrix} \color{red}{1}&-2&1 \\ 3&\phantom{-}\color{red}{4}&13 \end{bmatrix} \qquad\quad {\bf After: } \qquad \begin{bmatrix} \color{red}{1}&-2&1 \\ 0&\color{red}{10}&10 \end{bmatrix} .$
The last equation 10y = 10 reveals y = 1, and we go up the triangle to x = 3. This quick process is called back substitution. It is used for upper triangular systems of any size, after forward elimination is complete. We plot our equations with Mathematica.
Plot[{(x - 1)/2, (13 - 3*x)/4}, {x, -0.5, 4}, PlotStyle -> Thick] Plot[{(x - 1)/2, 1}, {x, -0.5, 4}, PlotStyle -> Thick]

Instead of eliminating the variable x, we can go after y. If we multiply the first equation by 2 and add to the second equation, we get

${\bf Before: } \quad \begin{split} x -2\, y &= 1 , \\ 3\,x + 4\,y &= 13 ; \end{split} \qquad {\bf After: } \quad \begin{split} x -2\, y &= 1 , \\ 5\,x \qquad &= 15 ; \end{split} \qquad \begin{split} \mbox{(multiply by 2 and add)} \\ (y\mbox{ has been eliminated)} \end{split}$
or in matrix form:
${\bf Before: } \qquad \begin{bmatrix} 1&\color{red}{-2}&1 \\ \color{red}{3}&\phantom{-}4&13 \end{bmatrix} \qquad\quad {\bf After: } \qquad \begin{bmatrix} 1&\color{red}{-2}&1 \\ \color{red}{5}&\phantom{-}0&15 \end{bmatrix} .$
vline = Line[{{3, -0.5}, {3, 1.5}}];
Plot[{(x - 1)/2}, {x, -0.5, 4}, Epilog -> {Directive[Thick, Orange], vline}, PlotStyle -> Thick]
Which variable should you eliminate, x or y? For a computer, it does not matter, but for humans it does because it is more attractive. So mostly for educational purposes, we will follow tradition and we will eliminate variables from left to right in order to reduce the matrices into upper triangular form. However, remember that when you write codes for practical calculations, it does not matter which variable you eliminate and in what order---computer does not care!

When we used matrix form corresponding to the given system of equations, we marked with red color special positions in the corresponding augmented matrix because they important for understanding. These positions are usually referred to as pivots. ■

End of Example 1

Example 2: Now we consider slightly different system of algebraic equations
\begin{align*} x -2\, y &= 1 , \\ 3\,x - 6\,y &= 13 . \end{align*}
Eliminating variable x by subtracting 3 times first equation from the second one, we obtain < div class="math"> \begin{align*} x -2\, y &= 1 , \\ 0\,x - 0\,y &= \color{red}{10} . \end{align*}
There is no solution. Remember that zero is never allowed as a pivot, hence we get an equation with a pivot at the last column.
${\bf Before: } \qquad \begin{bmatrix} \color{red}{1}&-2&1 \\ 3&-6&\color{red}{13} \end{bmatrix} \qquad\quad {\bf After: } \qquad \begin{bmatrix} \color{red}{1}&-2&1 \\ 0&\phantom{-}0&\color{red}{10} \end{bmatrix} .$

 Parallel lines Plot[{(x - 1)/2, (3*x-13)/6}, {x, -0.5, 4}, PlotStyle -> Thick]

End of Example 2

Example 3: We transfer the system of algebraic equations to matrix form using its augmented matrix
$\begin{split} x -2\, y &= 1 , \\ 3\,x - 6\,y &= 3 . \end{split} \qquad \Longrightarrow \qquad \begin{bmatrix} \color{red}{1}&-2&1 \\ 3&-6&3 \end{bmatrix} .$
The result of subtracting 3 times first equation from the last one reveals the 2×2 matrix with only one pivot:
$\begin{bmatrix} \color{red}{1}&-2&1 \\ 0&\phantom{-}0&0 \end{bmatrix} .$
The last line in the matrix shows that every x and y satisfy the equation 0·x + 0·y = 0. There is really only one equation x - 2y = 1. One of the variables is free when another one is expressed through the free one:
$x = 1 + 2\,y \qquad \mbox{or} \qquad y = \left( x-1 \right) /2 ,$
when y or x is freely chosen, respectively. There is no need to plot one straight line that includes both equations because every its point satisfies both equations. We have a whole line of solutions. ■
End of Example 3

Example 4: Consider the system of algebraic equations
\begin{align*} 0\,x -2\, y &= -2 , \\ 3\,x + 4\,y &= 13 . \end{align*}
For this system, we cannot choose the first coefficient as a pivot because by definition pivot cannot be a zero. So exchange two equations to obtain an equivalent augmented matrix:
$\begin{bmatrix} 0&-2&-2 \\ 3&\phantom{-}4&13 \end{bmatrix} \ \sim \ \begin{bmatrix} \color{red}{3}&\phantom{-}4&13 \\ 0&\color{red}{-2}&-2 \end{bmatrix} .$

 Two lines intersect at a point (3,1) Plot[{(x - 1)/2, 1}, {x, -0.5, 4}, PlotStyle -> Thick] The new system is already triangular, so one of the lines is parallel to an axis.

End of Example 4

To understand Gaussian elimination, you have to go beyond 2×2 systems of equations. Therefore, we present examples of 3×3 systems of equations that will be enough to see the pattern. Other example with rectangular matrices to follow.

Example 5: Consider the system of algebraic equations
\begin{align*} x -3\, y +z &= 6 , \\ -6\,x + 3\,y - 15\,z&= 3 , \\ 2\,x - 8\,y + 8\,z&= 10 . \end{align*}
We convert the given system of equations into an augmented matrix:
$\left[ \begin{array}{ccc|c} \phantom{-}1&-3&1&6 \\ -6&\phantom{-}3&-15&3 \\ \phantom{-}2&-8&\phantom{-}8&10 \end{array} \right] .$
This matrix contains all of the information in the system of equations without the unknown variables x, y, and z to carry around. Now we perform the process of elimination. The notation to the right of each matrix describes the row operations that were performed to get the matrix on that line. For example 2R1+R2 ↦ R2 means "replace row 2 with the sum of 2 times row 1 and row 2."
$\left[ \begin{array}{ccc|c} \color{red}{1}&-3&\phantom{-}1&6 \\ 0&\color{red}{-15}&-9&39 \\ 0&-2& \phantom{-}6&-2 \end{array} \right] \qquad \begin{array}{c} \\ 6\,R_1 + R_2 \mapsto R_2 \\ -2\,R_1 + R_3 \mapsto R_3 \end{array}$
$\left[ \begin{array}{ccc|c} \color{red}{1}&-3&\phantom{-}1&6 \\ 0&\color{red}{-15}&-9&39 \\ 0&-2&\phantom{-}6&-2 \end{array} \right] \,\sim \, \left[ \begin{array}{ccc|c} \color{red}{1}&-3&\phantom{-}1&6 \\ 0&\color{red}{-5}&-3&13 \\ 0&\phantom{-}1&\color{red}{-3}&1 \end{array} \right] \qquad \begin{array}{c} \\ \frac{1}{3}\,R_2 \mapsto R_2 \\ -\frac{1}{2}\,R_3 \mapsto R_3 \end{array} .$
$\left[ \begin{array}{ccc|c} \color{red}{1}&-3&\phantom{-}1&6 \\ 0&\color{red}{-5}&-3&13 \\ 0&\phantom{-}1&\color{red}{-3}&1 \end{array} \right] \,\sim \, \left[ \begin{array}{ccc|c} \color{red}{1}&-3&\phantom{-}1&6 \\ 0&\color{red}{-5}&-3&13 \\ 0&\phantom{-}0&\color{red}{-\frac{18}{5}}&\frac{18}{5} \end{array} \right] \qquad \begin{array}{c} \\ \\ \frac{1}{5}\,R_2 + R_3 \mapsto R_3 \end{array}$
If we now reverse the conversion process and turn the augmented matrix into a system of equations we have
\begin{align*} x -3\, y +z &= 6 , \\ 0\,x - 5\,y - 3\,z&= 2 , \\ 0\,x + 0\,y - \frac{18}{5}\,z&= \frac{18}{5} . \end{align*}
We can now easily solve for x, y, and z by back-substitution to obtain x = 1, y = -2, and z = -1. For a system of equations with a 3x3 matrix of coefficients, the goal of the process of Gaussian Elimination is to create (at least) a triangle of zeroes in the lower left hand corner of the matrix below the diagonal. Note that you may switch the order of the rows at any time in trying to get to this form.
a1 = ContourPlot3D[x - 3 y + z == 6, {x, -10, 10}, {y, -10, 10}, {z, -10, 10}, AxesLabel -> {x, y, z}, Mesh -> None, ContourStyle -> Directive[Red]];

f2[x_, y_] := (-2* x + y-1)/5;
a2 = ParametricPlot3D[{x, y, f2[x, y]}, {x, -10, 10}, {y, -10, 10}, AxesLabel -> {x, y, z}, Mesh -> None, PlotStyle -> Directive[Green]];

f3[x_, y_] := (5- x + 4*y)/4;
a3 = Graphics3D[{LightBlue, Polygon[Flatten[#, 1] &@{#[[1]], #[[2]],f3[#[[1]], #[[2]]]} & /@ {{-10, -10}, {-10, 10}, {10, 10}, {10, -10}}]}];
Show[a1, a2, a3]
Finally we plot planes in the echelon form:
ff2[x_, y_] := -(5*y + 2)/5;
b2 = ParametricPlot3D[{x, y, ff2[x, y]}, {x, -10, 10}, {y, -10, 10}, AxesLabel -> {x, y, z}, Mesh -> None, PlotStyle -> Directive[Green]];
ff3[x_, y_] := -1;
b3 = Graphics3D[{LightBlue, Polygon[Flatten[#, 1] &@{#[[1]], #[[2]], ff3[#[[1]], #[[2]]]} & /@ {{-10, -10}, {-10, 10}, {10, 10}, {10, -10}}]}];
Show[a1, b2, b3]
End of Example 5

Example 6: Consider the system of algebraic equations
\begin{align*} x -2\, y-6\,z &= 1 , \\ x -4\,y -12\,z &= 2, \\ 2\,x +4\,y + 12\,z &= 3 . \end{align*}
First, we plot planes corresponding the given system of equations:
a1 = ContourPlot3D[x - 2 y -6 z == 1, {x, -10, 10}, {y, -10, 10}, {z, -10, 10}, AxesLabel -> {x, y, z}, Mesh -> None, ContourStyle -> Directive[Orange]];

f2[x_, y_] := (x -4 y-2)/12;
a2 = ParametricPlot3D[{x, y, f2[x, y]}, {x, -10, 10}, {y, -10, 10}, AxesLabel -> {x, y, z}, Mesh -> None, PlotStyle -> Directive[Green]];

f3[x_, y_] := (3- 2*x - 4*y)/12;
a3 = Graphics3D[{LightBlue, Polygon[Flatten[#, 1] &@{#[[1]], #[[2]],f3[#[[1]], #[[2]]]} & /@ {{-10, -10}, {-10, 10}, {10, 10}, {10, -10}}]}];
Show[a1, a2, a3]
We keep x in the first equation and eliminate it from the other equations. To do so, add -1 times equation 1 to equation 2. After some practice, this type of calculation is usually performed mentally. However, it is convenient to use software:
$\begin{array}{c} -1 \cdot [\mbox{equation }1] \\ + [\mbox{equation }2] \\ \hline [\mbox{new equation }2] \end{array} \qquad \begin{array}{ccccc} -x&+2\,y& +6\,z& =&-1 \\ x&-4\,y& -12\,z& =&2 \\ \hline &-2\,y& -6\,z & =& 1 \end{array}$
To subtract row 1 from row 2, enter in Mathematica:
A = {{1, -2, -6, 1}, {1, -4, -12, 2}, {2, 4, 12, 3}}
m2 = A;
m2[[2]] -= m2[[1]]
To subtract row 1 times 2 from row 3 enter:
m3 = m2;
m3[[3]] = m3[[3]] - 2*m3[[1]]
$\begin{array}{c} -2 \cdot [\mbox{equation }1] \\ + [\mbox{equation }3] \\ \hline [\mbox{new equation }3] \end{array} \qquad \begin{array}{ccccc} -2\,x&+4\,y& +12\,z& =&-2 \\ 2\,x&+4\,y& +12\,z& =&3 \\ \hline &8\,y& +24\,z & =& 1 \end{array}$
$\begin{split} x-2\,y -6\,z &=1 , \\ -2\,y -6\,z &= 1 , \\ 8\,y +24\,z &= 1 ; \end{split} \qquad \Longleftrightarrow \qquad \left[ \begin{array}{ccc|c} \color{red}{1}&-2&-6&1 \\ 0&\color{red}{-2}&-6&1 \\ 0&\phantom{-}8&24&1 \end{array} \right] .$
Now, multiply equation 2 by 4 and add to the last one. This yields
$\begin{split} x-2\,y -6\,z &=1 , \\ -2\,y -6\,z &= 1 , \\ 0\,y +0\,z &= 5 ; \end{split} \qquad \Longleftrightarrow \qquad \left[ \begin{array}{ccc|c} \color{red}{1}&-2&-6&1 \\ 0&\color{red}{-2}&-6&1 \\ 0&\phantom{-}0&0&\color{red}{5} \end{array} \right] .$
Notice the last equation reads: 0=5. This is not possible. So the system has no solutions; it is not possible to find values x, y, and z that satisfy all three equations simultaneously.
End of Example 6

Example 7: Consider the system of algebraic equations
\begin{align*} x -2\, y-6\,z &= 1 , \\ x -4\,y -12\,z &= 2, \\ 2\,x +4\,y + 12\,z &= -2 . \end{align*}
First, we plot planes corresponding the given system of equations:
a1 = ContourPlot3D[x - 2 y -6 z == 1, {x, -10, 10}, {y, -10, 10}, {z, -10, 10}, AxesLabel -> {x, y, z}, Mesh -> None, ContourStyle -> Directive[Orange]];

f2[x_, y_] := (x -4 y-2)/12;
a2 = ParametricPlot3D[{x, y, f2[x, y]}, {x, -10, 10}, {y, -10, 10}, AxesLabel -> {x, y, z}, Mesh -> None, PlotStyle -> Directive[Green]];

f3[x_, y_] := (-2- 2*x - 4*y)/12;
a3 = Graphics3D[{LightBlue, Polygon[Flatten[#, 1] &@{#[[1]], #[[2]],f3[#[[1]], #[[2]]]} & /@ {{-10, -10}, {-10, 10}, {10, 10}, {10, -10}}]}];
Show[a1, a2, a3]
In augmented matrix form we have
$\left[ \begin{array}{ccc|c} \color{red}{1}&-2&-6&\phantom{-}1 \\ 1&-4&-12&\phantom{-}2 \\ 2&\phantom{-}4&12&-2 \end{array} \right] .$
We now use the method of Gaussian Elimination and annihilate variable x from two last equations:
$\left[ \begin{array}{ccc|c} \color{red}{1}&-2&-6&\phantom{-}1 \\ 0&\color{red}{-2}&-6&\phantom{-}1 \\ 0&\phantom{-}8&24&-4 \end{array} \right] \qquad \begin{array}{c} \\ -1\,R_1 + R_2 \mapsto R_2 \\ -2\,R_1 + R_3 \mapsto R_3 \end{array} .$
Next we divide every term in the last equation by 4 to obtain
$\left[ \begin{array}{ccc|c} \color{red}{1}&-2&-6&\phantom{-}1 \\ 0&\color{red}{-2}& -6&\phantom{-}1 \\ 0&\phantom{-}2&6&-1 \end{array} \right] \qquad \begin{array}{c} \\ \\ \frac{1}{4}\, R_3 \mapsto R_3 \end{array} .$
Finally we add the second row and the third row. This leads to its reduced echelon form with only two pivots:
$\left[ \begin{array}{ccc|c} \color{red}{1}&-2&-6&1 \\ 0&\color{red}{-2}&-6&1 \\ 0&\phantom{-}0&\phantom{-}0&0 \end{array} \right]$
Converting back to a system of equations, we have
\begin{align*} x -2\, y-6\,z &= 1 , \\ 0\,x -2\,y -6\,z &= 1, \\ 0\,x +0\,y + 0\,z &= 0 . \end{align*}
Notice the last equation: 0=0 (this resulted from equation 3 being a linear combination of the other two equations). This is always true. And, we can solve the first two equations to get x and y as functions of z alone. Solving these equations, we get
Solve[{x - 2*y - 6*z == 1, -2*x - 6*z == 1}, {x, y}]
{{x -> 1/2 (-1 - 6 z), y -> -(3/4) (1 + 6 z)}}
So
$x= - \frac{1}{2} \left( 1+ 6\,x \right) , \qquad y = - \frac{3}{4} \left( 1+ 6\,x \right) ,$
where z is a free variable.
End of Example 7

Example 8: Consider the system of algebraic equations
\begin{align*} x_1 -2\, x_2 + x_3 + x_4 &= -6 , \\ x_1 -4\,x_2 - x_3 + 3\,x_4 &= -12, \\ 2\,x_1 -3\,x_2 +2\,x_3 + x_4 &= -8 , \\ -3\,x_1 +2\,x_2 + x_3 + 2\,x_4 &= -4 . \end{align*}
The augmented matrix for this system becomes
$\left[ \begin{array}{cccc|c} \phantom{-}1&-2&\phantom{-}1&1&-6 \\ \phantom{-}1&-4&-1&3&-12 \\ \phantom{-}2&-3&\phantom{-}2&1&-8 \\ -3&\phantom{-}2& \phantom{-}1&2&-4 \end{array} \right] .$
To eliminate x1 from the last three equations, we multiply the first equation by -1, -2, and 3, respectively. By adding the results to the corresponding rows, it will introduce zeroes into positions below the pivot (which we mark with red) in the first column:
$\left[ \begin{array}{cccc|c} \phantom{-}1&-2& \phantom{-}1&1&-6 \\ \phantom{-}1&-4&-1&3&-12 \\ \phantom{-}2&-3& \phantom{-}2&1&-8 \\ -3& \phantom{-}2& \phantom{-}1&2&-4 \end{array} \right] \,\sim \, \left[ \begin{array}{cccc|c} \color{red}{1}&-2&\phantom{-}1&\phantom{-}1&-6 \\ 0&-2&-2&\phantom{-}2&-6 \\ 0&\phantom{-}1& \phantom{-}0&-1& \phantom{-}4 \\ 0&-4&\phantom{-}4& \phantom{-}5&-22 \end{array} \right] \qquad \begin{array}{c} \\ -1\,R_1 + R_2 \mapsto R_2 \\ -2\,R_1 + R_3 \mapsto R_3 \\ 3\,R_1 + R_4 \mapsto R_4 \end{array} .$
It is convenient to divide the second row by 2:
$\left[ \begin{array}{cccc|c} \color{red}{1}&-2&\phantom{-}1&\phantom{-}1&-6 \\ 0&-1&-1&\phantom{-}1&-3 \\ 0&\phantom{-}1&\phantom{-}0&-1&\phantom{-}4 \\ 0&-4&\phantom{-}4&\phantom{-}5&-22 \end{array} \right] \,\sim \left[ \begin{array}{cccc|c} \color{red}{1}&-2&\phantom{-}1& 1&-6 \\ 0&\color{red}{-1}&-1&1&-3 \\ 0&\phantom{-}0&-1&0&\phantom{-}1 \\ 0&\phantom{-}0&\phantom{-}8&1&-10 \end{array} \right] \qquad \begin{array}{c} \\ \\ R_2 + R_3 \mapsto R_3 \\ -4\,R_2 + R_4 \mapsto R_4 \end{array} .$
Finally, multiplying the third row by 8 and adding to the last row, we obtain, what is usually called the row echelon form for the given augmented matrix:
$\left[ \begin{array}{cccc|c} \color{red}{1}&-2&\phantom{-}1&1&-6 \\ 0&\color{red}{-1}&-1&1&-3 \\ 0&\phantom{-}0&\color{red}{-1}&0&\phantom{-}1 \\ 0&\phantom{-}0&\phantom{-}0&\color{red}{1}&-2 \end{array} \right]$
that has pivots in every row. Return this to the familiar linear system:
\begin{align*} x_1 -2\, x_2 + x_3 + x_4 &= -6 , \\ -x_2 - x_3 + x_4 &= -3, \\ -x_3 &= 1 , \\ x_4 &= -2 . \end{align*}
Solving by back substitution, we obtain
$x_1 =1, \quad x_2 =2 , \quad x_3 =-1, \quad x_4 = -2 .$
End of Example 8
Example 9: This example illustrates how we can use linear systems to determine how many molecules of various chemical compounds are required as input to a chemical reaction, as well as how many molecules of different compounds are produced as output.

When ethane (C₂H₆) burns in the presence of oxygen gas (O₂), it produces carbon dioxide (CO₂) and water vapor (H₂O). We thus say that the “unbalanced” equation for burning ethane is $C_2 H_6 + O_2 \, \to \, C\,O_2 + H_2 O .$ Since we don't know how many copies of each molecule are involved in the reaction, we multiply each molecule by unknown (integer) coefficient and make a chemical equation $x\,C_2 H_6 + y\,O_2 \, = \, z\,C\,O_2 + w\,H_2 O ,$ where integers x, y, z, and w represent how many copies of each molecule are present in the reaction. Hence, each side of the equation above has the same amount of each element on the left- and right-hand sides.

On the left-hand side of this chemical equation, we have 2y atoms of oxygen (O) and on the right-hand side we have 2z + w atoms of oxygen, so we require $2\,y = 2\, z + w \qquad \iff \qquad 2\,y - 2\, z - w =0 .$ Similarly matching up the number of atoms of carbon (C) and hydrogen (H) on the left- and right-hand sides reveals that $2\,x = z \qquad\mbox{and} \qquad 6\,x = 2\,w .$ We thus have a linear system with 4 variables and 3 equations, which we can solve with the aid of Mathematica. Since the number of equations is less than the number of unknowns, we choose one variable, say W as a free one.

Solve[{2*y== 2*z+w, 2*x==z, 6*x ==2*w}, {x,y,z}]
{{x -> w/3, y -> (7 w)/6, z -> (2 w)/3}}
Since one variable w is free, we could choose it so that all of the variables end up having integer values. In particular, if we choose w = 6, then we getx = 2, y = 7, and z = 4, so that the balanced chemical equation becomes $2\,C_2 H_6 + 7\,O_2 \, = \, 4\,C\,O_2 + 6\,H_2 O .$
End of Example 9

Chiò’s Method

In 1853 Felice (Félix) Chiò (1813–1871) published his short Mémoire sur les fonctions connues sous le noms De Résultantes Ou De Déterminans. The details of Chiò’s life are not well known. In 1846 when he was teaching mathemat- ics at the Military Academy of Turin, he presented a paper to the Academy of Sciences in Paris that was reported in its proceedings, Comptes Rendus (v. XXIII, no. 10, 7 September 1846), and published in 1853 in the form of two memoirs as Recherches sur la série de Lagrange. In 1854 he was appointed to the chair of physics ‘sublime’ at the Military Academy. In the same year he was appointed professor of mathematical physics at the University of Turin.

Historically, before computers were available, most of examples and exercises in textbooks on Linear Algebra involve integers rather than fractions or irrational numbers or their floating point representations. Obviously, people prefer to keep it that way avoiding heavy manual calculations. We demonstrate such approach, which is referred to as Chiò’s method, in some examples.

Let us consider a 3 × 3 matrix ${\bf A} = \begin{bmatrix} 2& 3& -1 \\ 3& -2& 4 \\ 1& 5& 2 \end{bmatrix} .$ Suppose we want to treat the first entry in the first row as a pivot. In order to eliminate all entries in the first column below the pivot, we multiply by it (in our case, by "2") other rows: ${\bf A}_1 = \begin{bmatrix} 2& 3& -1 \\ 6& -4& 8 \\ 2& 10& 4 \end{bmatrix} .$

A = {{2, 3, -1}, {3, -2, 4}, {1, 5, 2}};
With row reductions R₂ ← R₂ − 3·R₁ and R₃ ← R₃ − R₁, we obtain an equivalent matrix ${\bf A}_2 = \begin{bmatrix} 2& 3& -1 \\ 0& -13& 11 \\ 0& 7& 5 \end{bmatrix} .$
A2 = {A[[1]], 2*A[[2]] - 3*A[[1]], 2*A[[3]] - A[[1]]}
{{2, 3, -1}, {0, -13, 11}, {0, 7, 5}}
Now we choose "−13" as a pivot in the second row, so we multiply by 13 the third row ${\bf A}_3 = \begin{bmatrix} 2& 3& -1 \\ 0& -13& 11 \\ 0& 91& 65 \end{bmatrix} .$
A3 = {A2[[1]], A2[[2]], 13*A2[[3]]}
{{2, 3, -1}, {0, -13, 11}, {0, 91, 65}}
Multiplying the second row by 7 and adding to the third row, we get
A4 = {A3[[1]], A3[[2]], A3[[3]] + 7*A3[[2]]}
{{2, 3, -1}, {0, -13, 11}, {0, 0, 142}}
${\bf A}_4 = \begin{bmatrix} 2& 3& -1 \\ 0& -13& 11 \\ 0& 0& 142 \end{bmatrix} .$ This all-integer approach is easier for mental calculations.

1. Anton, Howard (2005), Elementary Linear Algebra (Applications Version) (9th ed.), Wiley International
2. Beezer, R., A First Course in Linear Algebra, 2015.
3. Beezer, R., A Second Course in Linear Algebra, 2013.