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

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

...<br />

TypeError: base ring <strong>of</strong> the matrix needs a field <strong>of</strong> fractions, not Ring <strong>of</strong> integers modulo 6<br />

sage: R. = PolynomialRing(QQ, ’y’)<br />

sage: B = matrix(R, [[y+1, y^2+y], [y^2, y^3]])<br />

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

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

...<br />

TypeError: cannot take absolute value <strong>of</strong> matrix entries, try ’pivot=nonzero’<br />

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

sage: P<br />

[1 0]<br />

[0 1]<br />

sage: L<br />

[ 1 0]<br />

[y^2/(y + 1) 1]<br />

sage: U<br />

[ y + 1 y^2 + y]<br />

[ 0 0]<br />

sage: L.base_ring()<br />

Fraction Field <strong>of</strong> Univariate Polynomial Ring in y over Rational Field<br />

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

True<br />

sage: F. = FiniteField(5^2)<br />

sage: C = matrix(F, [[a + 3, 4*a + 4, 2, 4*a + 2],<br />

... [3, 2*a + 4, 2*a + 4, 2*a + 1],<br />

... [3*a + 1, a + 3, 2*a + 4, 4*a + 3],<br />

... [a, 3, 3*a + 1, a]])<br />

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

sage: P<br />

[1 0 0 0]<br />

[0 1 0 0]<br />

[0 0 1 0]<br />

[0 0 0 1]<br />

sage: L<br />

[ 1 0 0 0]<br />

[3*a + 3 1 0 0]<br />

[ 2*a 4*a + 2 1 0]<br />

[2*a + 3 2 2*a + 4 1]<br />

sage: U<br />

[ a + 3 4*a + 4 2 4*a + 2]<br />

[ 0 a + 1 a + 3 2*a + 4]<br />

[ 0 0 1 4*a + 2]<br />

[ 0 0 0 0]<br />

sage: L.base_ring()<br />

Finite Field in a <strong>of</strong> size 5^2<br />

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

True<br />

With no pivoting strategy given (i.e. pivot=None) the routine will try to use partial pivoting, but then<br />

fall back to the nonzero strategy. For the nonsingular matrix below, we see evidence <strong>of</strong> pivoting when<br />

viewed over the rationals, <strong>and</strong> no pivoting over the integers mod 29.<br />

sage: entries = [3, 20, 11, 7, 16, 28, 5, 15, 21, 23, 22, 18, 8, 23, 15, 2]<br />

sage: A = matrix(Integers(29), 4, 4, entries)<br />

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

124 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!