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

The QR decoposition will produce a unitary matrix as Q <strong>and</strong> the SVD decomposition will create two<br />

unitary matrices, U <strong>and</strong> V.<br />

sage: A = matrix(CDF, [[ 1 - I, -3*I, -2 + I, 1, -2 + 3*I],<br />

... [ 1 - I, -2 + I, 1 + 4*I, 0, 2 + I],<br />

... [ -1, -5 + I, -2 + I, 1 + I, -5 - 4*I],<br />

... [-2 + 4*I, 2 - I, 8 - 4*I, 1 - 8*I, 3 - 2*I]])<br />

sage: Q, R = A.QR()<br />

sage: Q.is_unitary()<br />

True<br />

sage: U, S, V = A.SVD()<br />

sage: U.is_unitary(algorithm=’naive’)<br />

True<br />

sage: U.is_unitary(algorithm=’orthonormal’)<br />

True<br />

sage: V.is_unitary(algorithm=’naive’) # not tested - known bug (trac #11248)<br />

True<br />

If we make the tolerance too strict we can get misleading results.<br />

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

sage: Q, R = A.QR()<br />

sage: Q.is_unitary(algorithm=’naive’, tol=1e-16)<br />

False<br />

sage: Q.is_unitary(algorithm=’orthonormal’, tol=1e-17)<br />

False<br />

Rectangular matrices are not unitary/orthogonal, even if their columns form an orthonormal set.<br />

sage: A = matrix(CDF, [[1,0], [0,0], [0,1]])<br />

sage: A.is_unitary()<br />

False<br />

The smallest cases. The Schur decomposition used by the orthonormal algorithm will fail on a matrix <strong>of</strong><br />

size zero.<br />

sage: P = matrix(CDF, 0, 0)<br />

sage: P.is_unitary(algorithm=’naive’)<br />

True<br />

sage: P = matrix(CDF, 1, 1, [1])<br />

sage: P.is_unitary(algorithm=’orthonormal’)<br />

True<br />

sage: P = matrix(CDF, 0, 0,)<br />

sage: P.is_unitary(algorithm=’orthonormal’)<br />

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

...<br />

ValueError: failed to create intent(cache|hide)|optional array-- must have defined dimension<br />

TESTS:<br />

sage: P = matrix(CDF, 2, 2)<br />

sage: P.is_unitary(tol=’junk’)<br />

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

...<br />

TypeError: tolerance must be a real number, not junk<br />

sage: P.is_unitary(tol=-0.3)<br />

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

375

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

Saved successfully!

Ooh no, something went wrong!