Section 11.2 Eigenvalues
This section demonstrates how to use Sage to compute eigenvalues. First, we will show how Sage can assist with the calculations at each step of the eignevalue computation process. Then, we will show how to use Sageβs direct methods to obtain eigenvalues.
Subsection 11.2.1 Assisted Calculation of Eigenvalues
Since the equation \(Av = \lambda v \) is equivalent to \((A - \lambda I)v = 0 \) , the eigenvalues of \(A\) are precisely the scalars \(\lambda\) for which this equation has nontrivial solutions. The determinant of the coefficient matrix of this homogeneous system must be zero. Therefore, we require \(\det(A - \lambda I) = 0 \text{.}\)
The nth-degree polynomial \(\det(A - \lambda I)\) is called the characteristic polynomial of \(A\text{.}\) The eigenvalues of \(A\) are the solutions of the characteristic equation:
\begin{gather*}
\det(A - \lambda I) = 0.
\end{gather*}
Letβs start by solving this equation manually, to calculate the eigenvalues. First, we enter our matrix \(A\text{:}\)
We declare \(\lambda\) as a variable.
We then construct the matrix \(B = A - \lambda I\text{.}\)
Next, we define the characteristic equation \(\det(B) = 0\text{.}\)
Finally, we solve the characteristic equation.
Sage returns the solution of the equation, which are the eigenvalues of \(A\text{.}\) By using the
lhs() method, we obtain the left-hand side part of the equation, namely, the characteristic polynomial.
Now we factor the characteristic polynomial, so that we can identify each eigenvalue and determine how many times it appears as a root. The number of times an eigenvalue occurs as a root of the characteristic polynomial is called its algebraic multiplicity.
The exponents in the factorization indicate the algebraic multiplicity of each eigenvalue. The
factor_list method returns a list of tuples of the form \(\big(f(x), r\big)\text{,}\) where \(f(x)\) is the factor and \(r\) is the algebraic multiplicity of that factor.
Subsection 11.2.2 Sage Calculation of Eigenvalues
Sage provides the
eigenvalues() method to compute the eigenvalues directly and return them as a list.
Observe that the eigenvalues are returned in a list, and each eigenvalue is repeated according to its algebraic multiplicity. We can access each eigenvalue by indexing the list.
Sage also provides a direct method to compute the multiplicities of the eigenvalues.
Sage also provides a direct method to compute the multiplicities of the eigenvalues.
Observe that we obtained the same eigenvalues as before, each repeated according to its algebraic multiplicity.
To directly calculate the characteristic polynomial, Sage provides the
characteristic_polynomial() method. Note that this method computes the polynomial
\begin{gather*}
p = \det(\lambda I - A),
\end{gather*}
which may differ from our definition of the characteristic polynomial by a sign, depending on the dimension \(n\) of the matrix. Indeed,
\begin{gather*}
\det(\lambda I - A) = (-1)^n \det(A - \lambda I).
\end{gather*}
To compute the polynomial \(p\text{,}\) we can use the
characteristic_polynomial() or charpoly() methods. Using either method will yield the same result.
We can check now that the characteristic polynomial cpoly we computed by hand before, coincides with this polynomial \(p\) returned by the
characteristic_polynomial() method multiplied by \((-1)^n\text{.}\)
Note that if we want to test whether the symbolic expression \(q\) is equal to the symbolic expression \(r\text{,}\) we need to type
bool(q == r).
