21.3 Eigendecompositions

In Section 21.2 we asked what a matrix does to space when it is applied once. Many computations in machine learning, however, apply the same matrix over and over. A deep linear network with identical layers computes A50x\mathbf A^{50}\mathbf x after 50 layers, and gradient descent on a quadratic objective multiplies its error by the same fixed matrix at every step. In each case we want to know whether the signal grows, dies out, or settles down, and how quickly that happens. Multiplying out the matrix powers gives us the numbers, but it does not explain them.

A random walk between two web pages is the smallest version of this question. Suppose a surfer on page 1 stays on page 1 or clicks to page 2 with probability 1/21/2 each; from page 2 she stays with probability 3/43/4 and returns to page 1 with probability 1/41/4. Let pk\mathbf p_k hold the probabilities of being on each page after kk clicks. Each click multiplies this vector by a fixed matrix,

pk+1=Ppk,P=(1/21/41/23/4),\mathbf p_{k+1}=\mathbf P\mathbf p_k, \qquad \mathbf P=\begin{pmatrix}1/2&1/4\\1/2&3/4\end{pmatrix},

whose columns record the click probabilities from each page and therefore sum to one. Starting on page 1 with p0=(1,0)\mathbf p_0=(1,0), the first few distributions are (0.5,0.5)(0.5,0.5), (0.375,0.625)(0.375,0.625), (0.344,0.656)(0.344,0.656), and (0.336,0.664)(0.336,0.664). The changes shrink with every click, as if the walk were settling onto a fixed distribution. Where is the surfer after 50 clicks, and how fast does the distribution converge? PageRank asks the very same question of the entire web.

The key is to rewrite the starting vector in the coordinates of a few special directions, the eigenvectors, along which the matrix acts simply as multiplication by a number. In those coordinates, each component evolves on its own as a scalar power λk\lambda^k.

In Section 1.3 we already met eigenvectors as the directions that a matrix only stretches: the symmetric matrix S=(2112)\mathbf S=\left(\begin{smallmatrix}2&1\\1&2\end{smallmatrix}\right) stretches (1,1)(1,1) by 3 and (1,−1)(1,-1) by 1, and for any symmetric matrix we had Akx=∑iciλikvi\mathbf A^k\mathbf x=\sum_i c_i\lambda_i^k\mathbf v_i. Here we drop the symmetry requirement. We learn how to find the eigenvalues of an arbitrary square matrix, see when a full set of eigenvectors exists and what replaces it when one does not, and then prove why symmetry guarantees so much more.

Three results carry the most weight: the eigenvector expansion (21.3.4) of Akx\mathbf A^k\mathbf x, the spectral theorem, and the quadratic form written as a weighted sum of squares, (21.3.12). A reader in a hurry can jump from Section 21.3.1.3 straight to Section 21.3.2.1. We leave two practical questions to Section 21.4: how to locate and compute eigenvalues when a matrix is large, and the situations in which eigenvalues can mislead us. Throughout this section we compute with NumPy, whose eig function returns complex eigenvalues whenever a real matrix has them.

import numpy as np

21.3.1 Eigenvalues and Diagonalization#

21.3.1.1 Eigenvectors and Eigenvalues#

Certain input vectors are only rescaled by P\mathbf P, as though the matrix were a single number. Applying P\mathbf P to (1,2)(1,2) gives P(1,2)=(12+12, 12+32)=(1,2)\mathbf P(1,2)=(\tfrac12+\tfrac12,\ \tfrac12+\tfrac32)=(1,2), leaving it completely unchanged, while applying P\mathbf P to (1,−1)(1,-1) gives (12−14, 12−34)=14(1,−1)(\tfrac12-\tfrac14,\ \tfrac12-\tfrac34)=\tfrac14(1,-1). Along the first direction P\mathbf P multiplies by 11; along the second it multiplies by 1/41/4.

In general, a nonzero vector v\mathbf v is called an eigenvector of a square matrix A\mathbf A, with corresponding eigenvalue λ\lambda, if

Av=λv.(21.3.1)\mathbf{A}\mathbf{v} = \lambda \mathbf{v}. \tag{21.3.1}

In geometric terms, A\mathbf A only stretches an eigenvector by the factor λ\lambda, reversing its direction when λ<0\lambda\lt 0. For the surfer's matrix P\mathbf P, the eigenpairs (λ,v)(\lambda,\mathbf v) are (1,(1,2))(1,(1,2)) and (14,(1,−1))(\tfrac14,(1,-1)). We exclude the zero vector from being an eigenvector because it trivially satisfies (21.3.1) for every λ\lambda. However, all solutions of Av=λv\mathbf A\mathbf v=\lambda\mathbf v for a fixed λ\lambda, together with 0\mathbf 0, form a linear subspace called the eigenspace of λ\lambda.

The eigenvalue λ=0\lambda=0, on the other hand, is perfectly valid. It means that Av=0\mathbf A\mathbf v=\mathbf 0 for some nonzero v\mathbf v, so a square matrix is singular if and only if 00 is one of its eigenvalues. Notice also that a real matrix need not have any real eigenvectors: a rotation by 90∘90^\circ turns every nonzero direction in the plane. Its eigenvalues turn out to be complex, a case we take up in Section 21.3.1.6.

It is tempting to confuse eigenvectors with the axes of the ellipse produced when an invertible 2×22\times2 matrix acts on the unit circle. Figure 21.3.1 shows why the two concepts are distinct. For the symmetric matrix S\mathbf S, the eigenvectors do lie along the ellipse axes. For the upper-triangular matrix (1102)\left(\begin{smallmatrix}1&1\\0&2\end{smallmatrix}\right), however, they do not: its eigenvectors are (1,0)(1,0) with λ=1\lambda=1 and (1,1)(1,1) with λ=2\lambda=2, whereas the ellipse axes point at 58∘58^\circ and −32∘-32^\circ (Section 21.5 shows how to compute them). The ellipse axes mark the directions of largest and smallest stretch, while the eigenvectors mark the directions that are not rotated at all. For symmetric matrices these two sets of directions always coincide, as the spectral theorem of Section 21.3.2.1 proves; for general matrices they need not.

Figure 21.3.1:

The unit circle (dashed) and its image (blue). Left: for the symmetric matrix (2112)\left(\begin{smallmatrix}2&1\\1&2\end{smallmatrix}\right), the unit eigenvectors (green) lie along the ellipse axes, and their images (red) are scaled by 3 and 1 (for λ=1\lambda=1 the two arrows coincide). Right: for the upper-triangular matrix (1102)\left(\begin{smallmatrix}1&1\\0&2\end{smallmatrix}\right), the eigenvectors (1,0)(1,0) and (1,1)(1,1) do not align with the ellipse axes (grey).

21.3.1.2 The Characteristic Polynomial#

We spotted the eigenvectors of P\mathbf P by inspection, which does not take us far on larger matrices. To find the eigenvalues of any square matrix systematically, move λv\lambda\mathbf v to the left-hand side of (21.3.1) and factor out v\mathbf v:

(A−λI)v=0.(21.3.2)(\mathbf{A} - \lambda \mathbf{I})\mathbf{v} = \mathbf 0. \tag{21.3.2}

A nonzero solution v\mathbf v exists if and only if A−λI\mathbf A-\lambda\mathbf I has a nontrivial null space—that is, if and only if it is singular, so that det⁡(A−λI)=0\det(\mathbf A-\lambda\mathbf I)=0. Expanding this determinant yields a polynomial of degree nn in λ\lambda, called the characteristic polynomial p(λ)=det⁡(A−λI)p(\lambda)=\det(\mathbf A-\lambda\mathbf I). Its roots are precisely the eigenvalues of A\mathbf A. Once a root λ\lambda is known, solving the homogeneous linear system (21.3.2) gives its eigenspace.

Let us run this recipe on the surfer's matrix:

det⁡(P−λI)=(12−λ)(34−λ)−14⋅12=λ2−54λ+14=(λ−1)(λ−14).\det(\mathbf P-\lambda\mathbf I) =\Bigl(\tfrac12-\lambda\Bigr)\Bigl(\tfrac34-\lambda\Bigr)-\tfrac14\cdot\tfrac12 =\lambda^2-\tfrac54\lambda+\tfrac14 =(\lambda-1)\Bigl(\lambda-\tfrac14\Bigr).

The roots are 11 and 1/41/4, matching the two scaling factors we noticed earlier. Because P−λI\mathbf P-\lambda\mathbf I is singular at each root, a single row suffices to find the eigenvector. For λ=1\lambda=1, the first row of P−I\mathbf P-\mathbf I gives −12v1+14v2=0-\tfrac12v_1+\tfrac14v_2=0, so v2=2v1v_2=2v_1 and we may choose v=(1,2)\mathbf v=(1,2). For λ=14\lambda=\tfrac14, the first row of P−14I\mathbf P-\tfrac14\mathbf I gives 14v1+14v2=0\tfrac14v_1+\tfrac14v_2=0, yielding v=(1,−1)\mathbf v=(1,-1). Keep in mind that every eigenvector is determined only up to a nonzero scalar factor: if v\mathbf v is an eigenvector, then so is cvc\mathbf v for any c≠0c\neq0, since both sides of (21.3.1) scale by cc.

In practice we leave this algebra to a numerical library. NumPy's eig returns the eigenvalues together with a matrix whose columns are the corresponding eigenvectors; the last line below checks (21.3.1) for all pairs at once.

P = np.array([[0.5, 0.25], [0.5, 0.75]])
lam, V = np.linalg.eig(P)
print('eigenvalues:', lam)
print('eigenvectors (columns):\n', V)
print('max |P V - V diag(lam)|:', np.abs(P @ V - V * lam).max())
eigenvalues: [0.25 1.  ]
eigenvectors (columns):
 [[-0.70710678 -0.4472136 ]
 [ 0.70710678 -0.89442719]]
max |P V - V diag(lam)|: 0.0

Order, scale, and sign are all at the library's discretion: here eig returns the eigenvalues as 1/41/4 and 11, and the columns are unit-length vectors parallel to (1,−1)(1,-1) and (1,2)(1,2).

