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: eigenvalues = [T[i,i] for i in range(4)]; eigenvalues<br />

[30.733... + 4648.541...*I, -0.184... - 159.057...*I, -0.523... + 11.158...*I, -0.025... - 0<br />

sage: A.eigenvalues()<br />

[30.733... + 4648.541...*I, -0.184... - 159.057...*I, -0.523... + 11.158...*I, -0.025... - 0<br />

sage: abs(A.norm()-T.norm()) < 1e-10<br />

True<br />

We begin with a real matrix but ask for a decomposition over the complexes. The result will yield an<br />

upper-triangular matrix over the complex numbers for T.<br />

sage: A = matrix(RDF, 4, 4, [x^3 for x in range(16)])<br />

sage: Q, T = A.schur(base_ring=CDF)<br />

sage: (Q*Q.conjugate().transpose()).zero_at(1.0e-12)<br />

[1.0 0.0 0.0 0.0]<br />

[0.0 1.0 0.0 0.0]<br />

[0.0 0.0 1.0 0.0]<br />

[0.0 0.0 0.0 1.0]<br />

sage: T.parent()<br />

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

sage: all([T.zero_at(1.0e-12)[i,j] == 0 for i in range(4) for j in range(i)])<br />

True<br />

sage: (Q*T*Q.conjugate().transpose()-A).zero_at(1.0e-11)<br />

[0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0]<br />

Now totally over the reals. But with complex eigenvalues, the similar matrix may not be upper-triangular.<br />

But “at worst” there may be some 2×2 blocks on the diagonal which represent a pair <strong>of</strong> conjugate complex<br />

eigenvalues. These blocks will then just interrupt the zeros below the main diagonal. This example has a<br />

pair <strong>of</strong> these <strong>of</strong> the blocks.<br />

sage: A = matrix(RDF, 4, 4, [[1, 0, -3, -1],<br />

... [4, -16, -7, 0],<br />

... [1, 21, 1, -2],<br />

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

sage: Q, T = A.schur()<br />

sage: (Q*Q.conjugate().transpose()).zero_at(1.0e-12)<br />

[1.0 0.0 0.0 0.0]<br />

[0.0 1.0 0.0 0.0]<br />

[0.0 0.0 1.0 0.0]<br />

[0.0 0.0 0.0 1.0]<br />

sage: all([T.zero_at(1.0e-12)[i,j] == 0 for i in range(4) for j in range(i)])<br />

False<br />

sage: all([T.zero_at(1.0e-12)[i,j] == 0 for i in range(4) for j in range(i-1)])<br />

True<br />

sage: (Q*T*Q.conjugate().transpose()-A).zero_at(1.0e-11)<br />

[0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0]<br />

sage: sorted(T[0:2,0:2].eigenvalues() + T[2:4,2:4].eigenvalues())<br />

[-5.710... - 8.382...*I, -5.710... + 8.382...*I, -0.789... - 2.336...*I, -0.789... + 2.336..<br />

sage: sorted(A.eigenvalues())<br />

[-5.710... - 8.382...*I, -5.710... + 8.382...*I, -0.789... - 2.336...*I, -0.789... + 2.336..<br />

sage: abs(A.norm()-T.norm()) < 1e-12<br />

True<br />

Starting with complex numbers <strong>and</strong> requesting a result over the reals will never happen.<br />

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