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: P, L, U = A.LU()<br />

sage: P<br />

[0.0 0.0 0.0 0.0 1.0]<br />

[1.0 0.0 0.0 0.0 0.0]<br />

[0.0 0.0 1.0 0.0 0.0]<br />

[0.0 0.0 0.0 1.0 0.0]<br />

[0.0 1.0 0.0 0.0 0.0]<br />

sage: L.zero_at(0) # Use zero_at(0) to get rid <strong>of</strong> signed zeros<br />

[ 1.0 0.0 0.0 0.0 0.0]<br />

[ 0.0 1.0 0.0 0.0 0.0]<br />

[ 0.5 0.5 1.0 0.0 0.0]<br />

[0.75 0.25 0.0 1.0 0.0]<br />

[0.25 0.75 0.0 0.0 1.0]<br />

sage: U.zero_at(0) # Use zero_at(0) to get rid <strong>of</strong> signed zeros<br />

[24.0 25.0 26.0 27.0 28.0 29.0]<br />

[ 0.0 1.0 2.0 3.0 4.0 5.0]<br />

[ 0.0 0.0 0.0 0.0 0.0 0.0]<br />

[ 0.0 0.0 0.0 0.0 0.0 0.0]<br />

[ 0.0 0.0 0.0 0.0 0.0 0.0]<br />

sage: P*A-L*U<br />

[0.0 0.0 0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0 0.0 0.0]<br />

sage: P.transpose()*L*U<br />

[ 0.0 1.0 2.0 3.0 4.0 5.0]<br />

[ 6.0 7.0 8.0 9.0 10.0 11.0]<br />

[12.0 13.0 14.0 15.0 16.0 17.0]<br />

[18.0 19.0 20.0 21.0 22.0 23.0]<br />

[24.0 25.0 26.0 27.0 28.0 29.0]<br />

Trivial cases return matrices <strong>of</strong> the right size <strong>and</strong> characteristics.<br />

sage: A = matrix(RDF, 5, 0, entries=0)<br />

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

sage: P.parent()<br />

Full MatrixSpace <strong>of</strong> 5 by 5 dense matrices over Real Double Field<br />

sage: L.parent()<br />

Full MatrixSpace <strong>of</strong> 5 by 5 dense matrices over Real Double Field<br />

sage: U.parent()<br />

Full MatrixSpace <strong>of</strong> 5 by 0 dense matrices over Real Double Field<br />

sage: P*A-L*U<br />

[]<br />

The results are immutable since they are cached.<br />

sage: P, L, U = matrix(RDF, 2, 2, range(4)).LU()<br />

sage: L[0,0] = 0<br />

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

...<br />

ValueError: matrix is immutable; please change a copy instead (i.e., use copy(M) to change a<br />

sage: P[0,0] = 0<br />

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

...<br />

ValueError: matrix is immutable; please change a copy instead (i.e., use copy(M) to change a<br />

sage: U[0,0] = 0<br />

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

...<br />

351

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

Saved successfully!

Ooh no, something went wrong!