Numerical libraries do not actually form and solve the characteristic polynomial. For n≥5n\ge5 there is no general closed-form formula for polynomial roots in radicals, and even for moderate nn the roots are notoriously sensitive to tiny rounding errors in the polynomial coefficients. Instead, eig applies a sequence of orthogonal changes of basis that gradually drive the matrix into triangular form without altering its eigenvalues. A triangular matrix displays its eigenvalues right on its diagonal: subtracting λI\lambda\mathbf I keeps it triangular, and the determinant of a triangular matrix is simply the product of its diagonal entries (Section 21.2.3.2). For matrices far too large to factor at all, power iteration (Section 21.4.1.2) extracts dominant eigenvalues using only matrix--vector products.

21.3.1.3 Diagonalization#

We can now answer our opening question about P50p0\mathbf P^{50}\mathbf p_0. Collect the two eigenvectors of P\mathbf P as the columns of a matrix V\mathbf V, and place their eigenvalues on the diagonal of Λ\boldsymbol\Lambda:

V=(112−1),Λ=(1001/4).\mathbf V=\begin{pmatrix}1&1\\2&-1\end{pmatrix}, \qquad \boldsymbol\Lambda=\begin{pmatrix}1&0\\0&1/4\end{pmatrix}.

Written side by side as columns, the two eigenvector equations Pvi=λivi\mathbf P\mathbf v_i=\lambda_i\mathbf v_i compactly read PV=VΛ\mathbf P\mathbf V=\mathbf V\boldsymbol\Lambda. Because det⁡V=−1−2=−3≠0\det\mathbf V=-1-2=-3\neq0, the matrix V\mathbf V is invertible, with V−1=13(112−1)\mathbf V^{-1}=\tfrac13\left(\begin{smallmatrix}1&1\\2&-1\end{smallmatrix}\right). Multiplying on the right by V−1\mathbf V^{-1} yields

P=VΛV−1.(21.3.3)\mathbf{P} = \mathbf{V} \boldsymbol{\Lambda} \mathbf{V}^{-1}. \tag{21.3.3}

Read this factorization from right to left as three steps: change to eigenvector coordinates (V−1\mathbf V^{-1}), scale each coordinate independently by its eigenvalue (Λ\boldsymbol\Lambda), and change back to the original coordinates (V\mathbf V). A square matrix A\mathbf A that can be written as A=VΛV−1\mathbf A=\mathbf V\boldsymbol\Lambda\mathbf V^{-1}, with V\mathbf V invertible and Λ\boldsymbol\Lambda diagonal, is called diagonalizable, and the factorization itself is its eigendecomposition. Such a factorization exists if and only if A\mathbf A has nn linearly independent eigenvectors to fill the columns of V\mathbf V.

Taking powers of a diagonalizable matrix now becomes effortless. In a product of kk copies of VΛV−1\mathbf V\boldsymbol\Lambda\mathbf V^{-1}, every adjacent pair V−1V\mathbf V^{-1}\mathbf V cancels out:

Ak=(VΛV−1)⋯(VΛV−1)⏞k times=VΛ⋯Λ⏞k timesV−1=VΛkV−1.\mathbf{A}^k = \overbrace{(\mathbf{V}\boldsymbol{\Lambda} \mathbf{V}^{-1})\cdots(\mathbf{V}\boldsymbol{\Lambda} \mathbf{V}^{-1})}^{\textrm{$k$ times}} = \mathbf{V}\overbrace{\boldsymbol{\Lambda}\cdots\boldsymbol{\Lambda}}^{\textrm{$k$ times}}\mathbf{V}^{-1} = \mathbf{V}\boldsymbol{\Lambda}^k \mathbf{V}^{-1}.

Powers of a diagonalizable matrix thus reduce to powers of scalars. Applying Ak\mathbf A^k to a vector x\mathbf x, and writing c=V−1x\mathbf c=\mathbf V^{-1}\mathbf x for the coordinates of x\mathbf x in the eigenbasis (so that x=∑icivi\mathbf x=\sum_i c_i\mathbf v_i), we obtain

Akx=VΛkc=∑i=1nciλikvi.(21.3.4)\mathbf A^k\mathbf x=\mathbf V\boldsymbol\Lambda^k\mathbf c =\sum_{i=1}^n c_i\lambda_i^k\mathbf v_i . \tag{21.3.4}

Each eigen-coordinate evolves independently as the geometric sequence ciλikc_i\lambda_i^k. For the surfer starting on page 1, c=V−1p0=13(1,2)=(13,23)\mathbf c=\mathbf V^{-1}\mathbf p_0=\tfrac13(1,2)=(\tfrac13,\tfrac23), which gives the closed-form distribution after any number of clicks kk:

pk=Pkp0=13(12)+23(14)k(1−1).(21.3.5)\mathbf p_k=\mathbf P^k\mathbf p_0 =\frac13\begin{pmatrix}1\\2\end{pmatrix} +\frac23\Bigl(\frac14\Bigr)^k\begin{pmatrix}1\\-1\end{pmatrix}. \tag{21.3.5}

This completely settles the opening question. As kk grows, the second term vanishes and the distribution approaches π=(1/3,2/3)\boldsymbol\pi=(1/3,2/3): in the long run, the surfer spends twice as much time on page 2 as on page 1. The remaining error is 23 4−k\tfrac23\,4^{-k} in each entry and always points along the eigenvector (1,−1)(1,-1). Every click divides that error by 44, so after 10 clicks it has dropped to 6×10−76\times10^{-7}, and after 50 clicks it is below 10−3010^{-30}. As a sanity check, setting k=3k=3 gives (13+196, 23−196)=(0.34375,0.65625)(\tfrac13+\tfrac1{96},\ \tfrac23-\tfrac1{96})=(0.34375,0.65625), matching the third iterate we computed at the start. Figure 21.3.2 illustrates the geometry: because the entries of every pk\mathbf p_k sum to one, the iterates slide along the line x+y=1x+y=1 toward the point where the eigenvector of λ=1\lambda=1 intersects it.

Figure 21.3.2:

The surfer's distributions pk\mathbf p_k slide along x+y=1x+y=1 toward π=(1/3,2/3)\boldsymbol\pi=(1/3,2/3), where the eigenvector (1,2)(1,2) of λ=1\lambda=1 meets the line. The error points along the eigenvector (1,−1)(1,-1) of λ=1/4\lambda=1/4 and shrinks by a factor of 4 per click.

Let us verify that fifty matrix multiplications and the two-term eigen-expansion produce the same p50\mathbf p_{50}, and check the ratio of consecutive errors.

p0 = np.array([1.0, 0.0])
c = np.linalg.solve(V, p0)              # coordinates of p0 in the eigenbasis
print('P^50 p0             :', np.linalg.matrix_power(P, 50) @ p0)
print('sum c_i lam_i^50 v_i:', V @ (c * lam ** 50))
pi = np.array([1 / 3, 2 / 3])
errs = np.array([np.abs(np.linalg.matrix_power(P, k) @ p0 - pi).max()
                 for k in range(8)])
print('error ratios:', np.round(errs[1:] / errs[:-1], 4))
P^50 p0             : [0.33333333 0.66666667]
sum c_i lam_i^50 v_i: [0.33333333 0.66666667]
error ratios: [0.25 0.25 0.25 0.25 0.25 0.25 0.25]

The two computations agree, and every consecutive error ratio is 0.250.25. The eigenvalue 11 governs the part of p0\mathbf p_0 that survives, while the eigenvalue 1/41/4 governs the part that dies out.

The same recipe applies to other functions of a diagonalizable matrix. When no eigenvalue is zero, A−1=VΛ−1V−1\mathbf A^{-1}=\mathbf V\boldsymbol\Lambda^{-1}\mathbf V^{-1}: simply invert each eigenvalue on the diagonal. Similarly, the matrix exponential eAt=VeΛtV−1e^{\mathbf A t}=\mathbf V e^{\boldsymbol\Lambda t}\mathbf V^{-1}, which solves the linear differential equation x˙=Ax\dot{\mathbf x}=\mathbf A\mathbf x, is built by exponentiating each eigenvalue; Section 26.1 develops it in detail.

Similarity. The eigendecomposition tells us that P\mathbf P and Λ\boldsymbol\Lambda represent the very same linear map written in two different bases. In general, two matrices related by A′=BAB−1\mathbf A'=\mathbf B\mathbf A\mathbf B^{-1} for some invertible B\mathbf B are called similar. The next proposition confirms that changing basis cannot alter a matrix's eigenvalues. It relies on the multiplicativity of the determinant from Section 21.2,

det⁡(XY)=det⁡X det⁡Y,\det(\mathbf X\mathbf Y)=\det\mathbf X\,\det\mathbf Y,

which in particular gives det⁡(B−1)=1/det⁡B\det(\mathbf B^{-1})=1/\det\mathbf B from BB−1=I\mathbf B\mathbf B^{-1}=\mathbf I.

Proposition (similar matrices share the characteristic polynomial). For every square A\mathbf A and every invertible B\mathbf B,

det⁡(BAB−1−λI)=det⁡(A−λI).(21.3.6)\det(\mathbf B\mathbf A\mathbf B^{-1}-\lambda\mathbf I)=\det(\mathbf A-\lambda\mathbf I). \tag{21.3.6}

Proof. Rewrite λI=B(λI)B−1\lambda\mathbf I=\mathbf B(\lambda\mathbf I)\mathbf B^{-1} and factor out B\mathbf B and B−1\mathbf B^{-1}: det⁡(BAB−1−λI)=det⁡(B(A−λI)B−1)=det⁡B det⁡(A−λI) det⁡B−1=det⁡(A−λI)\det(\mathbf B\mathbf A\mathbf B^{-1}-\lambda\mathbf I) =\det\bigl(\mathbf B(\mathbf A-\lambda\mathbf I)\mathbf B^{-1}\bigr) =\det\mathbf B\,\det(\mathbf A-\lambda\mathbf I)\,\det\mathbf B^{-1} =\det(\mathbf A-\lambda\mathbf I). ■\blacksquare

Similar matrices therefore have the same eigenvalues with the same multiplicities as roots, and any quantity determined by the characteristic polynomial is a similarity invariant. The two most useful invariants are the determinant and the trace. For any diagonalizable matrix,

