Eigenvalues
18 min
For a square matrix A, an eigenvector is a (nonzero) vector v
that A only stretches or shrinks — never rotates:
A @ v = λ * v
λ (lambda) is the corresponding eigenvalue — how much v gets
scaled. Most vectors DO get rotated when you multiply them by a matrix;
eigenvectors are the special directions that don't. They show up
everywhere: PCA (dimensionality reduction) finds the eigenvectors of a
covariance matrix, Google's original PageRank is an eigenvector
computation, and a matrix's eigenvalues tell you a huge amount about its
behavior (stability, whether it's invertible, how a system evolves over
time) without needing to solve anything iteratively.
The determinant of a 2x2 matrix — a single number that shows up directly in the eigenvalue formula below, and separately tells you whether the matrix is invertible (invertible exactly when determinant != 0).
For a 2×2 matrix, there's a direct formula — no need to solve anything
iteratively. Let trace = a + d (the sum of the diagonal) and
det = a*d - b*c (the determinant). Then:
λ = (trace ± √(trace² - 4·det)) / 2
This comes from solving the matrix's characteristic equation,
det(A - λI) = 0 — for a 2×2 matrix, that expands into a quadratic in
λ, and the formula above is just the quadratic formula applied to it.
Larger matrices don't have a clean closed-form formula like this one
(that's why NumPy's np.linalg.eig uses iterative numerical methods
instead) — the 2×2 case is the one place you can compute eigenvalues
entirely by hand.
Write `determinant_2x2(m)`, returning the determinant of a 2×2 matrix `m` (given as `[[a, b], [c, d]]`): `a*d - b*c`.
Write `eigenvalues_2x2(m)`, returning the two eigenvalues of a 2×2 matrix `m` as a sorted list `[smaller, larger]`, using the trace/determinant formula. Assume the eigenvalues are always real (the discriminant is never negative).
For a 2×2 matrix, which two properties determine its eigenvalues via the characteristic equation?
You know what an eigenvalue/eigenvector represents geometrically, and can compute both eigenvalues of a 2x2 matrix directly from its trace and determinant.