In this example we will find the eigenvalues and a corresponding eigenvector for each eigenvalue for the matrix

A=(75108)

First we introducte the matrix and we store it in the variable A

A = matrix([[ 7, -5], \
            [10, -8]])

Eigenvalues

To find the eigenvalues we will calulate

AλI.

However, in SageMath (as well as in Python), lambda is a reserved word. So we will use the letter l instead. We store the matrix into the variable AmlI:

l = var('l', latex_name=r'\lambda')
AmlI = A - l*identity_matrix(2)

Here, we have used the function identity_matrix with argument 2 to create the corresponding identity matrix.

To find the eigenvalues we need to calculate the determinant of AλI, which gives us the characteristic equation. We achieve that with the function determinant from the matrix class. We will create the characteristic equation p(λ).

p(l) = AmlI.determinant()

We can check the equation by using the function show.

show(p(l).expand())

The output is

λ2+λ6

Finding the zeros of this equation will give us the eigenvalues.

In our case:

  • λ=2 is a zero since p(2)=0.
  • λ=3 is a zero since p(3)=0.

The eigenvalues are λ=2, λ=3.

Eigenvectors

To find the eigenvectors, we need to solve the system

(AλI)(xy)=(00)

Let’s do it!

Eigenvector with associated eigenvalue λ=2.

We substitue λ=2 into AλI and we will store the result into the variable L1:

L1 = AmlI(l=2)

Now we multiply the matrix by the column vector (xy). To do that, we need to create the variable y

NOTE: Although we call it “column vector”, it should be a matrix in SageMath.

y = var('y')
L1xy = L1*matrix([[x],[y]])

If we use the function show, we can visualize the matrix L1xy:

(5x5y10x10y)

Now we can see that one equation is a multiple of the other. Therefore, we could choose, for example, the first equation

5x5y=0

And we obtain the line y=x. Now, subsituting y=x into the vector (xy) we have

(xy)=(xx)=x(11)

And we can choose v1=(11) as an eigenvector.

Eigenvector with associated eigenvalue λ=3.

We repeat the same procedure above.

We substitue λ=3 into AλI and we will store the result into the variable L2:

L2 = AmlI(l=-3)

Now we multiply the matrix by the column vector (xy). To do that, we need to create the variable y

y = var('y')
L2xy = L2*matrix([[x],[y]])

If we use the function show, we can visualize the matrix L2xy:

(10x5y10x5y)

Now we can see that one equation is a multiple of the other. Therefore, we could choose, for example, the first equation

10x5y=0

And we obtain the line y=2x. Now, subsituting y=2x into the vector (xy) we have

(xy)=(x2x)=x(12)

And we can choose v2=(12) as an eigenvector.