Activity 5.2.1. Using Sage to find row reduced echelon matrices.
We may ask Sage to create the \(2\times4\) matrix
\begin{equation*}
\left[
\begin{array}{rrrr}
-1 \amp 0 \amp 2 \amp 7 \\
2 \amp 1 \amp -3 \amp -1 \\
\end{array}
\right]
\end{equation*}
by entering When evaluated, Sage will confirm the matrix by writing out the rows of the matrix, each inside square brackets.
Notice that there are three separate things (we call them arguments) inside the parentheses: the number of rows, the number of columns, and the entries of the matrix listed by row inside square brackets. These three arguments are separated by commas. Notice that there is no way of specifying whether this is an augmented or coefficient matrix so it will be up to us to interpret our results appropriately.
Sage syntax.
Some common mistakes are
- to forget the square brackets around the list of entries,
- to omit an entry from the list or to add an extra one,
- to forget to separate the rows, columns, and entries by commas, and
- to omit the parentheses around the arguments after
matrix.
If you see an error message, carefully proofread your input and try again.
- Enter the following matrix into Sage.\begin{equation*} \left[ \begin{array}{rrrr} -1 \amp -2 \amp 2 \amp -1 \\ 2 \amp 4 \amp -1 \amp 5 \\ 1 \amp 2 \amp 0 \amp 3 \end{array} \right] \end{equation*}
-
Give the matrix the name \(A\) by entering
A = matrix( ..., ..., [ ... ])We may then find its reduced row echelon form by enteringA = matrix( ..., ..., [ ... ]) A.rref()A common mistake is to forget the parentheses afterrref.Sage practices.
Here are some practices that you may find helpful when working with matrices in Sage.- Break the matrix entries across lines, one for each row, for better readability by pressing Enter between rows.
A = matrix(2, 4, [ 1, 2, -1, 0, -3, 0, 4, 3 ]) - Print your original matrix to check that you have entered it correctly. You may want to also print a dividing line to separate matrices.
A = matrix(2, 2, [ 1, 2, 2, 2]) print (A) print ("---------") A.rref()
Use Sage to find the reduced row echelon form of the matrix from Item a of this activity. - Use Sage to describe the solution space of the system of linear equations\begin{equation*} \begin{alignedat}{5} -x_1 \amp \amp \amp \amp \amp {}+{} \amp 2x_4 \amp {}={} \amp 4 \\ \amp \amp 3x_2 \amp {}+{} \amp x_3 \amp {}+{} \amp 2x_4 \amp {}={} \amp 3 \\ 4x_1 \amp {}-{} \amp 3x_2 \amp \amp \amp {}+{} \amp x_4 \amp {}={} \amp 14 \\ \amp \amp 2x_2 \amp {}+{} \amp 2x_3 \amp {}+{} \amp x_4 \amp {}={} \amp 1 \\ \end{alignedat} \end{equation*}
-
Consider the two matrices:\begin{equation*} \begin{array}{rcl} A \amp = \amp \left[ \begin{array}{rrrr} 1 \amp -2 \amp 1 \amp -3 \\ -2 \amp 4 \amp 1 \amp 1 \\ -4 \amp 8 \amp -1 \amp 7 \\ \end{array}\right] \\ B \amp = \amp \left[ \begin{array}{rrrrrr} 1 \amp -2 \amp 1 \amp -3 \amp 0 \amp 3 \\ -2 \amp 4 \amp 1 \amp 1 \amp 1 \amp -1 \\ -4 \amp 8 \amp -1 \amp 7 \amp 3 \amp 2 \\ \end{array}\right] \\ \end{array} \end{equation*}We say that \(B\) is an augmentation of \(A\) because it is obtained from \(A\) by adding some more columns.Using Sage, define the matrices and compare their reduced row echelon forms. What do you notice about the relationship between the two reduced row echelon forms?
-
Using the system of equations in Item c, write the augmented matrix corresponding to the system of equations. What did you find for the reduced row echelon form of the augmented matrix?Now write the coefficient matrix of this system of equations. What does Item d of this activity tell you about its reduced row echelon form?
Answer.
matrix(3, 4, [-1,-2, 2,-1, 2, 4,-1, 5, 1, 2, 0, 3])- The reduced row echelon form of the matrix is\begin{equation*} \begin{bmatrix} 1 \amp 2 \amp 0 \amp 3 \\ 0 \amp 0 \amp 1 \amp 1 \\ 0 \amp 0 \amp 0 \amp 0 \end{bmatrix}. \end{equation*}
- There is a unique solution \((x_1,x_2,x_3,x_4) = (-2,-1,0,3)\text{.}\)
- The first four columns of the reduced row echelon form of \(B\) form the reduced row echelon form of \(A\text{.}\)
- The reduced row echelon form of the coefficient matrix is\begin{equation*} \begin{bmatrix} 1 \amp 0 \amp 0 \amp 0 \\ 0 \amp 1 \amp 0 \amp 0 \\ 0 \amp 0 \amp 1 \amp 0 \\ 0 \amp 0 \amp 0 \amp 1 \\ \end{bmatrix}. \end{equation*}
Solution.
matrix(3, 4, [-1,-2, 2,-1, 2, 4,-1, 5, 1, 2, 0, 3])- The reduced row echelon form of the matrix is\begin{equation*} \begin{bmatrix} 1 \amp 2 \amp 0 \amp 3 \\ 0 \amp 0 \amp 1 \amp 1 \\ 0 \amp 0 \amp 0 \amp 0 \end{bmatrix}. \end{equation*}
- Sage tells us that the reduced row echelon form of the corresponding augmented matrix is\begin{equation*} \begin{bmatrix} 1 \amp 0 \amp 0 \amp 0 \amp -2 \\ 0 \amp 1 \amp 0 \amp 0 \amp -1 \\ 0 \amp 0 \amp 1 \amp 0 \amp 0 \\ 0 \amp 0 \amp 0 \amp 1 \amp 3 \\ \end{bmatrix} \end{equation*}so there is a unique solution \((x_1,x_2,x_3,x_4) = (-2,-1,0,3)\text{.}\)
- The first four columns of the reduced row echelon form of \(B\) form the reduced row echelon form of \(A\text{.}\)
- The reduced row echelon form of the coefficient matrix is\begin{equation*} \begin{bmatrix} 1 \amp 0 \amp 0 \amp 0 \\ 0 \amp 1 \amp 0 \amp 0 \\ 0 \amp 0 \amp 1 \amp 0 \\ 0 \amp 0 \amp 0 \amp 1 \\ \end{bmatrix}. \end{equation*}
