2.5. Gaussian elimination#
Gaussian elimination (GE) named after German mathematician Carl Friedrich Gauss is an algorithm for solving systems of linear equations. It is the most common method used in practice since it can by easily programmed into a computer and applied to larger systems. Consider the following method for solving a linear system of three equations in three unknowns:
Swap the first two equations around
Subtract 3 times the first equation from the second equation and 2 times the first equation from the third equation
Multiply the second equation by \(\dfrac{1}{4}\)
Add the second equation to the third
Here the third equation gives the solution to \(x_3=-4\). We can substitute the value of \(x_3\) into the other two to find the solutions of \(x_2\) and \(x_1\)
In this method, we used three types of operations on the equations in the system. These operations are known as elementary row operations.
(Elementary Row Operations (EROs))
The three elementary row operations that can be applied to a linear system of equations without changing the solution are
Type I: swap any two rows of the system
Type II: multiply one row by a non-zero scalar
Type III: replace a single row by itself plus a multiple of another row
In the solution to the linear system of equations shown above we used a type I row operation in step 1, a type II row operation in step 3 and type III row operations in steps 2 and 4.
We can represent the linear system using matrices for convenience. We begin by expressing the linear system using an augmented matrix consisting of the concatenation of \(A\) and \(\vec{x}\) so any EROs that are applied to the augmented matrix are applied to the coefficients and the constant terms at the same time.
(Augmented matrix)
The augmented matrix is a representation of a system of linear equations \(A\vec{x}=\vec{b}\) such that the \(m\times n\) coefficient matrix \(A\) and right-hand side constant vector \(\vec{b}\) are combined into a single \(m\times (n+1)\) matrix \((A \mid \vec{b})\).
When writing the augmented matrix we often draw a partition separating \(A\) and \(\vec{b}\) (although this is not strictly necessary), i.e.,
Elementary row operations are applied to the augmented matrix so that we reduce it to what is known as row echelon form where the solution of the system can be easily calculated.
(Row Echelon Form (REF))
A matrix is said to be in Row Echelon Form (REF) if the following conditions are satisfied:
Any non-zero rows are above any all-zero rows
In each non-zero row the pivot element, the first non-zero element in the row, is to the right of the pivot element in the row above
For example, the following matrices are in row echelon form and the red numbers are the pivot elements
Note that the elements below the pivot elements are all zero.
2.5.1. Row reduction#
The process of transforming a matrix into row echelon form using elementary row operations is known as row reduction. For example, we will use Gaussian elimination to solve the following system of linear equations
Expressing this using an augmented matrix, we have
The first pivot element is in row 1 column 1 which has a value of 3. We need to apply row operations so that the elements in the column beneath the pivot element are zero. To do so we add a multiple of the pivot row to each of the rows beneath (a type III row operation). Since the pivot element is 3 and the first non-zero element in row 2 is 1, to reduce this to zero we subtract row 1 multiplied by \(\dfrac{1}{3}\) from row 2.
We also need to do the same to row 3. Since the element row 3 column 1 has a value of 2, we need to subtract row 1 multiplied by \(\dfrac{2}{3}\) from row 3.
Note that these two row operations could have been done simultaneously since changing the values in row 2 does not affect row 3 and vice-versa. Column 1 is now in row echelon form so we move to the next pivot element in row 2 which is \(-\dfrac{4}{3}\).
The element in row 3 column 2 has a value of \(-\dfrac{11}{3}\) and the pivot element has a value of \(-\dfrac{4}{3}\) so we need to subtract row 2 multiplied by \(-\dfrac{11}{3} \div \left(-\dfrac{4}{3}\right) = \dfrac{11}{4}\) from row 3.
Now the augmented matrix is in row echelon form. We can convert back to matrix form and express the linear system as three separate equations.
Since we have reduced the coefficient matrix to row echelon form we have a solution for the final variable. We can then substitute known values of the variables into the preceding equation to solve for the preceding variable. We continue in this way until we have solutions for all of the variables in the system. This step is known as back substitution. So for our system the final equation gives \(x_3=-4\) so substitution into the second equation gives
and substituting \(x_2\) and \(x_3\) into the first equation gives
In the interest of brevity, the following notation is used to denote the three types of EROs
Swap row \(i\) and row \(j\): \(R_i \leftrightarrow R_j\)
Multiply row \(i\) by the scalar \(k\): \(kR_i\)
Add \(k\) multiples of row \(j\) to row \(i\): \(R_i + kR_j\)
Since the EROs do not change the solution to the system of equations, it does not matter which EROs are applied to row reduce the augmented matrix. A common approach is to ensure the pivot elements have a value of 1 which can decrease the number of fractional values thus simplifying the calculations. For example, consider the following row reduction of the same augmented matrix as before.
Solving using back substitution gives \(x_1 = 1\), \(x_2 = -10\) and \(x_3 = -4\) which was the same solution as we saw before.
The steps used in Gaussian elimination are summarised in Algorithm 2.1.
(Gaussian elimination)
Inputs: An \(m \times n\) coefficient matrix \(A\) and an \(m\)-element constant vector \(\vec{b}\).
Outputs: An augmented matrix in row echelon form.
Form the augmented matrix \(( A \mid \vec{b} )\)
Set pivot row \(k\) to 1
For each column \(j\) from 1 to \(n\):
Check pivot element:
If the pivot element \(a_{kj} = 0\)
Identify a row \(i\) where \(i > j\) and \(a_{ij} \neq 0\), if no such row exists skip to the next column
Swap row \(i\) with row \(k\)
Eliminate elements below pivot:
For each row \(i\) from \(k+1\) to \(m\):
Subtract \(\dfrac{a_{ij}}{a_{jj}}\) times row \(j\) from row \(i\)
Use Gaussian-elimination to solve the following systems of linear equations:
(i) \( \begin{align*} x_1 + 2x_2 &= 7, \\ 3x_1 - 4x_2 &= 1. \end{align*} \)
Solution
Solving for \(x_1\) and \(x_2\) using back substitution
This solution can be easily verified by substituting it back into the original system.
(ii) \(\begin{align*} x_1 + x_3 &= 3, \\ -2x_1 + x_2 + 3x_3 &= 3, \\ -x_1 + 2x_2 + 4x_3 &= 5. \end{align*}\)
Solution
Solving for \(x_1\), \(x_2\) and \(x_3\) using back substitution