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 0 1 0 0]<br />

[0 1 0 0 0]<br />

sage: L<br />

[ 1 0 0 0 0]<br />

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

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

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

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

sage: U<br />

[ 2 -1 0 6 4 8 -2]<br />

[ 0 3/2 2 -5 -3 -3 4]<br />

[ 0 0 -5/3 20/3 -2 -4 -10/3]<br />

[ 0 0 0 0 2/5 4/5 0]<br />

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

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

True<br />

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

sage: P<br />

[1 0 0 0 0]<br />

[0 1 0 0 0]<br />

[0 0 1 0 0]<br />

[0 0 0 1 0]<br />

[0 0 0 0 1]<br />

sage: L<br />

[ 1 0 0 0 0]<br />

[ 2 1 0 0 0]<br />

[ 2 2 1 0 0]<br />

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

[ 1 2 2 0 1]<br />

sage: U<br />

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

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

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

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

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

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

True<br />

An example <strong>of</strong> the compact format.<br />

sage: B = matrix(QQ, [[ 1, 3, 5, 5],<br />

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

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

... [ 0, -2, -5, -8],<br />

... [-2, -6, -6, -2]])<br />

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

sage: perm<br />

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

sage: M<br />

[ -2 -6 -6 -2]<br />

[ 0 -2 -5 -8]<br />

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

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

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

We can easily illustrate the relationships between the two formats with a square matrix.<br />

sage: C = matrix(QQ, [[-2, 3, -2, -5],<br />

... [ 1, -2, 1, 3],<br />

122 Chapter 7. Base class for matrices, part 2

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

Saved successfully!

Ooh no, something went wrong!