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

Hilbert matrices are famously ill-conditioned, while an identity matrix can hit the minimum with the right<br />

norm.<br />

sage: A = matrix(RDF, 10, [1/(i+j+1) for i in range(10) for j in range(10)])<br />

sage: A.condition()<br />

1.633...e+13<br />

sage: id = identity_matrix(CDF, 10)<br />

sage: id.condition(p=1)<br />

1.0<br />

Return values are in RDF .<br />

sage: A = matrix(CDF, 2, range(1,5))<br />

sage: A.condition() in RDF<br />

True<br />

Rectangular <strong>and</strong> singular matrices raise errors if p is not ‘sv’.<br />

sage: A = matrix(RDF, 2, 3, range(6))<br />

sage: A.condition()<br />

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

...<br />

TypeError: matrix must be square if p is not ’sv’, not 2 x 3<br />

sage: A.condition(’sv’)<br />

7.34...<br />

sage: A = matrix(QQ, 5, range(25))<br />

sage: A.is_singular()<br />

True<br />

sage: B = A.change_ring(CDF)<br />

sage: B.condition()<br />

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

...<br />

LinAlgError: Singular matrix<br />

Improper values <strong>of</strong> p are caught.<br />

sage: A = matrix(CDF, 2, range(1,5))<br />

sage: A.condition(p=’bogus’)<br />

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

...<br />

ValueError: condition number ’p’ must be +/- infinity, ’frob’, ’sv’ or an integer, not bogus<br />

sage: A.condition(p=632)<br />

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

...<br />

ValueError: condition number integer values <strong>of</strong> ’p’ must be -2, -1, 1 or 2, not 632<br />

TESTS:<br />

Some condition numbers, first by the definition which also exercises norm(), then by this method.<br />

sage: A = matrix(CDF, [[1,2,4],[5,3,9],[7,8,6]])<br />

sage: c = A.norm(2)*A.inverse().norm(2)<br />

sage: d = A.condition(2)<br />

sage: abs(c-d) < 1.0e-12<br />

True<br />

sage: c = A.norm(1)*A.inverse().norm(1)<br />

sage: d = A.condition(1)<br />

sage: abs(c-d) < 1.0e-12<br />

True<br />

360 Chapter 19. Dense matrices using a NumPy backend.

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

Saved successfully!

Ooh no, something went wrong!