Sage CEVAL Computing Eigenvalues

We can now give a more careful explantion about eigenvalues in Sage. Sage will compute the characteristic polynomial of a matrix, with amazing ease (in other words, quite quickly, even for large matrices). The two matrix methods .charpoly() and .characteristic_polynomial() do exactly the same thing. We will use the longer name just to be more readable, you may prefer the shorter.

We now can appreciate a very fundamental obstacle to determining the eigenvalues of a matrix, which is a theme that will run through any advanced study of linear algebra. Study this example carefully before reading the discussion that follows.









We know by Theorem EMRCP that to compute eigenvalues, we need the roots of the characteristic polynomial, and from basic algebra, we know these correspond to linear factors. However, with our matrix defined with entries from QQ, the factorization of the characteristic polynomial does not “leave” that number system, only factoring “far enough” to retain factors with rational coefficients. The solutions to $x^2 - 2 = 0$ are somewhat obvious ($\pm\sqrt{2}\approx\pm 1.414213$), but the roots of the cubic factor are more obscure.

But then we have QQbar to the rescue. Since this number system contains the roots of every possible polynomial with integer coefficients, we can totally factor any characteristic polynomial that results from a matrix with entries from QQbar. A common situation will be to begin with a matrix having rational entries, yet the matrix has a characteristic polynomial with roots that are complex numbers.

We can demonstrate this behavior with the extend keyword option, which tells Sage whether or not to expand the number system to contain the eigenvalues.





For matrices with entries from QQ, the default behavior is to extend to QQbar when necessary. But for other number systems, you may need to explicitly use the extend=True option.

From a factorization of the characteristic polynomial, we can see the algebraic multiplicity of each eigenvalue as the second entry of the each pair returned in the list. We demonstrate with Example SEE, extending to QQbar, which is not strictly necessary for this simple matrix.



One more example, which illustrates the behavior when we use floating-point approximations as entries (in other words, we use CDF as our number system). This is Example EMMS4, both as an exact matrix with entries from QQbar and as an approximate matrix with entries from CDF.





So, we see $\lambda=2$ as an eigenvalue with algebraic multiplicity 3, while the numerical results contain three complex numbers, each very, very close to 2. The approximate nature of these eigenvalues may be disturbing (or alarming). However, their computation, as floating-point numbers, can be incredibly fast with sophisticated algorithms allowing the analysis of huge matrices with millions of entries. And perhaps your original matrix includes data from an experiment, and is not even exact in the first place. Designing and analyzing algorithms to perform these computations quickly and accurately is part of the field known as numerical linear algebra.

One cautionary note: Sage uses a definition of the characteristic polynomial slightly different than ours, namely $\detname{xI_n-A}$. This has the advantage that the $x^n$ term always has a positive one as the leading coefficient. For even values of $n$ the two definitions create the identical polynomial, and for odd values of $n$, the two polynomials differ only by a multiple of $-1$. The reason this is not very critical is that Theorem EMRCP is true in either case, and this is a principal use of the characteristic polynomial. Our definition is more amenable to computations by hand.