Activity 4.2.5
We will use Sage to find the eigenvalues and eigenvectors of a matrix. Let's begin with the matrix \(A = \left[\begin{array}{rr} 1 \amp 2 \\ 2 \amp 1 \\ \end{array}\right] \text{.}\)

We can find the characteristic polynomial of a matrix \(A\) by writing
A.charpoly('lam')
. Notice that we have to give Sage a variable in which to write the polynomial; here, we uselam
though you could just as well usex
.The factored form of the characteristic polynomial may be more useful since it will tell us the eigenvalues and their multiplicities. The factor chacteristic polynomial is found with
A.fcp('lam')
. 
If we only want the eigenvalues, we can use
A.eigenvalues()
.Notice that the multiplicity of an eigenvalue is the number of times it is repeated in the list of eigenvalues.

Finally, we can find eigenvectors by
A.eigenvectors_right()
. (We are looking for right eigenvalues since the vector \(\vvec\) appears to the right of \(A\) in the definition \(A\vvec=\lambda \vvec\text{.}\))At first glance, the result of this command can be a little confusing to interpret. What we see is a list with one entry for each eigenvalue. For each eigenvalue, there is a triple consisting of (i) the eigenvalue \(\lambda\text{,}\) (ii) a basis for \(E_\lambda\text{,}\) and (iii) the multiplicity of \(\lambda\text{.}\)

When working with decimal entries, which are called floating point numbers in computer science, we must remember that computers perform only approximate arithmetic. This is a problem when we wish to find the eigenvectors of such a matrix. To illustrate, consider the matrix \(A=\left[\begin{array}{rr} 0.4 \amp 0.3 \\ 0.6 \amp 0.7 \\ \end{array}\right] \text{.}\)
Without using Sage, find the eigenvalues of this matrix.
What do you find for the reduced row echelon form of \(AI\text{?}\)

Let's now use Sage to determine the reduced row echelon form of \(AI\text{:}\)
What result does Sage report for the reduced row echelon form? Why is this result not correct?

Because the arithmetic Sage performs with floating point entries is only approximate, we are not able to find the eigenspace \(E_1\text{.}\) In this next chapter, we will learn how to address this issue. In the meantime, we can get around this problem by writing the entries in the matrix as rational numbers: