Lesson 11 of 18

Eigenvalues & Eigenvectors

Eigenvalues and Eigenvectors

An eigenvector mathbfvmathbf{v} of a matrix mathbfAmathbf{A} is a vector that only gets scaled (not rotated) when multiplied by mathbfAmathbf{A}:

mathbfAcdotmathbfv=lambdacdotmathbfvmathbf{A} cdot mathbf{v} = lambda cdot mathbf{v}

The scalar lambdalambda (lambda) is the eigenvalue — it tells you how much the eigenvector is stretched.

The Characteristic Equation

Eigenvalues satisfy det(mathbfAlambdaI)=0det(mathbf{A} - lambda I) = 0. For a 2imes22 imes 2 matrix this yields:

lambda2exttrace(mathbfA)cdotlambda+det(mathbfA)=0lambda^2 - ext{trace}(mathbf{A}) cdot lambda + det(mathbf{A}) = 0

Using the quadratic formula:

import math

def eigenvalues_2x2(A):
    tr = A[0][0] + A[1][1]          # trace
    d = A[0][0]*A[1][1] - A[0][1]*A[1][0]   # determinant
    disc = tr**2 - 4*d
    l1 = (tr - math.sqrt(disc)) / 2
    l2 = (tr + math.sqrt(disc)) / 2
    return sorted([int(round(l1)), int(round(l2))])

A = [[3, 0], [0, 5]]
print(eigenvalues_2x2(A))   # [3, 5]

Diagonal Matrices

For diagonal matrices, the eigenvalues are just the diagonal entries.

Why Eigenvalues Matter

  • PCA (Principal Component Analysis) — eigenvectors of the covariance matrix give the principal components; eigenvalues give the variance explained
  • Google PageRank — the web's link structure is a matrix; the PageRank vector is its dominant eigenvector
  • Stability analysis — eigenvalues determine whether a dynamical system converges or diverges

Your Task

Implement sorted_eigenvalues(A) that returns the eigenvalues of a 2imes22 imes 2 matrix mathbfAmathbf{A} sorted in ascending order, as a list of integers.

Pyodide loading...
Loading...
Click "Run" to execute your code.