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

More precisely, for an n × n matrix, the diameter <strong>of</strong> the interval containing similar eigenvalues could be<br />

as large as sum <strong>of</strong> the reciprocals <strong>of</strong> the first n integers times tol.<br />

Warning: Use caution when using the tol parameter to group eigenvalues. See the examples below<br />

to see how this can go wrong.<br />

EXAMPLES:<br />

sage: m = matrix(RDF, 2, 2, [1,2,3,4])<br />

sage: ev = m.eigenvalues(); ev<br />

[-0.372281323..., 5.37228132...]<br />

sage: ev[0].parent()<br />

Complex Double Field<br />

sage: m = matrix(RDF, 2, 2, [0,1,-1,0])<br />

sage: m.eigenvalues(algorithm=’default’)<br />

[1.0*I, -1.0*I]<br />

sage: m = matrix(CDF, 2, 2, [I,1,-I,0])<br />

sage: m.eigenvalues()<br />

[-0.624810533... + 1.30024259...*I, 0.624810533... - 0.30024259...*I]<br />

The adjacency matrix <strong>of</strong> a graph will be symmetric, <strong>and</strong> the eigenvalues will be real.<br />

sage: A = graphs.PetersenGraph().adjacency_matrix()<br />

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

sage: ev = A.eigenvalues(algorithm=’symmetric’); ev<br />

[-2.0, -2.0, -2.0, -2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 3.0]<br />

sage: ev[0].parent()<br />

Real Double Field<br />

The matrix A is “r<strong>and</strong>om”, but the construction <strong>of</strong> B provides a positive-definite Hermitian matrix. Note<br />

that the eigenvalues <strong>of</strong> a Hermitian matrix are real, <strong>and</strong> the eigenvalues <strong>of</strong> a positive-definite matrix will<br />

be positive.<br />

sage: A = matrix([[ 4*I + 5, 8*I + 1, 7*I + 5, 3*I + 5],<br />

... [ 7*I - 2, -4*I + 7, -2*I + 4, 8*I + 8],<br />

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

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

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

sage: ev = B.eigenvalues(algorithm=’hermitian’); ev<br />

[2.68144025..., 49.5167998..., 274.086188..., 390.71557...]<br />

sage: ev[0].parent()<br />

Real Double Field<br />

A tolerance can be given to aid in grouping eigenvalues that are similar numerically. However, if the<br />

parameter is too small it might split too finely. Too large, <strong>and</strong> it can go wrong very badly. Use with care.<br />

sage: G = graphs.PetersenGraph()<br />

sage: G.spectrum()<br />

[3, 1, 1, 1, 1, 1, -2, -2, -2, -2]<br />

sage: A = G.adjacency_matrix().change_ring(RDF)<br />

sage: A.eigenvalues(algorithm=’symmetric’, tol=1.0e-5)<br />

[(-2.0, 4), (1.0, 5), (3.0, 1)]<br />

sage: A.eigenvalues(algorithm=’symmetric’, tol=2.5)<br />

[(-2.0, 4), (1.33333333333, 6)]<br />

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