Subsection 1.3.2 Sage and matrices
When we encounter a matrix,
Theorem 1.2.6 tells us that there is exactly one reduced row echelon matrix that is row equivalent to it.
In fact, the uniqueness of this reduced row echelon matrix is what motivates us to define this particular form. When solving a system of linear equations using Gaussian elimination, there are other row equivalent matrices that reveal the structure of the solution space. The reduced row echelon matrix is simply a convenience as it is an agreement we make with one another to seek the same matrix.
An added benefit is that we can ask a computer program, like Sage, to find reduced row echelon matrices for us. We will learn how to do this now that we have a little familiarity with Sage.
First, notice that a matrix has a certain number of rows and columns. For instance, the matrix
has three rows and five columns. We consequently refer to this as a
matrix.
We may ask Sage to create the
matrix
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.
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.
Alternatively, you can create a matrix by simply listing its rows, like this
matrix([ [-1, 0, 2, 7],
[ 2, 1,-3,-1] ])
Activity 1.3.2. Using Sage to find row reduced echelon matrices.
Enter the following matrix into Sage.
-
Give the matrix the name by entering
A = matrix( ..., ..., [ ... ])
We may then find its reduced row echelon form by entering
A = matrix( ..., ..., [ ... ])
A.rref()
A common mistake is to forget the parentheses after 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
-
Consider the two matrices:
We say that is an augmentation of because it is obtained from 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?
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()
The last part of the previous activity,
Item d, demonstrates something that will be helpful for us in the future. In that activity, we started with a matrix
which we augmented by adding some columns to obtain a matrix
We then noticed that the reduced row echelon form of
is itself an augmentation of the reduced row echelon form of
To illustrate, we can consider the reduced row echelon form of the augmented matrix:
We can then determine the reduced row echelon form of the coefficient matrix by looking inside the augmented matrix.
If we trace through the steps in the Gaussian elimination algorithm carefully, we see that this is a general principle, which we now state.
Proposition 1.3.1. Augmentation Principle.
If matrix
is an augmentation of matrix
then the reduced row echelon form of
is an augmentation of the reduced row echelon form of
Subsection 1.3.3 Computational effort
At the beginning of this section, we indicated that linear algebra has become more prominent as computers have grown more powerful. Computers, however, still have limits. Let’s consider how much effort is expended when we ask to find the reduced row echelon form of a matrix. We will measure, very roughly, the effort by the number of times the algorithm requires us to multiply or add two numbers.
We will assume that our matrix has the same number of rows as columns, which we call
We are mainly interested in the case when
is very large, which is when we need to worry about how much effort is required.
Let’s first consider the effort required for each of our row operations.
Scaling a row multiplies each of the entries in a row by some number, which requires operations.
Interchanging two rows requires no multiplications or additions so we won’t worry about the effort required by an interchange.
A replacement requires us to multiply each entry in a row by some number, which takes operations, and then add the resulting entries to another row, which requires another operations. The total number of operations is
Our goal is to transform a matrix to its reduced row echelon form, which looks something like this:
We roughly perform one replacement operation for every 0 entry in the reduced row echelon matrix. When
is very large, most of the
entries in the reduced row echelon form are 0 so we need roughly
replacements. Since each replacement operation requires
operations, the number of operations resulting from the needed replacements is roughly
Each row is scaled roughly one time so there are roughly
scaling operations, each of which requires
operations. The number of operations due to scaling is roughly
Therefore, the total number of operations is roughly
When
is very large, the
term is much smaller than the
term. We therefore state that
This is a very rough measure of the effort required to find the reduced row echelon form; a more careful accounting shows that the number of arithmetic operations is roughly
As we have seen, some matrices require more effort than others, but the upshot of this observation is that the effort is proportional to
We can think of this in the following way: If the size of the matrix grows by a factor of 10, then the effort required grows by a factor of
While today’s computers are powerful, they cannot handle every problem we might ask of them. Eventually, we would like to be able to consider matrices that have
(a trillion) rows and columns. In very broad terms, the effort required to find the reduced row echelon matrix will require roughly
operations.
To put this into context, imagine we need to solve a linear system with a trillion equations and a trillion variables and that we have a computer that can perform a trillion,
operations every second. Finding the reduced row echelon form would take about
years. At this time, the universe is estimated to be approximately
years old. If we started the calculation when the universe was born, we’d be about one-millionth of the way through.
This may seem like an absurd situation, but we’ll see in
Subsection 4.5.3 how we use the results of such a computation every day. Clearly, we will need some better tools to deal with
really big problems like this one.