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

[ 1/4 -1/8 3 4 5]<br />

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

[ 3 4 5 1/4 -1/8]<br />

Without subdivisions it also deduces dimensions for scalars if possible:<br />

sage: C = matrix(ZZ, 1, 2, range(2))<br />

sage: block_matrix([ [ C, 0 ], [ 3, 4 ], [ 5, 6, C ] ], subdivide=False )<br />

[0 1 0 0]<br />

[3 0 4 0]<br />

[0 3 0 4]<br />

[5 6 0 1]<br />

If all submatrices are sparse (unless there are none at all), the result will be a sparse matrix. Otherwise it will be<br />

dense by default. The sparse keyword can be used to override this:<br />

sage: A = Matrix(ZZ, 2, 2, [0, 1, 0, 0], sparse=True)<br />

sage: block_matrix([ [ A ], [ A ] ]).parent()<br />

Full MatrixSpace <strong>of</strong> 4 by 2 sparse matrices over Integer Ring<br />

sage: block_matrix([ [ A ], [ A ] ], sparse=False).parent()<br />

Full MatrixSpace <strong>of</strong> 4 by 2 dense matrices over Integer Ring<br />

Consecutive zero submatrices are consolidated.<br />

sage: B = matrix(2, range(4))<br />

sage: C = matrix(2, 8, range(16))<br />

sage: block_matrix(2, [[B,0,0,B],[C]], subdivide=False)<br />

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

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

[ 0 1 2 3 4 5 6 7]<br />

[ 8 9 10 11 12 13 14 15]<br />

Ambiguity is not tolerated.<br />

sage: B = matrix(2, range(4))<br />

sage: C = matrix(2, 8, range(16))<br />

sage: block_matrix(2, [[B,0,B,0],[C]], subdivide=False)<br />

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

...<br />

ValueError: insufficient information to determine submatrix widths<br />

Historically, giving only a flat list <strong>of</strong> submatrices, whose number was a perfect square, would create a new<br />

matrix by laying out the submatrices in a square grid. This behavior is now deprecated.<br />

sage: A = matrix(2, 3, range(6))<br />

sage: B = matrix(3, 3, range(9))<br />

sage: block_matrix([A, A, B, B])<br />

doctest:...: DeprecationWarning: invocation <strong>of</strong> block_matrix with just a list whose length is a p<br />

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

[3 4 5|3 4 5]<br />

[-----+-----]<br />

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

[3 4 5|3 4 5]<br />

[6 7 8|6 7 8]<br />

Historically, a flat list <strong>of</strong> matrices whose number is not a perfect square, with no specification <strong>of</strong> the number <strong>of</strong><br />

rows or columns, would raise an error. This behavior continues, but could be removed when the deprecation<br />

above is completed.<br />

24 Chapter 2. Matrix Constructor

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

Saved successfully!

Ooh no, something went wrong!