det⁡(A)=det⁡(VΛV−1)=det⁡(V)det⁡(Λ)det⁡(V−1)=det⁡(Λ)=λ1λ2⋯λn.(21.3.7)\det(\mathbf{A}) = \det(\mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^{-1}) = \det(\mathbf{V})\det(\boldsymbol{\Lambda})\det(\mathbf{V}^{-1}) = \det(\boldsymbol{\Lambda}) = \lambda_1 \lambda_2 \cdots \lambda_n . \tag{21.3.7}

Thus the determinant is the product of the eigenvalues: whatever volume distortion V\mathbf V introduces, V−1\mathbf V^{-1} undoes, leaving only the axis scaling of Λ\boldsymbol\Lambda. For the trace, we use its cyclic property (Section 21.2.1.4),

tr⁡(XY)=tr⁡(YX),\operatorname{tr}(\mathbf X\mathbf Y)=\operatorname{tr}(\mathbf Y\mathbf X),

which holds for any X\mathbf X and Y\mathbf Y whose products are square. Setting X=V\mathbf X=\mathbf V and Y=ΛV−1\mathbf Y=\boldsymbol\Lambda\mathbf V^{-1} gives

tr⁡(A)=tr⁡(VΛV−1)=tr⁡(ΛV−1V)=tr⁡(Λ)=λ1+⋯+λn.(21.3.8)\operatorname{tr}(\mathbf{A}) = \operatorname{tr}(\mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^{-1}) = \operatorname{tr}(\boldsymbol{\Lambda}\mathbf{V}^{-1}\mathbf{V}) = \operatorname{tr}(\boldsymbol{\Lambda}) = \lambda_1+\cdots+\lambda_n . \tag{21.3.8}

Thus the trace is the sum of the eigenvalues. On the surfer's matrix we can check both identities at a glance: tr⁡P=12+34=54=1+14\operatorname{tr}\mathbf P=\tfrac12+\tfrac34=\tfrac54=1+\tfrac14 and det⁡P=38−18=14=1⋅14\det\mathbf P=\tfrac38-\tfrac18=\tfrac14=1\cdot\tfrac14. For any 2×22\times2 matrix, these two numbers fix both eigenvalues directly as the roots of λ2−(tr⁡)λ+det⁡\lambda^2-(\operatorname{tr})\lambda+\det.

In fact, both identities hold for every square matrix, diagonalizable or not, provided we count the eigenvalues over C\mathbb C with their multiplicities as roots. By the fundamental theorem of algebra (which we take as given), every degree-nn polynomial factors completely over C\mathbb C:

det⁡(A−λI)=∏i=1n(λi−λ).\det(\mathbf A-\lambda\mathbf I)=\prod_{i=1}^n(\lambda_i-\lambda).

Setting λ=0\lambda=0 immediately yields det⁡A=∏iλi\det\mathbf A=\prod_i\lambda_i. For the trace, compare the coefficients of λn−1\lambda^{n-1} on both sides. On the right-hand side the coefficient is (−1)n−1∑iλi(-1)^{n-1}\sum_i\lambda_i. On the left-hand side, only the product of the diagonal entries of A−λI\mathbf A-\lambda\mathbf I reaches degree n−1n-1, giving (−1)n−1∑iaii(-1)^{n-1}\sum_i a_{ii}. Hence tr⁡A=∑iλi\operatorname{tr}\mathbf A=\sum_i\lambda_i. Because any non-real eigenvalues of a real matrix come in complex conjugate pairs, both the sum and the product remain real.

Finally, the rank of a diagonalizable matrix equals its number of nonzero eigenvalues, counted with multiplicity: multiplying by the invertible matrices V\mathbf V and V−1\mathbf V^{-1} preserves dimensions, so rank⁡A=rank⁡Λ\operatorname{rank}\mathbf A=\operatorname{rank}\boldsymbol\Lambda. Exercise 2 examines what happens when a matrix is not diagonalizable.

21.3.1.4 Algebraic and Geometric Multiplicity#

The surfer's matrix had two distinct eigenvalues and yielded two linearly independent eigenvectors. That was no coincidence: distinct eigenvalues always produce independent eigenvectors.

Proposition (distinct eigenvalues give independent eigenvectors). Eigenvectors belonging to distinct eigenvalues are linearly independent. In particular, any n×nn\times n matrix with nn distinct eigenvalues is diagonalizable.

Proof. Suppose, for the sake of contradiction, that some eigenvectors v1,…,vm\mathbf{v}_1,\ldots,\mathbf{v}_m with distinct eigenvalues λ1,…,λm\lambda_1,\ldots,\lambda_m are linearly dependent. Among all nontrivial dependence relations, choose one with the fewest nonzero coefficients, ∑i=1mcivi=0\sum_{i=1}^{m} c_i\mathbf{v}_i = \mathbf 0, and relabel if needed so that cm≠0c_m\neq0. Such a relation must have at least two nonzero coefficients, since cmvm=0c_m\mathbf{v}_m=\mathbf 0 alone would force vm=0\mathbf{v}_m=\mathbf 0. Now apply A\mathbf{A} to the relation and subtract λm\lambda_m times the original relation:

0=A ⁣∑icivi−λm ⁣∑icivi=∑i=1m−1ci(λi−λm) vi.\mathbf 0 = \mathbf{A}\!\sum_i c_i\mathbf{v}_i - \lambda_m\!\sum_i c_i\mathbf{v}_i = \sum_{i=1}^{m-1} c_i(\lambda_i-\lambda_m)\,\mathbf{v}_i .

The vm\mathbf{v}_m term drops out, leaving a shorter relation. Yet it is still nontrivial: any other nonzero coefficient cic_i (i<mi\lt m) survives as ci(λi−λm)≠0c_i(\lambda_i-\lambda_m)\neq0 because the eigenvalues are distinct. This contradicts the minimality of our chosen relation. When A\mathbf A has nn distinct eigenvalues, its nn independent eigenvectors form a basis of Cn\mathbb C^n (or of Rn\mathbb R^n when all eigenvalues are real), so V\mathbf{V} is invertible. ■\blacksquare

When eigenvalues repeat, we have to keep track of two different counts. The number of times λ\lambda appears as a root of the characteristic polynomial is its algebraic multiplicity a(λ)a(\lambda). The dimension of its eigenspace—the number of linearly independent eigenvectors it contributes—is its geometric multiplicity g(λ)g(\lambda).

Proposition. For every eigenvalue λ\lambda of a square matrix, 1≤g(λ)≤a(λ)1\le g(\lambda)\le a(\lambda).

Proof. Because A−λI\mathbf A-\lambda\mathbf I is singular, its null space is nontrivial, which gives g≥1g\ge1. For the upper bound, pick a basis v1,…,vg\mathbf v_1,\ldots,\mathbf v_g of the eigenspace, extend it to a basis of Cn\mathbb C^n, and place these basis vectors as the columns of B\mathbf B. The first gg columns of AB\mathbf A\mathbf B are simply λv1,…,λvg\lambda\mathbf v_1,\ldots,\lambda\mathbf v_g, so in this new basis the matrix takes a block upper-triangular form:

B−1AB=(λIgX0Y).\mathbf B^{-1}\mathbf A\mathbf B=\begin{pmatrix}\lambda\mathbf I_g&\mathbf X\\\mathbf 0&\mathbf Y\end{pmatrix}.

By (21.3.6), this matrix has the same characteristic polynomial pp as A\mathbf A. Let us write the polynomial variable as tt, since λ\lambda now stands for our fixed eigenvalue. Subtracting tIt\mathbf I preserves the block upper-triangular structure, with diagonal blocks (λ−t)Ig(\lambda-t)\mathbf I_g and Y−tI\mathbf Y-t\mathbf I. Because the determinant of a block upper-triangular matrix is the product of the determinants of its diagonal blocks (Section 21.2.3.2), we get p(t)=(λ−t)gdet⁡(Y−tI)p(t)=(\lambda-t)^g\det(\mathbf Y-t\mathbf I). Thus (λ−t)g(\lambda-t)^g divides the characteristic polynomial, which means a≥ga\ge g. ■\blacksquare

An eigenvalue can never supply more independent eigenvectors than its multiplicity as a root, though it can supply fewer. Now pick a basis for each eigenspace and pool all the chosen vectors together. They are jointly independent: if a linear combination of them equals zero, group the terms by eigenvalue; each group is either zero or an eigenvector, and the proposition on distinct eigenvalues forces every group to vanish. A matrix therefore possesses at most ∑λg(λ)\sum_\lambda g(\lambda) linearly independent eigenvectors. Over C\mathbb C, the algebraic multiplicities sum to nn and g(λ)≤a(λ)g(\lambda)\le a(\lambda) for every λ\lambda, which gives a crisp criterion: the eigenvectors of A\mathbf A span Cn\mathbb C^n if and only if g(λ)=a(λ)g(\lambda)=a(\lambda) for every complex eigenvalue λ\lambda.

For a real matrix to have a basis of real eigenvectors, all of its eigenvalues must also be real. The 90∘90^\circ rotation R90=(0−110)\mathbf R_{90}=\left(\begin{smallmatrix}0&-1\\1&0\end{smallmatrix}\right) shows why that extra requirement is essential: its eigenvalues ±i\pm i each satisfy g=a=1g=a=1, so it has a full complex eigenbasis, yet no real eigenvector at all.

When eigenvalues repeat, diagonalizability can fail altogether. The simplest counterexample is the shear from Section 21.2.1.2:

T=(1101).(21.3.9)\mathbf{T} = \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix}. \tag{21.3.9}

