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

sage: ( L*L.transpose() - m ).norm(1) < 2^-50<br />

True<br />

Here is a Hermitian example:<br />

sage: r = matrix(CDF, 2, 2, [ 1, -2*I, 2*I, 6 ]); r<br />

[ 1.0 -2.0*I]<br />

[ 2.0*I 6.0]<br />

sage: r.eigenvalues()<br />

[0.298437881284, 6.70156211872]<br />

sage: ( r - r.conjugate().transpose() ).norm(1) < 1e-30<br />

True<br />

sage: L = r.cholesky_decomposition(); L<br />

[ 1.0 0.0]<br />

[ 2.0*I 1.41421356237]<br />

sage: ( r - L*L.conjugate().transpose() ).norm(1) < 1e-30<br />

True<br />

sage: L.parent()<br />

Full MatrixSpace <strong>of</strong> 2 by 2 dense matrices over Complex Double Field<br />

TESTS:<br />

The following examples are not positive definite:<br />

sage: m = -identity_matrix(3).change_ring(RDF)<br />

sage: m.cholesky_decomposition()<br />

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

...<br />

ValueError: The input matrix was not symmetric <strong>and</strong> positive definite<br />

sage: m = -identity_matrix(2).change_ring(RealField(100))<br />

sage: m.cholesky_decomposition()<br />

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

...<br />

ValueError: The input matrix was not symmetric <strong>and</strong> positive definite<br />

Here is a large example over a higher precision complex field:<br />

[12.1121838768, 5.17714373118, 0.183583821657, 0.798520682956, 2.03399202232, 3.81092266261]<br />

sage: r = MatrixSpace(ComplexField(100), 6, 6).r<strong>and</strong>om_element()<br />

sage: m = r * r.conjugate().transpose()<br />

sage: m.change_ring(CDF) # for display purposes<br />

[ 4.03491289478 1.65865229397 + 1.20395241554*I -0.275377464753 - 0.3<br />

[ 1.65865229397 - 1.20395241554*I 5.19463366777 0.192784646673 + 0.2<br />

[-0.275377464753 + 0.392579363912*I 0.192784646673 - 0.217539084881*I<br />

[ 0.646019176609 + 1.80427378747*I -1.24630239913 + 1.00510523556*I -0.550558880479 - 0.3<br />

[ 1.15898675468 - 2.35202344518*I 1.65179716714 - 1.27031304403*I 1.00862850855 - 0.9<br />

[ -1.07920143474 - 1.37815737417*I 1.17275462994 - 0.565615358757*I -0.740344951784 + 0.<br />

sage: eigs = m.change_ring(CDF).eigenvalues() # again for display purposes<br />

sage: all(abs(imag(e)) < 1.3e-15 for e in eigs)<br />

True<br />

sage: [real(e) for e in eigs]<br />

sage: ( m - m.conjugate().transpose() ).norm(1) < 1e-50<br />

True<br />

sage: L = m.cholesky_decomposition(); L.change_ring(CDF)<br />

[ 2.00870926089 0.0<br />

[ 0.825730396261 - 0.599366189511*I 2.03802923221<br />

[ -0.137091748475 + 0.195438618996*I 0.20761467212 - 0.145606613292*I<br />

[ 0.321609099528 + 0.898225453828*I -0.477666770113 + 0.0346666053769*I -0.416429223553 -<br />

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