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

(0, 1, 2, 3)<br />

sage: B = matrix(QQ, 4, 4, entries)<br />

sage: perm, _ = B.LU(format=’compact’); perm<br />

(2, 0, 1, 3)<br />

The U matrix is only guaranteed to be upper-triangular. The rows are not necessarily linearly independent,<br />

nor are the pivots columns or rank in evidence.<br />

sage: A = matrix(QQ, [[ 1, -4, 1, 0, -2, 1, 3, 3, 2],<br />

... [-1, 4, 0, -4, 0, -4, 5, -7, -7],<br />

... [ 0, 0, 1, -4, -1, -3, 6, -5, -6],<br />

... [-2, 8, -1, -4, 2, -4, 1, -8, -7],<br />

... [ 1, -4, 2, -4, -3, 2, 5, 6, 4]])<br />

sage: P, L, U = A.LU()<br />

sage: U<br />

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

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

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

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

[ 0 0 0 0 1/3 -3 7/3 -19/3 -19/3]<br />

sage: A.rref()<br />

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

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

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

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

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

sage: A.pivots()<br />

(0, 2, 4, 5)<br />

TESTS:<br />

Unknown keywords are caught.<br />

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

sage: A.LU(pivot=’junk’)<br />

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

...<br />

ValueError: pivot strategy must be None, ’partial’ or ’nonzero’, not junk<br />

sage: A.LU(format=’garbage’)<br />

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

...<br />

ValueError: format must be ’plu’ or ’compact’, not garbage<br />

Components <strong>of</strong> the ‘compact’ format are immutable, while components <strong>of</strong> the ‘plu’ format are not.<br />

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

sage: perm, M = A.LU(format=’compact’)<br />

sage: perm[0] = 25<br />

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

...<br />

TypeError: ’tuple’ object does not support item assignment<br />

sage: M.is_immutable()<br />

True<br />

sage: P, L, U = A.LU(format=’plu’)<br />

sage: all([A.is_mutable() for A in [P, L, U]])<br />

True<br />

Partial pivoting is based on the absolute values <strong>of</strong> entries <strong>of</strong> a column. Trac #12208 shows that the return<br />

value <strong>of</strong> the absolute value must be h<strong>and</strong>led carefully. This tests that situation in the case <strong>of</strong> cylotomic<br />

fields.<br />

125

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

Saved successfully!

Ooh no, something went wrong!