Section 1.1 Entering a matrix and row reduction
Matrices can be entered explicitly or generated randomly, even with prescribed properties. Here we enter the \(4\times 5\) matrix \(A\) explicitly.
The generic format to create an \(m\times n\) matrix \(A\) is A=matrix(R,[[row 1], ..., [row m]])
where each row has \(n\) comma-separated entries, and \(R\) is the ring (field) in which the coefficients lie. Typical for this is R
is replaced with ZZ
, QQ
, RR
,or CC
, for (respectively) the integers, the rational, real or complex numbers.
To print the matrix, either type A
on the next line, or separate the two commands on the same line as we have done below with a semicolon. The %display
latex
line simply tells the process to display the output in a nicely mathematically typeset fashion, and the line concerning delimeters writes matrices with square brackets instead of parentheses.
Whether the matrix \(A\) above represents the coefficient matrix or the augmented matrix of a linear system, one thing we often want to do is row reduce the matrix. We can produce either an echelon or the reduced row-echelon form (which we know to be unique.)
Make sure you have created the matrix above before executing the commands below, otherwise Sage will be confused.
Here is a command to put a matrix in echelon form which is often adequate to answer many questions about the associated linear system.
Here we produce the reduced row-echelon form of \(A.\)
Remark 1.1.1. Does the choice of ring (ZZ,QQ,RR,CC) matter?
This is a slightly subtle point you can ignore for now choosing your ring to be QQ or RR. Note that in the former case your answers will have fractions; in the later, it will have decimal approximations.
Also, in the first example I chose the ring to be ZZ (the integers), and Sage tries to do arithmetic in the ring you choose. This is the reason the echelon form has no fractions. If you go back and change ZZ to QQ in the definition of the matrix \(A,\) the answers given by echelon_form
and rref
will be the same.
Playground space (Enter your own commands).