Its characteristic polynomial is (1−λ)2(1-\lambda)^2, so λ=1\lambda=1 has algebraic multiplicity 22. Yet (T−I)v=0(\mathbf{T}-\mathbf{I})\mathbf{v}=\mathbf 0 becomes (0100)v=0\left(\begin{smallmatrix}0&1\\0&0\end{smallmatrix}\right)\mathbf v=\mathbf 0, which forces v2=0v_2=0. The eigenspace is only the line spanned by (1,0)(1,0), so the geometric multiplicity is 11. There is no eigenbasis, and the shear is not diagonalizable. Any matrix with g(λ)<a(λ)g(\lambda)\lt a(\lambda) for some eigenvalue is called defective. Figure 21.3.3 makes the shortage visible: the shear slides every horizontal line sideways in proportion to its height, leaving the horizontal axis as the sole line through the origin that keeps its direction. (By contrast, a diagonalizable 2×22\times2 matrix with a repeated eigenvalue λ\lambda would have to be λI\lambda\mathbf I, which preserves every direction.)

Figure 21.3.3:

The defective shear acting on the plane. Every horizontal line slides to the right by an amount proportional to its height, tilting the grid, while the xx-axis (green) maps to itself: Te1=e1\mathbf{T}\mathbf{e}_1=\mathbf{e}_1 is the only eigendirection, with λ=1\lambda=1. The other basis vector picks up a horizontal component, Te2=(1,1)\mathbf{T}\mathbf{e}_2=(1,1), so no second direction is preserved: geometric multiplicity 1 against algebraic multiplicity 2.

Iterating the shear shows how defectiveness changes the behavior of matrix powers: Tk=(1k01)\mathbf T^k=\left(\begin{smallmatrix}1&k\\0&1\end{smallmatrix}\right), so Tke2=(k,1)\mathbf T^k\mathbf e_2=(k,1) grows without bound even though the only eigenvalue is 11. No pure eigen-expansion can produce that linear factor kk. The next subsection explains where it comes from.

21.3.1.5 The Jordan Normal Form#

When geometric multiplicity falls short, no eigenbasis exists. What structure takes its place? For what follows in this book, one consequence matters most: a defective eigenvalue multiplies λk\lambda^k by a polynomial in kk. Over the complex numbers, every square matrix is similar to a block-diagonal matrix built from Jordan blocks

Jm(λ)=(λ1λ⋱⋱1λ),\mathbf{J}_m(\lambda) = \begin{pmatrix} \lambda & 1 & & \\ & \lambda& \ddots & \\ & & \ddots & 1 \\ & & & \lambda \end{pmatrix},

which are m×mm\times m blocks carrying a single eigenvalue λ\lambda down the diagonal and 11s on the superdiagonal immediately above it. This factorization is the Jordan normal form (Horn and Johnson, 2012), which we use without proof. By (21.3.6), it has the same eigenvalues as the original matrix.

Each Jordan block supplies exactly one eigenvector, namely its first basis vector. The geometric multiplicity of λ\lambda is therefore the number of blocks carrying λ\lambda, while its algebraic multiplicity is the sum of their sizes. In particular, a matrix is diagonalizable if and only if every Jordan block has size 1×11\times1. The shear T\mathbf T of (21.3.9) is the single block J2(1)\mathbf{J}_2(1).

Under repeated application, a Jordan block does more than simply scale. Write Jm(λ)=λI+N\mathbf{J}_m(\lambda)=\lambda\mathbf{I}+\mathbf{N}, where N\mathbf{N} has 11s just above the diagonal and zeros everywhere else. Geometrically, N\mathbf N acts as a shift, sending each basis vector to the previous one, so Nm=0\mathbf N^m=\mathbf 0 (any matrix with a vanishing power is called nilpotent). Because I\mathbf{I} and N\mathbf{N} commute, we can expand powers with the binomial theorem. For m=2m=2, every term beyond the first two contains N2=0\mathbf{N}^2=\mathbf 0, leaving

J2(λ)k=(λI+N)k=λkI+kλk−1N.\mathbf{J}_2(\lambda)^k = (\lambda\mathbf{I}+\mathbf{N})^k = \lambda^k\mathbf{I} + k\lambda^{k-1}\mathbf{N}.

In the long run, the eigenvalue still decides between growth and decay, but it is now multiplied by a polynomial in kk (of degree m−1m-1 for an m×mm\times m block). When ∣λ∣=1|\lambda|=1, as in the shear, the iterates drift linearly. When ∣λ∣|\lambda| is slightly below 11, something more surprising happens: the upper-right entry kλk−1k\lambda^{k-1} initially grows, peaks near k≈−1/log⁡∣λ∣k\approx-1/\log|\lambda|, and only then decays toward zero. For λ=0.99\lambda=0.99 this puts the peak near k≈100k\approx100, where the entry reaches 100⋅0.9999≈37100\cdot0.99^{99}\approx37. Let us check this prediction numerically.

J = np.array([[0.99, 1.], [0., 0.99]])   # the Jordan block J_2(0.99)
for k in [1, 50, 100, 200, 800]:
    Jk = np.linalg.matrix_power(J, k)
    pred = k * 0.99 ** (k - 1)   # predicted corner entry, k * lambda^(k-1)
    print(f'k = {k:3d}   ||J^k|| = {np.linalg.norm(Jk, 2):8.3f}   '
          f'k * 0.99^(k-1) = {pred:8.3f}')
k =   1   ||J^k|| =    1.609   k * 0.99^(k-1) =    1.000
k =  50   ||J^k|| =   30.568   k * 0.99^(k-1) =   30.556
k = 100   ||J^k|| =   36.977   k * 0.99^(k-1) =   36.973
k = 200   ||J^k|| =   27.067   k * 0.99^(k-1) =   27.067
k = 800   ||J^k|| =    0.260   k * 0.99^(k-1) =    0.260

Every eigenvalue of J\mathbf{J} is 0.990.99, yet the norm of its powers climbs to about 3737 at k=100k=100 and is still 2727 at k=200k=200 before the exponential factor 0.99k0.99^k finally takes over. Eigenvalues alone do not warn us about this transient growth, a phenomenon we revisit in Section 21.4.2.3.

Jordan blocks represent one way a real matrix can lack a real eigenbasis: it simply has too few eigenvectors. The second way is quite different in nature. A real matrix can lack any real eigenvector in a plane because it rotates that plane.

21.3.1.6 Complex Eigenvalues#

Consider the planar rotation by an angle θ\theta (Section 21.2.1.3),

Rθ=(cos⁡θ−sin⁡θsin⁡θ−cos⁡θ).\mathbf{R}_\theta = \begin{pmatrix}\cos\theta & -\sin\theta\\ \sin\theta & \phantom{-}\cos\theta\end{pmatrix}.

Whenever θ\theta is not a multiple of π\pi, Rθ\mathbf{R}_\theta turns every nonzero real vector, leaving no real eigenvector. Its characteristic polynomial λ2−2cos⁡θ λ+1\lambda^2-2\cos\theta\,\lambda+1 has the complex conjugate roots λ=cos⁡θ±isin⁡θ=e±iθ\lambda=\cos\theta\pm i\sin\theta=e^{\pm i\theta}. Here the modulus ∣λ∣=1|\lambda|=1 reflects that Rθ\mathbf{R}_\theta preserves lengths, while the argument ±θ\pm\theta records the rotation angle.

Now look at the chapter's running 2×22\times2 matrix, which shows no obvious rotation in its entries:

A=(12−13),tr⁡A=4,det⁡A=5.\mathbf A=\begin{pmatrix}1&2\\-1&3\end{pmatrix}, \qquad \operatorname{tr}\mathbf A=4,\quad \det\mathbf A=5 .

Its characteristic polynomial is λ2−4λ+5\lambda^2-4\lambda+5, whose roots are λ=2±i=5 e±iθ\lambda=2\pm i=\sqrt5\,e^{\pm i\theta} with θ=arctan⁡12≈26.6∘\theta=\arctan\tfrac12\approx26.6^\circ. To find an eigenvector for 2+i2+i, read off the second row of A−(2+i)I\mathbf A-(2+i)\mathbf I, which gives −w1+(1−i)w2=0-w_1+(1-i)w_2=0. Setting w2=1w_2=1 yields

w=(1−i1)=(11)⏟u+i(−10)⏟v.\mathbf w=\begin{pmatrix}1-i\\1\end{pmatrix} =\underbrace{\begin{pmatrix}1\\1\end{pmatrix}}_{\mathbf u} +i\underbrace{\begin{pmatrix}-1\\0\end{pmatrix}}_{\mathbf v}.

Where is the rotation hiding? Take any real matrix A\mathbf{A} with a complex eigenpair Aw=λw\mathbf{A}\mathbf{w}=\lambda\mathbf{w}, where λ=a+ib\lambda=a+ib and b≠0b\neq0, and separate the eigenvector into its real and imaginary parts, w=u+iv\mathbf{w}=\mathbf{u}+i\mathbf{v}. Expanding A(u+iv)=(a+ib)(u+iv)\mathbf{A}(\mathbf{u}+i\mathbf{v})=(a+ib)(\mathbf{u}+i\mathbf{v}) and equating real and imaginary parts gives

Au=au−bv,Av=bu+av.\mathbf{A}\mathbf{u} = a\mathbf{u} - b\mathbf{v}, \qquad \mathbf{A}\mathbf{v} = b\mathbf{u} + a\mathbf{v}.

Both images stay inside span⁡{u,v}\operatorname{span}\{\mathbf{u},\mathbf{v}\}, so this subspace is invariant under A\mathbf{A}. Moreover, it is a genuine two-dimensional plane. If u\mathbf u and v\mathbf v were linearly dependent, their span would be a single line (not zero, because w≠0\mathbf w\neq\mathbf 0) mapped into itself, on which A\mathbf A would act by multiplying by some real scalar μ\mu. That would force Aw=μw\mathbf A\mathbf w=\mu\mathbf w, making λ=μ\lambda=\mu real and contradicting b≠0b\neq0. Placing v\mathbf{v} and u\mathbf{u} as the columns of B=[v    u]\mathbf{B}=[\mathbf{v}\;\;\mathbf{u}] turns the two identities into AB=B(a−bb−a)\mathbf{A}\mathbf{B}=\mathbf{B}\left(\begin{smallmatrix}a & -b\\ b & \phantom{-}a\end{smallmatrix}\right), or equivalently,

