Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

As explained by @slelievre, you can use the image method to get the row space of a matrix, that is, the vector space spanned by its rows. Then, the basis method allows to explicitly get a basis as a list of vectors. For example, consider the matrix $$ A=\left(\begin{array}{rrrrrr} 3 & 6 & 3 & 3 & -6 & -3 \\ 4 & 8 & 4 & 4 & -8 & -4 \\ 3 & 6 & 0 & 0 & -6 & -9 \\ -3 & -6 & -3 & -4 & 7 & 3 \end{array}\right). $$ We first define this matrix and get its RREF:

sage: A = matrix(QQ,[[3, 6, 3, 3, -6, -3], [4, 8, 4, 4, -8, -4], 
....:                [3, 6, 0, 0, -6, -9], [-3, -6, -3, -4, 7, 3]])
sage: A.rref()
[ 1  2  0  0 -2 -3]
[ 0  0  1  0  1  2]
[ 0  0  0  1 -1  0]
[ 0  0  0  0  0  0]

The first three rows form a basis of $\operatorname{row} A$. This is what the image method also points out:

sage: A.image()
Vector space of degree 6 and dimension 3 over Rational Field
Basis matrix:
[ 1  2  0  0 -2 -3]
[ 0  0  1  0  1  2]
[ 0  0  0  1 -1  0]

Let us extract the basis:

sage: A.image().basis()
[
(1, 2, 0, 0, -2, -3),
(0, 0, 1, 0, 1, 2),
(0, 0, 0, 1, -1, 0)
]

As an alternative, the pivots_row method provides the rows in the matrix that are linearly independent (please, note, in the original matrix, not in the rref):

sage: p = A.pivot_rows(); p
(0, 2, 3)

Now you can extract these rows and get a basis of $\operatorname{row} A$:

sage: A[p,:].rows()
[(3, 6, 3, 3, -6, -3), (3, 6, 0, 0, -6, -9), (-3, -6, -3, -4, 7, 3)]

For the sake of completeness, let us check that these rows really span $\operatorname{row} A$:

sage: A[p,:].image() == A.image()
True