Skip to main content

Linear Algebra with SageMath: Learn math with open-source software

Section 4.1 Row Reduction

A matrix is in reduced echelon form if:
  • The first nonzero number in the row is a leading \(1\text{.}\)
  • In any two consecutive rows that do not consist entirely of zeros, the leading \(1\) in the lower row occurs farther to the right than the leading \(1\) in the higher row.
  • Rows that consist entirely of zeros are at the bottom of the matrix.
  • Each column that contains a leading \(1\) has zeros everywhere else in that column.
Let’s use Sage to find the reduced echelon form of the following system of equations:
\begin{align*} \amp x + 2y \amp = 4\\ \amp y - z \amp = 0\\ \amp x + 2z \amp = 4 \end{align*}
First, we create the augmented matrix for the system of equations. Each row in the augmented matrix lists the coefficients of the variables in an equation. While we do not directly manipulate the variables themselves, they indicate the position of each coefficient. The last column of the augmented matrix contains the constants from the right-hand side of each equation.
\begin{align*} \left[\begin{array}{ccc|c} 1 \amp 2 \amp 0 \amp 4 \\ 0 \amp 1 \amp -1 \amp 0 \\ 1 \amp 0 \amp 2 \amp 4 \end{array}\right] \end{align*}
Define the coefficient matrix.
Define the constants vector.
Next, create the augmented matrix by passing the constants vector to the augment() method of the coefficient matrix.
Alternatively, we can create the augmented matrix directly by passing a list of lists to the matrix function.
Use the rref() method on the augmented matrix to get the reduced echelon form.
We can also use Sage to help us with the individual steps of the row reduction process. Let’s begin again with the augmented matrix.
Use the add_multiple_of_row(i, j, s) method to add \(s\) times row \(j\) to row \(i\text{.}\) The arguemnts use \(0\) based indexing.
Since we already have a leading \(1\) in the first row, the next step is to multiply the first row by \(-1\) and add it to the third row.
Next, multiple the second row by \(2\) and add it to the third row.
Multiply the second row by \(-2\) and add it to the first row.
Now that we have the system in reduced echelong form, we can refer to the variabels we can find the solution.