290 DEMO EE

Prof. Robert Beezer
Copyright 2012 All Rights Reserved

October 2, 2012
{{{ }}}

EE - Eigenvalues and Eigenvectors

0.0.1 Eigenvalues and Eigenvectors

A $6 × 6$ matrix with nice eigenvalues.

{{{ entries = [[-31, -23, -16, 12, 120, -17], [-3, 7, 0, -12, 60, -21], [-28, -14, -9, -4, 152, -30], [-36, -20, -16, -1, 192, -32], [-9, -5, -4, 0, 47, -8], [-1, 1, 0, -4, 20, -3]] A = matrix(QQ, entries) A }}} {{{ p = A.characteristic_polynomial() p }}} {{{ p.factor() }}}

Eigenvalues are the roots of the characteristic polynomial (Theorem EMRCP), which should be obvious from the factored version, including their (algebraic) multiplicities. Of course, it can be very easy to get these in Sage.

{{{ A.eigenvalues() }}}

We can create the singular matrices $A − λ{I}_{6}$ for each eigenvalue (we will do two). Row-reducing these matrices will exhibit their nonzero nullity.

{{{ (A-4*identity_matrix(6)).rref() }}} {{{ (A-3*identity_matrix(6)).rref() }}}

We now examine the eigenspace for the eigenvalue $λ = 3$, using Sage’s right kernel command and the pivot basis.

{{{ E6 = (A-3*identity_matrix(6)).right_kernel(basis='pivot') E6 }}}

A basis for the eigenspace will allow us to create eigenvectors of A for the eigenvalue $λ = 3$ at will.

{{{ B = E6.basis() B }}}

An arbitrary eigenvector:

{{{ v = 6*B[0] + (-3)*B[1] v }}}

We can check this. Compare $Av$ with $3v$.

{{{ A*v }}} {{{ 3*v }}}

Here’s an easy check:

{{{ A*v - 3*v }}}

Can you make more eigenvectors?

Eigenspaces, Eigenmatrices

Continuing with A from above, we can get eigen-stuff quickly from Sage, once we understand what is really happening (according to the definitions).

As always we want the “right” versions of the relevant commands. Eigenspaces are in the second parts of pairs, where the first part of each pair is the eigenvalue. Notice that they are vector spaces (with bases, etc).

{{{ A.eigenspaces_right() }}}

The eigenmatrix commands return pair of matrices. The first is a diagonal matrix with the eigenvalues on the diagonal. The second is a square matrix with linearly independent eigenvectors in the columns, and the order of the eigenvectors is the same as the order of the eigenvalues. That is, the eigenvector in column i of the second matrix is a basis vector for the eigenspace of the eigenvalue in column i of the first matrix.

{{{ A.eigenmatrix_right() }}}

Sometimes the dimension of an eigenspace (the geometric multiplicity) is strictly less than the number of times the eigenvalue appears as a root of the characteristic polynomial. This is the case with C next, but was not the case with A above.

{{{ entries = [[128, 20, 44, -50, 236, -18, -330, -565], [-23, -16, -5, 6, -40, 27, 62, 128], [-44, -12, -15, 16, -78, 20, 110, 207], [-2, 10, -4, 3, -10, -23, 20, -9], [-61, 5, -25, 27, -116, -26, 153, 225], [-12, -12, -1, 2, -20, 24, 34, 82], [-23, -3, -8, 9, -42, 2, 57, 99], [13, 6, 3, -4, 23, -12, -35, -72]] C = matrix(QQ, entries) C }}} {{{ C.eigenmatrix_right() }}}

Fancy Footwork

A totally random matrix is unlikely to have a characteristic polynomial that factors if we restict ourseves to the rationals. But we can find all the roots over $\overline{Q}$, the set of all algebraic numbers.

{{{ D = random_matrix(QQ, 10) D }}} {{{ p = D.characteristic_polynomial() p.factor() }}} {{{ p.roots(ring=QQbar, multiplicities=False) }}}

If we make a “block diagonal” matrix, then the characteristic polynomial will definitely factor some

{{{ E = block_diagonal_matrix( [random_matrix(QQ, 5), random_matrix(QQ, 5)]) E }}}

.fcp() is Sage shorthand for the “factored characteristic polynomial.”

{{{ E.fcp() }}}

Finally a large example, illustrating how fast Sage is at making characteristic polynomials and at factoring.

{{{ F = block_diagonal_matrix( [random_matrix(QQ, 50), random_matrix(QQ, 50)]) F.fcp() }}}

Numerical Matrices

If we use CDF (Complex Double Field) for the number system of the entries of our matrix, we get (good) approximate values for eigenvalues. (If we are OK with the approximate nature, these routines are very, very fast.)

{{{ G = random_matrix(QQ, 300) H = G.change_ring(CDF) H.eigenvalues() }}} {{{ }}}