Skip to main content

Section 5.4 Eigenvalues and Eigenvectors in Sage

In this section, we shall explore computation of eigenvalues and eigenvectors and related concepts in Sage. We shall also look applications of diagonalization in Sage.
Sage can compute eigenvalues and eigenvectors of a matrix and also of linear operator. If \(A\) is a square marix, then A.eignvalues() returns eigenvalues of the matrix \(A\text{.}\) Simplarly, A.eigenvectors_right() returns the eigenvectors along with the corresponding eigenvalue including the multiplicity of each eigenvalue. Apart from these two coammands, Sage also has A.eigenmatrix_right() which returns diagonal matrix of eigenvalues and the matrix whose columns of eigenvectors. Let us explore some example.

Example 5.4.1.

Find the eigenvalues of eigenvectors of \(A = \begin{pmatrix}1 \amp 1 \amp 1\\ 1 \amp 1 \amp 1\\1 \amp 1 \amp 1 \end{pmatrix}\text{.}\)
Solution.
Sage can also compute eigenvalues and eigenvectors of a symbolic matrix. Let us look at the next example.

Example 5.4.2.

Sage can also find the characteristic polynomial of matrix with ease using two matrix method A.charpoly() and A.characteristic_polynomial() Let us look at the next example.

Example 5.4.3.

Find the characteristics polynomial of the matrix
We can factorize the characteristic polynomial to find its roots.
Sage can find eigenvalues and eigenvalues of bigsize matriz also. However, the computation is done numerically. Let us look at the next example.

Example 5.4.4.

Consider the matrix \(A=\left(\begin{array}{rrrrr} 412 \amp -479 \amp 251 \amp -7 \amp 381 \\ -479 \amp 867 \amp -373 \amp -10 \amp -435 \\ 251 \amp -373 \amp 217 \amp -24 \amp 176 \\ -7 \amp -10 \amp -24 \amp 20 \amp 18 \\ 381 \amp -435 \amp 176 \amp 18 \amp 450 \end{array}\right)\text{.}\) Find the characteristics polynomial, eigenvalues and eigenvectors of \(A\text{.}\)
Now let us try to factorize the characteristic polynomial of \(A\text{.}\)
Clearly this polynomial cannot be factorized in the field of rational numbers. However, Sage provide an extended field QQbar in whihc we can find the rots of this polynomial.
These are the eigenvalues that sage can find using A.eigenvalues()
For this example, let us also verify that (i) the sum of eigenvalues equals to the trace and (ii) the product of eigenvalues equals to the determinant.
We can also verify the Cayley-Hamilton thorem for the above matrix.

Activity 5.4.1.

Consider the matrix \(A=\left(\begin{array}{rrrrrr} -24 \amp 6 \amp 0 \amp -1 \amp 31 \amp 7 \\ -9 \amp -2 \amp -8 \amp -17 \amp 24 \amp -29 \\ 4 \amp -10 \amp 1 \amp 1 \amp -12 \amp -36 \\ -19 \amp 11 \amp -1 \amp -4 \amp 33 \amp 29 \\ -11 \amp 6 \amp 2 \amp 3 \amp 14 \amp 21 \\ 5 \amp -1 \amp 2 \amp 5 \amp -11 \amp 4 \end{array}\right)\text{.}\) Find the eigenvalues of \(A\) and verify the Cayley-Hamilton theorem. Also find the sum and product of eigenvalues of \(A\) and observe that they are the trace and determinant of \(A\) respectively.

Example 5.4.5. Eigenspaces.

Consider a matrix \(A=\left(\begin{array}{rrrrr} -19 \amp 6 \amp 42 \amp -6 \amp 60 \\ -3 \amp -13 \amp 6 \amp 15 \amp 72 \\ -9 \amp 9 \amp 20 \amp -9 \amp 0 \\ -3 \amp 0 \amp 6 \amp 2 \amp 12 \\ 0 \amp -3 \amp 0 \amp 3 \amp 14 \end{array}\right)\text{.}\) Find the eigenvalues and eigenvectors of \(A\text{.}\) Also find the eigenspace corresponding to each eigenvalues. Check if the the given matrix is diagonalizable.
Solution.
This returns the eigenvalues are the corresponding eigenspace of each eigenvalue.
Note that the eigenspace corresponding to the eigenvalue \(\lambda\) is the \(\text{kerne}(A-\lambda I)\) and the gemetric multiplicity is the nullity of \((A-\lambda I)\text{.}\)
To find the eigenspace with respect to the eigenvalue \(\lambda\) can be obtained by appplying RREF to the matrix \((A-\lambda I)\) and solving the corresponding system of equations.
Now we can solve the system of equations, \(x_1-2x_3-4x_5=0, x_2-x_4-4x_5=0\) to obtaine the eigenspace.
Similarly, we can find the eigenspace with respect to the eigenvalue \(\lambda=-1\)

Example 5.4.6. Diagonalizability.

Consider the same matrix \(A=\left(\begin{array}{rrrrr} -19 \amp 6 \amp 42 \amp -6 \amp 60 \\ -3 \amp -13 \amp 6 \amp 15 \amp 72 \\ -9 \amp 9 \amp 20 \amp -9 \amp 0 \\ -3 \amp 0 \amp 6 \amp 2 \amp 12 \\ 0 \amp -3 \amp 0 \amp 3 \amp 14 \end{array}\right)\text{.}\) We shall check the diagonalizability of \(A\text{.}\)
Solution.
Clearly \(A\) is diagonalizable. We can also find the matrix \(P\) of eigenvectors and check if \(P^{-1}AP\) is the diagonal matrix whose diagonal entries are eigenvalues.

Example 5.4.7. Eigenvalues of a linear operator.

ConsiderΒ  the linear tranformation \(T\colon \mathbb{R}^3\to \mathbb{R}^3\) defined by
\begin{equation*} T(x,y,z)=(3x+2z,3y-2z, 2x-2y+z) \end{equation*}
Let us find the eigenvalues of \(T\) and also show that the eigenvalues are independent of the basis on the domain
We can also find the characteristics polynomial of \(T\text{.}\)
Let us find the matrix \(A\) of \(T\) with respect to the standard basis of \(\mathbb{R}^3\) and find find the eigenvalues of \(A\text{.}\)
Now let us find the matrix \(B\) of \(T\) with respect to a basis \(\beta=\{(1,1,0),(-1,1,1),(0,-1,1)\}\) and find eigenvalues of \(B\text{.}\)
Clearly eigenvalues of \(T\text{,}\) \(A\) and \(B\) are same. This is not suprizing as \(A\) and \(B\) are similar matrices and similar matrices have the same determinant and eigenvalues.