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 />

sage: r<strong>and</strong>om_matrix(QQ, 4, 10, den_bound = 10)<br />

[ -1 0 1/8 1/6 2/9 -1/6 1/5 -1/8 1/5 -1/5]<br />

[ 1/9 1/5 -1 2/9 1/4 -1/7 1/8 -1/9 0 2]<br />

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

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

R<strong>and</strong>om matrices over other rings. Several classes <strong>of</strong> matrices have specialized r<strong>and</strong>omize() methods. You<br />

can locate these with the <strong>Sage</strong> comm<strong>and</strong>:<br />

search_def(’r<strong>and</strong>omize’)<br />

The default implementation <strong>of</strong> r<strong>and</strong>omize() relies on the r<strong>and</strong>om_element() method for the base ring.<br />

The density <strong>and</strong> sparse keywords behave as described above.<br />

sage: K.=FiniteField(3^2)<br />

sage: r<strong>and</strong>om_matrix(K, 2, 5)<br />

[ 1 a 1 2*a + 1 2]<br />

[ 2*a a + 2 0 2 1]<br />

sage: r<strong>and</strong>om_matrix(RR, 3, 4, density=0.66)<br />

[ 0.000000000000000 -0.806696574554030 -0.693915509972359 0.000000000000000]<br />

[ 0.629781664418083 0.000000000000000 -0.833709843116637 0.000000000000000]<br />

[ 0.922346867410064 0.000000000000000 0.000000000000000 -0.940316454178921]<br />

sage: A = r<strong>and</strong>om_matrix(ComplexField(32), 3, density=0.8, sparse=True); A<br />

[ 0.000000000 0.399739209 + 0.909948633*I 0.000000000]<br />

[-0.361911424 - 0.455087671*I -0.687810605 + 0.460619713*I 0.625520058 - 0.360952012*I]<br />

[ 0.000000000 0.000000000 -0.162196416 - 0.193242896*I]<br />

sage: A.is_sparse()<br />

True<br />

R<strong>and</strong>om matrices in echelon form. The algorithm=’echelon_form’ keyword, along with a requested<br />

number <strong>of</strong> non-zero rows (num_pivots) will return a r<strong>and</strong>om matrix in echelon form. When the base ring is<br />

QQ the result has integer entries. Other exact rings may be also specified.<br />

sage: A=r<strong>and</strong>om_matrix(QQ, 4, 8, algorithm=’echelon_form’, num_pivots=3); A # r<strong>and</strong>om<br />

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

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

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

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

sage: A.base_ring()<br />

Rational Field<br />

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

(4, 8)<br />

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

True<br />

sage: A.rank()<br />

3<br />

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

True<br />

For more, see the documentation <strong>of</strong> the r<strong>and</strong>om_rref_matrix() function. In the notebook or at the <strong>Sage</strong><br />

comm<strong>and</strong>-line, first execute the following to make this further documentation available:<br />

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

R<strong>and</strong>om matrices with predictable echelon forms. The algorithm=’echelonizable’ keyword, along<br />

with a requested rank (rank) <strong>and</strong> optional size control (upper_bound) will return a r<strong>and</strong>om matrix in echelon<br />

form. When the base ring is ZZ or QQ the result has integer entries, whose magnitudes can be limited by the<br />

49

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

Saved successfully!

Ooh no, something went wrong!