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.matrix.constructor.r<strong>and</strong>om_unimodular_matrix(parent, upper_bound=None,<br />

max_tries=100)<br />

This function is available as r<strong>and</strong>om_unimodular_matrix(...) <strong>and</strong> matrix.r<strong>and</strong>om_unimodular(...).<br />

Generate a r<strong>and</strong>om unimodular (determinant 1) matrix <strong>of</strong> a desired size over a desired ring.<br />

INPUT:<br />

•parent - A matrix space specifying the base ring, dimensions <strong>and</strong> representation (dense/sparse) for the<br />

result. The base ring must be exact.<br />

•upper_bound - For large matrices over QQ or ZZ, upper_bound is the largest value matrix entries<br />

can achieve. But see the warning below.<br />

•max_tries - If designated, number <strong>of</strong> tries used to generate each new r<strong>and</strong>om row; only matters when<br />

upper_bound!=None. Used to prevent endless looping. (default: 100)<br />

A matrix not in reduced row-echelon form with the desired dimensions <strong>and</strong> properties.<br />

OUTPUT:<br />

An invertible matrix with the desired properties <strong>and</strong> determinant 1.<br />

Warning: When upper_bound is set, it is possible for this constructor to fail with a ValueError. This<br />

may happen when the upper_bound, rank <strong>and</strong>/or matrix dimensions are all so small that it becomes<br />

infeasible or unlikely to create the requested matrix. If you must have this routine return successfully, do not<br />

set upper_bound.<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=’unimodular’ keyword. We provide one example accessing this function directly, while<br />

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

EXAMPLES:<br />

A matrix size 5 over QQ.<br />

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

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

sage: A=r<strong>and</strong>om_unimodular_matrix(matrix_space); A # r<strong>and</strong>om<br />

[ -8 31 85 148 -419]<br />

[ 2 -9 -25 -45 127]<br />

[ -1 10 30 65 -176]<br />

[ -3 12 33 58 -164]<br />

[ 5 -21 -59 -109 304]<br />

sage: det(A)<br />

1<br />

A matrix size 6 with entries no larger than 50.<br />

sage: B=r<strong>and</strong>om_matrix(ZZ, 7, algorithm=’unimodular’, upper_bound=50);B # r<strong>and</strong>om<br />

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

[ 1 2 -5 0 14 19 -49]<br />

[ -3 -2 12 5 -6 -4 24]<br />

[ 1 2 -9 -3 3 4 -7]<br />

[ -2 -1 7 2 -8 -5 31]<br />

[ 2 2 -6 -3 8 16 -32]<br />

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

sage: det(B)<br />

1<br />

56 Chapter 2. Matrix Constructor

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

Saved successfully!

Ooh no, something went wrong!