B−1AB=(a−bb−a)=a2+b2⏟r (cos⁡θ−sin⁡θsin⁡θ−cos⁡θ),θ=arg⁡(a+ib).(21.3.10)\mathbf{B}^{-1}\mathbf{A}\mathbf{B} = \begin{pmatrix} a & -b\\ b & \phantom{-}a \end{pmatrix} = \underbrace{\sqrt{a^2+b^2}}_{r}\, \begin{pmatrix} \cos\theta & -\sin\theta\\ \sin\theta & \phantom{-}\cos\theta \end{pmatrix}, \qquad \theta=\arg(a+ib). \tag{21.3.10}

In the basis (v,u)(\mathbf v,\mathbf u) of its invariant plane, A\mathbf{A} acts as a rotation--scaling block rRθr\mathbf R_\theta: it scales by the modulus rr and rotates by the argument θ\theta. Because the derivation used only Aw=λw\mathbf A\mathbf w=\lambda\mathbf w, this block is independent of how w\mathbf w is scaled or rotated in phase. The connection also works in reverse: if we identify (x,y)∈R2(x,y)\in\mathbb{R}^2 with the complex number x+iyx+iy, then the block maps (x,y)(x,y) to (ax−by, bx+ay)(ax-by,\,bx+ay), which is simply complex multiplication by a+iba+ib.

For our running matrix A\mathbf A, we have B=(−1101)\mathbf B=\left(\begin{smallmatrix}-1&1\\0&1\end{smallmatrix}\right) and B−1AB=(2−112)\mathbf B^{-1}\mathbf A\mathbf B=\left(\begin{smallmatrix}2&-1\\1&2\end{smallmatrix}\right), which scales by 5\sqrt5 and rotates by 26.6∘26.6^\circ. One might expect every step to lengthen a vector by the factor 5≈2.24\sqrt5\approx2.24. Let us compute the block from the eigenvector returned by eig and track the actual lengths of the iterates Ak(1,0)\mathbf A^k(1,0).

A = np.array([[1., 2.], [-1., 3.]])
lam, V = np.linalg.eig(A)
j = np.argmax(lam.imag)                  # the eigenvalue a + ib with b > 0
r, theta = np.abs(lam[j]), np.angle(lam[j])
u, v = V[:, j].real, V[:, j].imag
B = np.column_stack([v, u])              # basis (v, u) of the invariant plane
print(f'lambda = {lam[j]:.4f}   r = {r:.4f}   theta = {theta:.4f}')
print('B^-1 A B =\n', np.round(np.linalg.inv(B) @ A @ B, 4))
xs = [np.array([1., 0.])]
for _ in range(8):
    xs.append(A @ xs[-1])
norms = np.linalg.norm(xs, axis=1)
print('norm ratios:', np.round(norms[1:] / norms[:-1], 2))
x20 = np.linalg.matrix_power(A, 20) @ np.array([1., 0.])
print(f'average rate ||A^20 x||^(1/20) = {np.linalg.norm(x20) ** (1 / 20):.3f}')
lambda = 2.0000+1.0000j   r = 2.2361   theta = 0.4636
B^-1 A B =
 [[ 2. -1.]
 [ 1.  2.]]
norm ratios: [1.41 2.92 3.45 2.76 2.27 1.88 1.5  1.54]
average rate ||A^20 x||^(1/20) = 2.252

Regardless of which eigenvector eig chooses, the resulting block is (2−112)\left(\begin{smallmatrix}2&-1\\1&2\end{smallmatrix}\right). Yet the vector lengths do not grow by a steady factor of 2.242.24 at each step. Along the trajectory (1,0)→(1,−1)→(−1,−4)→(−9,−11)→(−31,−24)(1,0)\to(1,-1)\to(-1,-4)\to(-9,-11)\to(-31,-24), the per-step norm ratios swing between roughly 1.41.4 and 3.53.5. The reason is that the scaling is uniform only in the coordinates (v,u)(\mathbf v,\mathbf u), which are not orthonormal. Back in standard coordinates, the iterates spiral outward along stretched ellipses, completing a full turn roughly every 2π/θ≈13.62\pi/\theta\approx13.6 steps. Only the long-run geometric average ∥Akx∥1/k\|\mathbf A^k\mathbf x\|^{1/k} settles at 5\sqrt5 (reaching 2.252.25 by k=20k=20). The motion is a rigid rotation and uniform scaling in standard coordinates only when the matrix is normal, a property we define in Section 21.4.2.2.

Up to a real change of basis, every real square matrix is built from the three elementary behaviors we have now uncovered, alone or in combination: stretching along a line, shearing within a Jordan block, and rotating with scaling in a plane. This decomposition is known as the real Jordan form (Horn and Johnson, 2012).

21.3.2 Symmetric Matrices and Quadratic Forms#

21.3.2.1 The Spectral Theorem#

Which matrices guarantee a real, orthonormal eigenbasis? Symmetry eliminates both obstacles we just encountered: it rules out complex eigenvalues as well as shortages of eigenvectors. The symmetric matrix S\mathbf S from Section 1.3 shows what happens. Its unit eigenvectors (1,1)/2(1,1)/\sqrt2 and (1,−1)/2(1,-1)/\sqrt2 are perpendicular, giving

S=(2112)=12(111−1)⏟V(3001)12(111−1)⏟V⊤.\mathbf S=\begin{pmatrix}2&1\\1&2\end{pmatrix} =\underbrace{\frac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}}_{\mathbf V} \begin{pmatrix}3&0\\0&1\end{pmatrix} \underbrace{\frac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}}_{\mathbf V^\top}.

Because the eigenvector matrix V\mathbf V is orthogonal (V⊤V=I\mathbf V^\top\mathbf V=\mathbf I), its inverse is simply its transpose. The spectral theorem guarantees that this holds for every real symmetric matrix. It is the central theorem of this chapter: positive definiteness, the Rayleigh quotient, and all of Section 21.5 rest on it.

Theorem (spectral theorem). Every real symmetric matrix A\mathbf{A} has real eigenvalues and an orthonormal basis of real eigenvectors. Equivalently,

A=VΛV⊤,(21.3.11)\mathbf{A} = \mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^\top , \tag{21.3.11}

where Λ=diag⁡(λ1,…,λn)\boldsymbol{\Lambda}=\operatorname{diag}(\lambda_1,\ldots,\lambda_n) is real and V\mathbf{V} is orthogonal.

We prove this in three steps: first, every eigenvalue is real; second, eigenvectors for distinct eigenvalues are orthogonal; third, a full orthonormal eigenbasis always exists. For complex vectors we use the Hermitian inner product ⟨x,y⟩=x∗y\langle\mathbf x,\mathbf y\rangle=\mathbf x^*\mathbf y, where x∗\mathbf x^* is the conjugate transpose (which reduces to the ordinary dot product on real vectors). The only external fact we borrow is that the characteristic polynomial has at least one complex root (the fundamental theorem of algebra), ensuring that at least one eigenpair exists over C\mathbb{C}. Parts (i) and (ii) take only two lines each; the real work is in part (iii).

Proof, part (i): the eigenvalues are real. Suppose Av=λv\mathbf{A}\mathbf{v}=\lambda\mathbf{v} with v≠0\mathbf{v}\neq\mathbf 0, allowing complex entries for the moment. Because A\mathbf{A} is real and symmetric, A∗=A⊤=A\mathbf A^*=\mathbf A^\top=\mathbf A, and therefore

λ v∗v=v∗Av=(Av)∗v=λˉ v∗v.\lambda\,\mathbf{v}^*\mathbf{v} = \mathbf{v}^*\mathbf{A}\mathbf{v} = (\mathbf{A}\mathbf{v})^*\mathbf{v} = \bar\lambda\,\mathbf{v}^*\mathbf{v}.

Since v∗v=∥v∥2>0\mathbf{v}^*\mathbf{v}=\|\mathbf v\|^2>0, we can divide both sides by it to obtain λ=λˉ\lambda=\bar\lambda: the eigenvalue must be real. Its eigenvector can then be chosen real as well, because it solves the real homogeneous system (A−λI)v=0(\mathbf A-\lambda\mathbf I)\mathbf v=\mathbf 0. ■\blacksquare

Proof, part (ii): eigenvectors of distinct eigenvalues are orthogonal. Let Au=λu\mathbf{A}\mathbf{u}=\lambda\mathbf{u} and Av=μv\mathbf{A}\mathbf{v}=\mu\mathbf{v} with λ≠μ\lambda\neq\mu, where both eigenvalues and both eigenvectors are real by part (i). Using A=A⊤\mathbf{A}=\mathbf{A}^\top to move A\mathbf{A} across the inner product,

λ⟨u,v⟩=⟨Au,v⟩=⟨u,Av⟩=μ⟨u,v⟩.\lambda\langle\mathbf{u},\mathbf{v}\rangle = \langle\mathbf{A}\mathbf{u},\mathbf{v}\rangle = \langle\mathbf{u},\mathbf{A}\mathbf{v}\rangle = \mu\langle\mathbf{u},\mathbf{v}\rangle.

Thus (λ−μ)⟨u,v⟩=0(\lambda-\mu)\langle\mathbf{u},\mathbf{v}\rangle=0. Because λ≠μ\lambda\neq\mu, we must have ⟨u,v⟩=0\langle\mathbf{u},\mathbf{v}\rangle=0. ■\blacksquare

Proof, part (iii): an orthonormal eigenbasis. We argue by induction on nn; for n=1n=1 the claim is immediate. For n>1n>1, part (i) supplies a real eigenpair (λ1,v1)(\lambda_1,\mathbf{v}_1) with ∥v1∥=1\|\mathbf{v}_1\|=1. Consider the (n−1)(n-1)-dimensional orthogonal complement U=v1⊥U=\mathbf{v}_1^{\perp}. Symmetry ensures that A\mathbf{A} maps UU back into itself: for any x∈U\mathbf{x}\in U,

⟨Ax,v1⟩=⟨x,Av1⟩=λ1⟨x,v1⟩=0.\langle\mathbf{A}\mathbf{x},\mathbf{v}_1\rangle = \langle\mathbf{x},\mathbf{A}\mathbf{v}_1\rangle = \lambda_1\langle\mathbf{x},\mathbf{v}_1\rangle = 0 .

