Ask Your Question
1

Finding basis of image of Matrix

asked 2020-06-01 00:52:22 +0100

whatupmatt gravatar image

Is there a command that explicitly gives me the vectors for the image given a matrix M? If not, lets suppose I have the matrix in row echelon, N. So I create an empty list. Basically, I want to say while i< # of rows, if row i of row echelon form matrix N has a 1, put M[i] in list. But I don't know how to say if a row has a 1( a pivot).

P.s., yes I need the rows. My matrix is like transposed.

edit retag flag offensive close merge delete

Comments

Please provide code for a matrix you care about, that can be copy-pasted in a fresh Sage session.

slelievre gravatar imageslelievre ( 2020-06-02 00:56:22 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2020-06-02 01:02:54 +0100

slelievre gravatar image

In Sage, matrices have an image method.

The image is given as a vector space with basis.

Using random coefficients in a square matrix we are likely to get an invertible matrix whose image is the whole space.

sage: a = matrix(QQ, 4, [randint(-5, 5) for _ in range(16)])
sage: a
[-5 -1 -1  0]
[ 4 -1  1  5]
[-5 -4  3  3]
[ 1  1 -1  2]
sage: a.image()
Vector space of degree 4 and dimension 4 over Rational Field
Basis matrix:
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]

Now change the last line to be a combination of the first three lines.

sage: b = copy(a)
sage: b
[-5 -1 -1  0]
[ 4 -1  1  5]
[-5 -4  3  3]
[ 1  1 -1  2]
sage: b[3] = 3*b[2] + b[1] - b[0]
sage: b
[ -5  -1  -1   0]
[  4  -1   1   5]
[ -5  -4   3   3]
[ -6 -12  11  14]
sage: b.image()
Vector space of degree 4 and dimension 3 over Rational Field
Basis matrix:
[     1      0      0  29/33]
[     0      1      0 -97/33]
[     0      0      1 -16/11]
edit flag offensive delete link more

Comments

Thanks for your help.

whatupmatt gravatar imagewhatupmatt ( 2020-06-04 18:20:40 +0100 )edit
1

answered 2020-06-02 12:37:17 +0100

Juanjo gravatar image

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
edit flag offensive delete link more

Comments

Thanks for your help.

whatupmatt gravatar imagewhatupmatt ( 2020-06-04 18:20:56 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-06-01 00:52:22 +0100

Seen: 2,268 times

Last updated: Jun 02 '20