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

OUTPUT:<br />

Suppose that A is an m × n matrix, then an LU decomposition is a lower-triangular m × m matrix L with<br />

every diagonal element equal to 1, <strong>and</strong> an upper-triangular m × n matrix, U such that the product LU,<br />

after a permutation <strong>of</strong> the rows, is then equal to A. For the ‘plu’ format the permutation is returned as an<br />

m × m permutation matrix P such that<br />

A = P LU<br />

It is more common to place the permutation matrix just to the left <strong>of</strong> A. If you desire this version, then use<br />

the inverse <strong>of</strong> P which is computed most efficiently as its transpose.<br />

If the ‘partial’ pivoting strategy is used, then the non-diagonal entries <strong>of</strong> L will be less than or equal to 1 in<br />

absolute value. The ‘nonzero’ pivot strategy may be faster, but the growth <strong>of</strong> data structures for elements<br />

<strong>of</strong> the decomposition might counteract the advantage.<br />

By necessity, returned matrices have a base ring equal to the fraction field <strong>of</strong> the base ring <strong>of</strong> the original<br />

matrix.<br />

In the ‘compact’ format, the first returned value is a tuple that is a permutation <strong>of</strong> the rows <strong>of</strong> LU that<br />

yields A. See the doctest for how you might employ this permutation. Then the matrices L <strong>and</strong> U are<br />

merged into one matrix – remove the diagonal <strong>of</strong> ones in L <strong>and</strong> the remaining nonzero entries can replace<br />

the entries <strong>of</strong> U beneath the diagonal.<br />

The results are cached, only in the compact format, separately for each pivot strategy called. Repeated<br />

requests for the ‘plu’ format will require just a small amount <strong>of</strong> overhead in each call to bust out the<br />

compact format to the three matrices. Since only the compact format is cached, the components <strong>of</strong> the<br />

compact format are immutable, while the components <strong>of</strong> the ‘plu’ format are regenerated, <strong>and</strong> hence are<br />

mutable.<br />

Notice that while U is similar to row-echelon form <strong>and</strong> the rows <strong>of</strong> U span the row space <strong>of</strong> A, the rows <strong>of</strong><br />

U are not generally linearly independent. Nor are the pivot columns (or rank) immediately obvious. However<br />

for rings without specialized echelon form routines, this method is about twice as fast as the generic<br />

echelon form routine since it only acts “below the diagonal”, as would be predicted from a theoretical<br />

analysis <strong>of</strong> the algorithms.<br />

Note: This is an exact computation, so limited to exact rings. If you need numerical results, convert the<br />

base ring to the field <strong>of</strong> real double numbers, RDF or the field <strong>of</strong> complex double numbers, CDF, which<br />

will use a faster routine that is careful about numerical subtleties.<br />

ALGORITHM:<br />

“Gaussian Elimination with Partial Pivoting,” Algorithm 21.1 <strong>of</strong> [TREFETHEN-BAU].<br />

EXAMPLES:<br />

Notice the difference in the L matrix as a result <strong>of</strong> different pivoting strategies. With partial pivoting, every<br />

entry <strong>of</strong> L has absolute value 1 or less.<br />

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

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

... [2, 0, 1, 4, 2, 6, 0],<br />

... [1, 0, -1, 8, -1, -1, -3],<br />

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

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

sage: P<br />

[0 0 0 0 1]<br />

[1 0 0 0 0]<br />

[0 0 0 1 0]<br />

121

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

Saved successfully!

Ooh no, something went wrong!