Choose an orthonormal basis of UU and assemble its vectors as the columns of Q∈Rn×(n−1)\mathbf Q\in\mathbb R^{n\times(n-1)}. Because every column of AQ\mathbf A\mathbf Q lies in UU, we can write AQ=QC\mathbf A\mathbf Q=\mathbf Q\mathbf C where C=Q⊤AQ\mathbf C=\mathbf Q^\top\mathbf A\mathbf Q represents A\mathbf A restricted to UU. Notice that C\mathbf C is symmetric, C⊤=Q⊤A⊤Q=C\mathbf C^\top=\mathbf Q^\top\mathbf A^\top\mathbf Q=\mathbf C, and has size (n−1)×(n−1)(n-1)\times(n-1). By the inductive hypothesis, C=V′Λ′V′⊤\mathbf C=\mathbf V'\boldsymbol\Lambda'\mathbf V'^\top for an orthogonal matrix V′\mathbf V'. Now look at the columns of QV′\mathbf Q\mathbf V': they are orthonormal because (QV′)⊤QV′=V′⊤V′=I(\mathbf Q\mathbf V')^\top\mathbf Q\mathbf V'=\mathbf V'^\top\mathbf V'=\mathbf I; they lie in UU, so they are orthogonal to v1\mathbf v_1; and they are eigenvectors of A\mathbf A, because AQV′=QCV′=QV′Λ′\mathbf A\mathbf Q\mathbf V'=\mathbf Q\mathbf C\mathbf V'=\mathbf Q\mathbf V'\boldsymbol\Lambda'. Appending them to v1\mathbf v_1 gives the orthogonal matrix V=[v1  QV′]\mathbf V=[\mathbf v_1\;\mathbf Q\mathbf V'] satisfying AV=VΛ\mathbf A\mathbf V=\mathbf V\boldsymbol\Lambda. ■\blacksquare

Geometrically, (21.3.11) breaks any symmetric linear map into three clean actions. First, V⊤\mathbf V^\top aligns the orthonormal eigenvectors with the coordinate axes—a pure rotation, possibly combined with a reflection (for S\mathbf S above, det⁡V=−1\det\mathbf V=-1). Next, Λ\boldsymbol\Lambda stretches each coordinate axis by its eigenvalue. Finally, V\mathbf V turns the axes back. This proves what the left panel of Figure 21.3.1 illustrated for S\mathbf S, now for every symmetric matrix.

Every matrix A\mathbf A, rectangular or square, produces a symmetric matrix A⊤A\mathbf A^\top\mathbf A. Its quadratic form x⊤A⊤Ax=∥Ax∥2\mathbf x^\top\mathbf A^\top\mathbf A\mathbf x=\|\mathbf A\mathbf x\|^2 can never be negative—a property that we name, test, and exploit next.

21.3.2.2 Positive Definiteness#

Can the quadratic form x⊤Ax\mathbf{x}^\top\mathbf{A}\mathbf{x} ever turn negative? This single question decides whether a critical point of a loss surface is a minimum, whether a matrix is a valid covariance, and whether a least-squares problem has a unique solution. A symmetric matrix A\mathbf{A} is positive semidefinite (PSD), written A⪰0\mathbf{A}\succeq0, if

x⊤Ax≥0for all x,\mathbf{x}^\top\mathbf{A}\mathbf{x} \ge 0 \quad\textrm{for all } \mathbf{x},

and positive definite (PD), written A≻0\mathbf{A}\succ0, if the inequality is strict for every nonzero x\mathbf{x}. For instance, x⊤Sx=2x12+2x1x2+2x22=x12+x22+(x1+x2)2\mathbf x^\top\mathbf S\mathbf x=2x_1^2+2x_1x_2+2x_2^2=x_1^2+x_2^2+(x_1+x_2)^2 is strictly positive whenever x≠0\mathbf x\neq\mathbf 0, so S≻0\mathbf S\succ0, whereas (100−1)\left(\begin{smallmatrix}1&0\\0&-1\end{smallmatrix}\right) is neither PD nor PSD because e2\mathbf e_2 gives −1-1. Completing the square by hand quickly becomes impractical in higher dimensions, but the eigenvalues settle the question cleanly for any symmetric matrix.

Proposition (definiteness from eigenvalues). For symmetric A\mathbf{A},

A⪰0  ⟺  λi≥0 for all i,A≻0  ⟺  λi>0 for all i.\mathbf{A}\succeq0 \iff \lambda_i\ge0\ \textrm{for all } i, \qquad \mathbf{A}\succ0 \iff \lambda_i>0\ \textrm{for all } i .

Proof. Apply the spectral theorem to write A=VΛV⊤\mathbf{A}=\mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^\top, and switch to eigenvector coordinates y=V⊤x\mathbf{y}=\mathbf{V}^\top\mathbf{x}—an orthogonal change of basis that preserves lengths. Then

x⊤Ax=x⊤VΛV⊤x=y⊤Λy=∑i=1nλi yi2=∑i=1nλi (vi⊤x)2.(21.3.12)\mathbf{x}^\top\mathbf{A}\mathbf{x} = \mathbf{x}^\top\mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^\top\mathbf{x} = \mathbf{y}^\top\boldsymbol{\Lambda}\mathbf{y} = \sum_{i=1}^{n}\lambda_i\,y_i^2 = \sum_{i=1}^{n}\lambda_i\,(\mathbf{v}_i^\top\mathbf{x})^2 . \tag{21.3.12}

In eigenvector coordinates, the quadratic form is simply a weighted sum of squares whose weights are the eigenvalues. If every λi≥0\lambda_i\ge0, this sum is clearly non-negative. Conversely, plugging in x=vj\mathbf{x}=\mathbf{v}_j gives y=ej\mathbf y=\mathbf e_j and vj⊤Avj=λj\mathbf{v}_j^\top\mathbf{A}\mathbf{v}_j=\lambda_j, forcing λj≥0\lambda_j\ge0. The positive definite case follows by the same argument with strict inequalities, since y≠0\mathbf y\neq\mathbf 0 whenever x≠0\mathbf x\neq\mathbf 0. ■\blacksquare

Let us check (21.3.12) on S\mathbf S with x=e1\mathbf x=\mathbf e_1: the eigen-coordinates are y=V⊤e1=(1/2,1/2)\mathbf y=\mathbf V^\top\mathbf e_1=(1/\sqrt2,1/\sqrt2), and the weighted sum gives 3⋅12+1⋅12=23\cdot\tfrac12+1\cdot\tfrac12=2, matching e1⊤Se1=s11\mathbf e_1^\top\mathbf S\mathbf e_1=s_{11}. Three consequences account for most appearances of positive definiteness in deep learning:

  • PD implies invertible. If A≻0\mathbf{A}\succ0 and Ax=0\mathbf{A}\mathbf{x}=\mathbf 0, then x⊤Ax=0\mathbf{x}^\top\mathbf{A}\mathbf{x}=0, which forces x=0\mathbf{x}=\mathbf 0.
  • Gram and covariance matrices are PSD. For any matrix X\mathbf{X}, x⊤X⊤Xx=∥Xx∥2≥0\mathbf{x}^\top\mathbf{X}^\top\mathbf{X}\mathbf{x}=\|\mathbf{X}\mathbf{x}\|^2\ge0, so X⊤X⪰0\mathbf X^\top\mathbf X\succeq0. It is strictly PD if and only if X\mathbf{X} has full column rank (so that Xx=0\mathbf{X}\mathbf{x}=\mathbf 0 implies x=0\mathbf{x}=\mathbf 0). Because the sample covariance of centered data is a Gram matrix divided by the number of samples, it is always PSD.
  • A PD Hessian guarantees a strict local minimum. Suppose ff is twice continuously differentiable with ∇f(x∗)=0\nabla f(\mathbf x^*)=\mathbf 0, and its Hessian ∇2f(x∗)\nabla^2 f(\mathbf x^*) (the symmetric matrix of second partial derivatives) is PD. For any small step δ\boldsymbol\delta, the second-order Taylor expansion (Section 22.2.3.2) reads f(x∗+δ)=f(x∗)+12δ⊤∇2f(x∗)δ+o(∥δ∥2)f(\mathbf x^*+\boldsymbol\delta)=f(\mathbf x^*)+\tfrac12\boldsymbol\delta^\top\nabla^2 f(\mathbf x^*)\boldsymbol\delta+o(\|\boldsymbol\delta\|^2). By (21.3.12), the quadratic term is at least 12λmin⁡∥δ∥2>0\tfrac12\lambda_{\min}\|\boldsymbol\delta\|^2>0, so x∗\mathbf x^* is a strict local minimum. Note that this condition is sufficient rather than necessary: f(x)=x4f(x)=x^4 has a strict minimum at 00 even though its second derivative there is 00.

Positive definiteness also admits a fast algorithmic test, the Cholesky factorization: A≻0\mathbf{A}\succ0 if and only if A=LL⊤\mathbf{A}=\mathbf{L}\mathbf{L}^\top for a lower-triangular matrix L\mathbf{L} with positive diagonal entries. One direction is immediate: such an L\mathbf{L} is invertible, so x⊤Ax=∥L⊤x∥2>0\mathbf{x}^\top\mathbf{A}\mathbf{x}=\|\mathbf{L}^\top\mathbf{x}\|^2>0 for every nonzero x\mathbf{x}. Attempting a Cholesky factorization is the standard numerical way to test positive definiteness, and it is considerably cheaper than computing all eigenvalues. As a bonus, the same factor L\mathbf{L} transforms independent standard Gaussian samples z\mathbf z into samples Lz\mathbf L\mathbf z with covariance LL⊤=A\mathbf L\mathbf L^\top=\mathbf A.

Geometrically, the signs of the eigenvalues govern the shape of the surface z=x⊤Axz=\mathbf{x}^\top\mathbf{A}\mathbf{x} (Figure 21.3.4): a bowl when all eigenvalues are positive, a trough that is flat along any zero-eigenvalue direction, and a saddle when signs are mixed.

Figure 21.3.4:

The quadratic-form surface z=x⊤Axz=\mathbf{x}^\top\mathbf{A}\mathbf{x} for three diagonal matrices takes its shape from the eigenvalue signs: a bowl when all λi>0\lambda_i>0 (positive definite), a trough when one λi=0\lambda_i=0 (positive semidefinite), and a saddle for mixed signs (indefinite).

