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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<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,12,algorithm=’diagonalizable’,eigenvalues=[4,2,6],dimensions=[2,3,5,2])<br />

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

...<br />

ValueError: each eigenvalue must have a corresponding dimension <strong>and</strong> each dimension a correspondi<br />

TODO:<br />

Modify the routine to allow for complex eigenvalues.<br />

AUTHOR:<br />

Billy Wonderly (2010-07)<br />

sage.matrix.constructor.r<strong>and</strong>om_echelonizable_matrix(parent, rank, upper_bound=None,<br />

max_tries=100)<br />

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

Generate a matrix <strong>of</strong> a desired size <strong>and</strong> rank, over a desired ring, whose reduced row-echelon form has only<br />

integral values.<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 />

•rank - Rank <strong>of</strong> result, i.e the number <strong>of</strong> non-zero rows in the reduced row echelon form.<br />

•upper_bound - If designated, size control <strong>of</strong> the matrix entries is desired. Set upper_bound to 1<br />

more than the maximum value entries can achieve. If None, no size control occurs. But see the warning<br />

below. (default: None)<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 />

OUTPUT:<br />

A matrix not in reduced row-echelon form with the desired dimensions <strong>and</strong> properties.<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=’echelonizable’ keyword. We provide one example accessing this function directly, while<br />

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

EXAMPLES:<br />

Generated matrices have the desired dimensions, rank <strong>and</strong> entry size. The matrix in reduced row-echelon form<br />

has only integer entries.<br />

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

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

sage: A=r<strong>and</strong>om_echelonizable_matrix(matrix_space, rank=4, upper_bound=40); A # r<strong>and</strong>om<br />

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

[ 5 -4 0 8 4 19]<br />

[ -3 3 -2 4 7 -16]<br />

[ -4 5 -7 26 31 -31]<br />

44 Chapter 2. Matrix Constructor

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

Saved successfully!

Ooh no, something went wrong!