Lesson 11 of 18
Eigenvalues & Eigenvectors
Eigenvalues and Eigenvectors
An eigenvector of a matrix is a vector that only gets scaled (not rotated) when multiplied by :
The scalar (lambda) is the eigenvalue — it tells you how much the eigenvector is stretched.
The Characteristic Equation
Eigenvalues satisfy . For a matrix this yields:
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 matrix sorted in ascending order, as a list of integers.
Pyodide loading...
Loading...
Click "Run" to execute your code.