We can see the rank condition for Gram matrices directly in their eigenvalues. Below we compare a tall matrix X\mathbf{X} with independent columns, whose X⊤X\mathbf X^\top\mathbf X should be PD, against one whose second column is twice the first, which should yield a PSD matrix with a zero eigenvalue.

X_full = np.array([[1., 0.], [1., 1.], [0., 1.], [2., 1.]])  # rank 2
X_dep = np.array([[1., 2.], [1., 2.], [0., 0.], [2., 4.]])   # col 2 = 2*col 1
for X, name in [(X_full, 'full column rank'), (X_dep, 'dependent columns')]:
    eigvals = np.linalg.eigvalsh(X.T @ X).round(4)
    eigvals[np.abs(eigvals) < 1e-9] = 0.0  # clean up tiny round-off / -0.0
    print(f'{name}: eigenvalues of X^T X = {eigvals}')
full column rank: eigenvalues of X^T X = [1.1459 7.8541]
dependent columns: eigenvalues of X^T X = [ 0. 30.]

Both eigenvalues are strictly positive in the full-rank case. In the dependent case, one drops to zero: the quadratic form vanishes along (2,−1)(2,-1), the very direction that X\mathbf X maps to zero.

21.3.2.3 The Rayleigh Quotient#

Identity (21.3.12) does more than test signs: it turns the largest and smallest eigenvalues into the solutions of optimization problems. For a symmetric matrix A\mathbf{A}, define the Rayleigh quotient

R(x)=x⊤Axx⊤x,x≠0.R(\mathbf{x}) = \frac{\mathbf{x}^\top\mathbf{A}\mathbf{x}}{\mathbf{x}^\top\mathbf{x}}, \qquad \mathbf{x}\neq\mathbf 0 .

This measures the quadratic form per unit squared length, and whenever x\mathbf{x} is an eigenvector, R(x)R(\mathbf{x}) equals its eigenvalue. Throughout this subsection we order the eigenvalues by their signed values, λ1≥⋯≥λn\lambda_1\ge\cdots\ge\lambda_n, rather than by magnitude.

Proposition (Rayleigh). For symmetric A\mathbf{A} with eigenvalues λ1≥⋯≥λn\lambda_1\ge\cdots\ge\lambda_n,

λ1=max⁡x≠0R(x),λn=min⁡x≠0R(x),\lambda_1 = \max_{\mathbf{x}\neq\mathbf 0} R(\mathbf{x}), \qquad \lambda_n = \min_{\mathbf{x}\neq\mathbf 0} R(\mathbf{x}),

with the maximum and minimum attained at the corresponding eigenvectors.

Proof. Rescaling x\mathbf{x} leaves R(x)R(\mathbf{x}) unchanged, so we may restrict attention to unit vectors. Setting y=V⊤x\mathbf{y}=\mathbf{V}^\top\mathbf{x} preserves the norm (∥y∥=∥x∥=1\|\mathbf y\|=\|\mathbf x\|=1) and turns (21.3.12) into R(x)=∑iλiyi2R(\mathbf x)=\sum_i\lambda_i y_i^2. This is a weighted average of the eigenvalues with non-negative weights yi2y_i^2 summing to 11. Every average lies between its smallest and largest values, so λn≤R(x)≤λ1\lambda_n\le R(\mathbf x)\le\lambda_1. Putting all the weight onto a single coordinate, at x=v1\mathbf x=\mathbf v_1 or x=vn\mathbf x=\mathbf v_n, attains the two bounds. ■\blacksquare

For our running symmetric matrix S\mathbf S, this tells us that R(x)R(\mathbf x) ranges over [1,3][1,3], peaking along the eigenvector at 45∘45^\circ and reaching its minimum along the eigenvector at 135∘135^\circ. Every intermediate direction blends the eigenvalues 11 and 33 in proportion to its squared eigen-coordinates.

Maximizing over subspaces recovers all intermediate eigenvalues as well: the Courant--Fischer theorem states that λj=max⁡dim⁡U=j min⁡0≠x∈UR(x)\lambda_j=\max_{\dim U=j}\ \min_{\mathbf 0\neq\mathbf x\in U}R(\mathbf x), the highest guaranteed Rayleigh quotient across all jj-dimensional subspaces UU (Exercise 4d guides you through the proof).

Two applications of the extreme eigenvalues recur throughout this book. First, for any matrix A\mathbf A, the largest Rayleigh quotient of A⊤A\mathbf A^\top\mathbf A is max⁡x≠0∥Ax∥2/∥x∥2\max_{\mathbf x\neq\mathbf 0}\|\mathbf A\mathbf x\|^2/\|\mathbf x\|^2, the square of the largest factor by which A\mathbf A can stretch a vector. Second, consider gradient descent on a convex quadratic f(x)=12x⊤Axf(\mathbf x)=\tfrac12\mathbf x^\top\mathbf A\mathbf x with A≻0\mathbf A\succ0, whose update is x←(I−ηA)x\mathbf x\leftarrow(\mathbf I-\eta\mathbf A)\mathbf x. By (21.3.4), each eigen-coordinate is multiplied by 1−ηλi1-\eta\lambda_i at every step, so the iteration converges from every starting point if and only if ∣1−ηλi∣<1|1-\eta\lambda_i|\lt 1 for all ii—that is, 0<η<2/λmax⁡0\lt \eta\lt 2/\lambda_{\max}. The largest eigenvalue thus caps the step size (it is the smoothness constant LL of Section 23.1), and for step sizes η≤1/λmax⁡\eta\le1/\lambda_{\max} the smallest eigenvalue dictates the slowest contraction rate, 1−ηλmin⁡1-\eta\lambda_{\min}. Their ratio λmax⁡/λmin⁡\lambda_{\max}/\lambda_{\min} is the condition number of A\mathbf A, which Section 21.5.3.2 generalizes to arbitrary matrices.

21.3.2.4 Sample Covariance and the Marchenko--Pastur Law#

When we look for structure in high-dimensional data, we inspect the largest eigenvalues of the sample covariance matrix. To judge which eigenvalues are truly large, however, we first need a baseline: what do the eigenvalues look like when the data contain no structure at all? Suppose we draw nn samples of pure noise in dd dimensions, with independent coordinates of mean 00 and variance 11 (so the true covariance is I\mathbf I), and stack them as the rows of X∈Rn×d\mathbf X\in\mathbb R^{n\times d}. Do the eigenvalues of the sample covariance C=1nX⊤X\mathbf C=\tfrac1n\mathbf X^\top\mathbf X cluster near 11? For any unit vector w\mathbf w, the Rayleigh quotient w⊤Cw\mathbf w^\top\mathbf C\mathbf w is the sample variance of the data projected onto w\mathbf w. The extreme eigenvalues of C\mathbf C are therefore the sample variances along the most and least variable directions—the very quantities that principal component analysis interprets as structure (Section 21.5.2.2).

Surprisingly, they do not cluster near 11. Let d,n→∞d,n\to\infty while holding the aspect ratio c=d/n≤1c=d/n\le1 fixed. Then the histogram of eigenvalues of C\mathbf C converges to a deterministic density supported on the interval

[(1−c)2, (1+c)2],\bigl[(1-\sqrt c)^2,\ (1+\sqrt c)^2\bigr],

known as the Marchenko--Pastur bulk (Marchenko and Pastur, 1967), and provided the noise has a finite fourth moment, the extreme eigenvalues converge right to its edges. When c>1c>1, the matrix C\mathbf C has rank at most n<dn\lt d, so at least d−nd-n eigenvalues are identically zero in addition to the bulk. Even with four samples per dimension (c=1/4c=1/4), pure-noise eigenvalues spread all the way across [0.25,2.25][0.25,2.25]: the sample variance along the loudest random direction is more than double the true variance, while along the quietest it is only a quarter. At n=4000n=4000 and d=1000d=1000, this asymptotic limit is already strikingly accurate. Let us test it.

n, d = 4000, 1000                       # aspect ratio c = d / n = 1/4
X = np.random.randn(n, d)               # pure noise: true covariance I
ev = np.linalg.eigvalsh(X.T @ X / n)
c = d / n
print(f'eigenvalues of C: min {ev.min():.3f}, max {ev.max():.3f}')
print(f'Marchenko-Pastur edges: {(1 - c ** 0.5) ** 2:.3f}, '
      f'{(1 + c ** 0.5) ** 2:.3f}')
eigenvalues of C: min 0.247, max 2.238
Marchenko-Pastur edges: 0.250, 2.250

On every run, the smallest and largest eigenvalues land within a few hundredths of the predicted edges 0.250.25 and 2.252.25. Any eigenvalue falling inside this bulk is indistinguishable from pure noise; only an eigenvalue clearly above the upper edge provides evidence of genuine structure. Exercise 5 explores how strong a signal must be before its eigenvalue escapes the bulk.

Throughout this section we took two things for granted: that we can actually compute the eigenvalues of a matrix, and that those eigenvalues tell us what its powers do after a handful of steps just as well as after many. For large matrices and for matrices far from symmetric, neither assumption is safe. Section 21.4 takes up both.

21.3.3 Summary#

In eigenvector coordinates, a diagonalizable matrix acts as a list of scalars, Akx=∑iciλikvi\mathbf A^k\mathbf x=\sum_i c_i\lambda_i^k\mathbf v_i, explaining repeated application in Markov chains, deep linear networks, and gradient descent on quadratics. A full eigenbasis exists over C\mathbb C if and only if every eigenvalue's geometric multiplicity matches its algebraic multiplicity; otherwise Jordan blocks introduce polynomial factors in kk that can cause transient growth, while complex conjugate pairs correspond to rotation and scaling in an invariant plane. Real symmetric matrices avoid both pitfalls: they always have real eigenvalues and an orthonormal eigenbasis. Their quadratic forms become weighted sums of squares, so eigenvalue signs determine positive definiteness and the extreme eigenvalues are the extremes of the Rayleigh quotient. Finally, the eigenvalues of a pure-noise sample covariance spread across the Marchenko--Pastur interval, meaning that only eigenvalues above the upper bulk edge signal real structure.

