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: abs(abs(delta)).n() < 1e-10<br />

True<br />

sage: A = matrix(SR, 2, 2, var(’a,b,c,d’))<br />

sage: A.eigenvectors_left()<br />

[(1/2*a + 1/2*d - 1/2*sqrt(a^2 + 4*b*c - 2*a*d + d^2), [(1, -1/2*(a - d + sqrt(a^2 + 4*b*c -<br />

sage: es = A.eigenvectors_left(); es<br />

[(1/2*a + 1/2*d - 1/2*sqrt(a^2 + 4*b*c - 2*a*d + d^2), [(1, -1/2*(a - d + sqrt(a^2 + 4*b*c -<br />

sage: eval, [evec], mult = es[0]<br />

sage: delta = eval*evec - evec*A<br />

sage: delta.apply_map(lambda x: x.full_simplify())<br />

(0, 0)<br />

This routine calls Maxima <strong>and</strong> can struggle with even small matrices with a few variables, such as a 3 × 3<br />

matrix with three variables. However, if the entries are integers or rationals it can produce exact values in a<br />

reasonable time. These examples create 0-1 matrices from the adjacency matrices <strong>of</strong> graphs <strong>and</strong> illustrate<br />

how the format <strong>and</strong> type <strong>of</strong> the results differ when the base ring changes. First for matrices over the rational<br />

numbers, then the same matrix but viewed as a symbolic matrix.<br />

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

sage: am = G.adjacency_matrix()<br />

sage: spectrum = am.eigenvectors_left()<br />

sage: qqbar_evalue = spectrum[2][0]<br />

sage: type(qqbar_evalue)<br />

<br />

sage: qqbar_evalue<br />

0.618033988749895<br />

sage: am = G.adjacency_matrix().change_ring(SR)<br />

sage: spectrum = am.eigenvectors_left()<br />

sage: symbolic_evalue = spectrum[2][0]<br />

sage: type(symbolic_evalue)<br />

<br />

sage: symbolic_evalue<br />

1/2*sqrt(5) - 1/2<br />

sage: qqbar_evalue == symbolic_evalue<br />

True<br />

A slightly larger matrix with a “nice” spectrum.<br />

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

sage: am = G.adjacency_matrix().change_ring(SR)<br />

sage: am.eigenvectors_left()<br />

[(-1, [(1, 0, -1, 1, 0, -1), (0, 1, -1, 0, 1, -1)], 2), (1, [(1, 0, -1, -1, 0, 1), (0, 1, 1,<br />

eigenvectors_right()<br />

Compute the right eigenvectors <strong>of</strong> a matrix.<br />

For each distinct eigenvalue, returns a list <strong>of</strong> the form (e,V,n) where e is the eigenvalue, V is a list <strong>of</strong><br />

eigenvectors forming a basis for the corresponding right eigenspace, <strong>and</strong> n is the algebraic multiplicity <strong>of</strong><br />

the eigenvalue.<br />

EXAMPLES:<br />

sage: A = matrix(SR,2,2,range(4)); A<br />

[0 1]<br />

[2 3]<br />

sage: right = A.eigenvectors_right(); right<br />

[(-1/2*sqrt(17) + 3/2, [(1, -1/2*sqrt(17) + 3/2)], 1), (1/2*sqrt(17) + 3/2, [(1, 1/2*sqrt(17<br />

307

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

Saved successfully!

Ooh no, something went wrong!