From A First Course in Linear Algebra
Version 2.00
© 2004.
Licensed under the GNU Free Documentation License.
http://linear.ups.edu/
Contributed by Steve Canfield
SAGE uses different rings to denote the type of an object. The rings are as
follows:
Most objects in SAGE will tell you which they are using with the base_ring() command. Keep this in mind, especially when row reducing or factoring. Here’s a quick example of where you might go wrong.
As you can clearly see, m isn’t even in reduced row-echelon form. This is because m is defined over the ZZ. You have to create matrices with the correct ring or you will get this type of odd result. This problem comes up in more places than just calculating the reduced row-echelon form, so unless you are specifically working with integers take note.
Contributed by Steve Canfield
A matrix in SAGE can be made a few ways. The first is simply
to define the matrix as an array of rows. SAGE uses brackets
(\left [\right . , \left .\right ])
to delimit arrays. So the input
a = matrix([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
|
would create a 3 × 4 matrix named a that is equal to
\left [\array{
1& 2 & 3 & 4
\cr
5& 6 & 7 & 8
\cr
9&10&11&12 } \right ]
|
SAGE will guess what type of matrix you are working with based on the inputs. If all the entries are integers, you will get back an integer matrix. If your matrix contains an entry in the {ℝ}^{} or {ℂ}^{} space, the matrix will be of those types. This can cause problems as integers cannot become fractions, which is an issue when calculating reduced row-echelon form. We therefore recommend using the following constructor to make your matrices:
a = matrix(QQ, [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
|
This gives you a matrix over the rational numbers which will be sufficient for
most of the course. If you are dealing with complex numbers you would replace
the QQ with CC.
To display a matrix named a , type a , and the output will be displayed with
rows and columns. If you type latex(a) you will get latex code to display
the matrix. Finally, SAGE will build an identity matrix for you with
im = identity\text{_}matrix(QQ, 3)
|
which yields
\left [\array{
1&0&0
\cr
0&1&0
\cr
0&0&1} \right ]
|
Contributed by Steve Canfield
If a is a
matrix defined in SAGE, then a.inverse() will return the inverse of
a, should it exist.
In the case where a
does not have an inverse SAGE will tell you the matrix must be nonsingular (see
Theorem NI).
Suppose a is the name of a matrix stored in SAGE. Then a.transpose() will return the transpose of a .
Contributed by Steve Canfield
SAGE can compute eigenspaces and eigenvalues for you. If you have a matrix
named a and you type
a.eigenspaces()
|
you will get a listing of the eigenvalues and the eigenspace for each. Let’s do an example.
Whew, that looks like a mess. At the top level, eigenspaces() returns a dictionary whose keys are the eigenvalues. So in this case we have eigenvalues 3 and -1. Each eigenvalue has an array after it that forms the basis of the eigenspace. In our example, there is 1 vector for λ = 3 and 2 vectors for λ = −1. Finally, the vectors SAGE spits out may not be the nicest ones to work with. In particular, we might want to scale the vectors to get rid of fractions.