21.3.4 Exercises#

  1. Trace, determinant, and definiteness. The identities (21.3.7) and (21.3.8) fix both eigenvalues of a 2×22\times2 matrix through their sum and product.

    1. Find the eigenvalues of (4114)\left(\begin{smallmatrix}4&1\\1&4\end{smallmatrix}\right) from its trace and determinant alone, without forming the characteristic polynomial. Then find its eigenvectors. Do the same for the surfer's matrix P\mathbf P, whose trace is 5/45/4 and determinant 1/41/4.
    2. Show that a symmetric 2×22\times2 matrix is positive definite if and only if its trace and its determinant are both positive. Which sign conditions on trace and determinant characterize positive semidefiniteness?
    3. Each of the matrices (2112)\left(\begin{smallmatrix}2&1\\1&2\end{smallmatrix}\right), (1221)\left(\begin{smallmatrix}1&2\\2&1\end{smallmatrix}\right), and (1111)\left(\begin{smallmatrix}1&1\\1&1\end{smallmatrix}\right) is the Hessian of the quadratic f(x)=12x⊤Axf(\mathbf{x})=\tfrac12\mathbf{x}^\top\mathbf{A}\mathbf{x} at its critical point 0\mathbf{0}. Use (b) to decide for each ff whether the origin is a strict minimum, a minimum that is not strict, or a saddle point. For the saddle point, give a direction along which ff decreases.
    4. Show that the Cholesky factor L\mathbf{L} of (abbc)\left(\begin{smallmatrix}a&b\\b&c\end{smallmatrix}\right) has the diagonal entries a\sqrt a and (ac−b2)/a\sqrt{(ac-b^2)/a}. Why do the conditions under which a factor with positive diagonal exists coincide with the test of (b)?
  2. Rank and zero eigenvalues. The section shows that the rank of a diagonalizable matrix equals the number of its nonzero eigenvalues, counted with multiplicity.

    1. Find the rank and the eigenvalues of N=(0100)\mathbf{N}=\left(\begin{smallmatrix}0&1\\0&0\end{smallmatrix}\right). Which step of the argument for diagonalizable matrices fails for N\mathbf{N}?
    2. Let g0g_0 be the geometric multiplicity of the eigenvalue 00 of an n×nn\times n matrix A\mathbf{A}, with g0=0g_0=0 when 00 is not an eigenvalue. Show that rank⁡A=n−g0\operatorname{rank}\mathbf{A}=n-g_0 for every square matrix. Conclude that the rank is at least the number of nonzero eigenvalues counted with algebraic multiplicity, with equality if and only if the eigenvalue 00 is not defective.
    3. The singular values of a matrix are σi=λi(A⊤A)\sigma_i=\sqrt{\lambda_i(\mathbf{A}^\top\mathbf{A})}, the square roots of the eigenvalues of the PSD matrix A⊤A\mathbf A^\top\mathbf A. Find the singular values of N\mathbf{N} and of the Jordan block Jm(0)\mathbf{J}_m(0) of Section 21.3.1.5. Compare the number of nonzero singular values with the rank and with the number of nonzero eigenvalues.
  3. The centering matrix. Let 1∈Rn\mathbf{1}\in\mathbb{R}^n be the all-ones vector and H=I−1n11⊤\mathbf{H}=\mathbf{I}-\tfrac1n\mathbf{1}\mathbf{1}^\top.

    1. Show that nI−11⊤n\mathbf{I}-\mathbf{1}\mathbf{1}^\top is positive semidefinite by writing x⊤(nI−11⊤)x\mathbf{x}^\top(n\mathbf{I}-\mathbf{1}\mathbf{1}^\top)\mathbf{x} as a sum of squares of the differences xi−xjx_i-x_j. Then find all eigenvalues of nI−11⊤n\mathbf{I}-\mathbf{1}\mathbf{1}^\top and their eigenvectors.
    2. Show that H\mathbf{H} is symmetric with H2=H\mathbf{H}^2=\mathbf{H}, and deduce its eigenvalues and its rank from (a).
    3. Let the rows of X∈Rn×d\mathbf{X}\in\mathbb{R}^{n\times d} be nn samples. Subtracting the sample mean from every row gives HX\mathbf{H}\mathbf{X}, so that the sample covariance is C=1nX⊤HX\mathbf{C}=\tfrac1n\mathbf{X}^\top\mathbf{H}\mathbf{X}. Show that C⪰0\mathbf{C}\succeq0 and rank⁡C≤n−1\operatorname{rank}\mathbf{C}\le n-1. How many zero eigenvalues does the sample covariance of 512512-dimensional embeddings computed from a minibatch of 256256 examples have at least? This is the case c=d/n>1c=d/n>1 of Section 21.3.2.4. Which operations on C\mathbf{C} does it rule out?

    Adapted from Gilbert Strang, MIT 18.065 Problem Sets, Problems for Lecture 13, Problem 4.

  4. [code] Accuracy of computed eigenvalues. ● The algorithm behind np.linalg.eigvals is backward stable: it returns the exact eigenvalues of a matrix A+E\mathbf{A}+\mathbf{E} with ∥E∥2\|\mathbf{E}\|_2 of the order of ϵmach∥A∥2\epsilon_{\textrm{mach}}\|\mathbf{A}\|_2, where ϵmach≈2.2×10−16\epsilon_{\textrm{mach}}\approx2.2\times10^{-16} in double precision (Golub and Van Loan, 1996). A small perturbation can move a defective eigenvalue by a fractional power of ε\varepsilon.

    1. Let e1,…,em\mathbf{e}_1,\ldots,\mathbf{e}_m be the standard basis vectors. Show that Jm(λ)+ε eme1⊤\mathbf{J}_m(\lambda)+\varepsilon\,\mathbf{e}_m\mathbf{e}_1^\top, which places ε\varepsilon in the lower-left corner of the Jordan block, has the eigenvalues λ+ε1/mω\lambda+\varepsilon^{1/m}\omega, where ω\omega ranges over the mm-th roots of unity.
    2. For m=1,…,4m=1,\ldots,4, form QJm(2)Q⊤\mathbf{Q}\mathbf{J}_m(2)\mathbf{Q}^\top with an orthogonal Q\mathbf{Q} taken from the QR factorization of a Gaussian matrix, and record the median over 2020 draws of max⁡i∣λ^i−2∣\max_i|\hat\lambda_i-2| for the computed eigenvalues λ^i\hat\lambda_i. Compare with ϵmach1/m\epsilon_{\textrm{mach}}^{1/m}. Repeat with the symmetric matrix Q(2I)Q⊤\mathbf{Q}(2\mathbf{I})\mathbf{Q}^\top.
    3. Let A\mathbf{A} and E\mathbf{E} be symmetric. Use the Rayleigh proposition of Section 21.3.2.3 to show that λmax⁡(A+E)≤λmax⁡(A)+∥E∥2\lambda_{\max}(\mathbf{A}+\mathbf{E})\le\lambda_{\max}(\mathbf{A})+\|\mathbf{E}\|_2 and λmin⁡(A+E)≥λmin⁡(A)−∥E∥2\lambda_{\min}(\mathbf{A}+\mathbf{E})\ge\lambda_{\min}(\mathbf{A})-\|\mathbf{E}\|_2. How does this explain the symmetric result of (b)?
    4. Prove the Courant--Fischer theorem λj=max⁡dim⁡U=j min⁡0≠x∈UR(x)\lambda_j=\max_{\dim U=j}\ \min_{\mathbf 0\neq\mathbf x\in U}R(\mathbf x) for symmetric A\mathbf A with λ1≥⋯≥λn\lambda_1\ge\cdots\ge\lambda_n. For the upper bound, intersect UU with span⁡(vj,…,vn)\operatorname{span}(\mathbf v_j,\ldots,\mathbf v_n), which has dimension n−j+1n-j+1, so the intersection is at least a line; for the lower bound take U=span⁡(v1,…,vj)U=\operatorname{span}(\mathbf v_1,\ldots,\mathbf v_j). Deduce Weyl's inequality ∣λj(A+E)−λj(A)∣≤∥E∥2|\lambda_j(\mathbf A+\mathbf E)-\lambda_j(\mathbf A)|\le\|\mathbf E\|_2 for every jj, which extends (c) to all eigenvalues.
  5. [code] Spikes above the bulk. ● Section 21.3.2.4 treats the Marchenko--Pastur bulk as the range of pure-noise eigenvalues. Suppose that the data contain one real direction: the nn samples have independent Gaussian coordinates of variance 11, except the first coordinate, whose variance is 1+β1+\beta. For n→∞n\to\infty with c=d/nc=d/n fixed, Baik and Silverstein (2006) show that the largest eigenvalue of C=1nX⊤X\mathbf{C}=\tfrac1n\mathbf{X}^\top\mathbf{X} converges to

λmax⁡→{(1+c)2,β≤c,(1+β)(1+c/β),β>c.\lambda_{\max}\to\begin{cases}(1+\sqrt c)^2, & \beta\le\sqrt c,\\ (1+\beta)\left(1+c/\beta\right), & \beta>\sqrt c.\end{cases}
  1. For n=2000n=2000 and d=500d=500, compute the largest eigenvalue of C\mathbf{C} for β∈{0,0.3,0.5,0.7,1,2}\beta\in\{0,0.3,0.5,0.7,1,2\}, averaged over five draws, and compare with the prediction.
  2. Fix d=500d=500 and β=0.4\beta=0.4. Use the formula to find the sample size nn above which the largest eigenvalue leaves the bulk. Then increase the number of samples through n∈{500,1000,2000,4000,8000}n\in\{500,1000,2000,4000,8000\}, and compare the largest eigenvalue with the bulk edge, with the prediction, and with the largest eigenvalue for β=0\beta=0 at the same nn. Why is the separation hard to see at n=4000n=4000?
  3. A practitioner keeps the principal components whose eigenvalues exceed the bulk edge. How large must the variance of a direction be at c=1/4c=1/4 for it to be kept? How many samples per dimension are needed to detect a direction whose variance exceeds the others by 10%10\%?

Discussions