08.02.2015 Views

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Matrices</strong> <strong>and</strong> <strong>Spaces</strong> <strong>of</strong> <strong>Matrices</strong>, Release 6.1.1<br />

•num_pivots - The number <strong>of</strong> non-zero rows in the result, i.e. the rank.<br />

OUTPUT:<br />

A matrix in reduced row echelon form with num_pivots non-zero rows. If the base ring is ZZ or QQ then<br />

the entries are all integers.<br />

Note: It is easiest to use this function via a call to the r<strong>and</strong>om_matrix() function with the<br />

algorithm=’echelon_form’ keyword. We provide one example accessing this function directly, while<br />

the remainder will use this more general function.<br />

EXAMPLES:<br />

<strong>Matrices</strong> generated are in reduced row-echelon form with specified rank. If the base ring is QQ the result has<br />

only integer entries.<br />

sage: from sage.matrix.constructor import r<strong>and</strong>om_rref_matrix<br />

sage: matrix_space = sage.matrix.matrix_space.MatrixSpace(QQ, 5, 6)<br />

sage: A=r<strong>and</strong>om_rref_matrix(matrix_space, num_pivots=4); A # r<strong>and</strong>om<br />

[ 1 0 0 -6 0 -3]<br />

[ 0 1 0 2 0 3]<br />

[ 0 0 1 -4 0 -2]<br />

[ 0 0 0 0 1 3]<br />

[ 0 0 0 0 0 0]<br />

sage: A.base_ring()<br />

Rational Field<br />

sage: (A.nrows(), A.ncols())<br />

(5, 6)<br />

sage: A in sage.matrix.matrix_space.MatrixSpace(ZZ, 5, 6)<br />

True<br />

sage: A.rank()<br />

4<br />

sage: A==A.rref()<br />

True<br />

<strong>Matrices</strong> can be generated over other exact rings.<br />

sage: B=r<strong>and</strong>om_matrix(FiniteField(7), 4, 4, algorithm=’echelon_form’, num_pivots=3); B # r<strong>and</strong>om<br />

[1 0 0 0]<br />

[0 1 0 6]<br />

[0 0 1 4]<br />

[0 0 0 0]<br />

sage: B.rank() == 3<br />

True<br />

sage: B.base_ring()<br />

Finite Field <strong>of</strong> size 7<br />

sage: B==B.rref()<br />

True<br />

TESTS:<br />

Rank <strong>of</strong> a matrix must be an integer.<br />

sage: r<strong>and</strong>om_matrix(QQ, 120, 56, algorithm=’echelon_form’, num_pivots=61/2)<br />

Traceback (most recent call last):<br />

...<br />

TypeError: the number <strong>of</strong> pivots must be an integer.<br />

<strong>Matrices</strong> must be generated over exact fields.<br />

52 Chapter 2. Matrix Constructor

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!