Chapter 9: Symmetric and positive definite matrices

Previous: LA 08 Eigenvalues and Eigenvectors | LA 00 Course Map | Next: LA 10 Singular Value Decomposition

The big idea

A symmetric matrix is the best-behaved kind of matrix: it is a pure stretch along perpendicular axes, with real stretch factors. When all those stretch factors are positive, the matrix is positive definite, and it describes a bowl-shaped function with exactly one lowest point. That is why these matrices run through optimization, statistics and control.

In this chapter you will learn to
  1. State the spectral theorem and explain it with a picture.
  2. Diagonalize a symmetric matrix with an orthogonal matrix, .
  3. Write and read a quadratic form .
  4. Test whether a matrix is positive definite in four different ways.
  5. Use the Hessian to classify minima, maxima and saddle points.
Before you start

You need eigenvalues and diagonalization (LA 08 Eigenvalues and Eigenvectors) and orthogonal matrices (LA 06 Orthogonality and Least Squares). One calculus idea is used in section 9.6: a minimum of has and .


9.1 Symmetric matrices

Definition: symmetric

A square matrix is symmetric if , meaning for all . The matrix is a mirror image of itself across its main diagonal.

Where they come from

Symmetric matrices are not rare special cases. They appear whenever a matrix describes a relationship between pairs that does not depend on order:

SourceWhy symmetric
for any
covariance matrix
Hessian (second derivatives)
distance or similarity matrix
undirected graph’s adjacency matrixedges have no direction
robot mass (inertia) matrixfrom kinetic energy

9.2 The spectral theorem

Spectral theorem

Every real symmetric matrix

  1. has only real eigenvalues, and
  2. has a full set of orthonormal eigenvectors (perpendicular, unit length).

Therefore

where is an orthogonal matrix whose columns are the eigenvectors, and is diagonal with the eigenvalues.

Compare with general diagonalization, :

General matrixSymmetric matrix
eigenvalues may be complexalways real
eigenvectors may be skewedalways perpendicular
may not be diagonalizablealways diagonalizable
need to compute , free

“Spectral” refers to the spectrum, the set of eigenvalues.

The picture

says acts in three steps:

  1. rotates space so the eigenvector directions line up with the coordinate axes.
  2. stretches along each axis by its eigenvalue.
  3. rotates back.

So a symmetric matrix is a pure stretch along perpendicular axes. It never shears or twists. A unit circle becomes an ellipse whose axes are the eigenvectors.

Why eigenvectors of different eigenvalues are perpendicular

Let and with . Compute the number in two ways.

  • Directly: .
  • Using symmetry, , so .

Both are the same number, so . Since , we must have : perpendicular.

The proof used symmetry in exactly one place. For non-symmetric matrices the step fails, and so does perpendicularity (in chapter 8’s example 8.1, the eigenvectors and were not perpendicular).

Worked example 9.1

Trace 4, determinant 3, so : and .

  • : , eigenvector .
  • : , eigenvector .

Perpendicular: ✓. Normalize to unit length:

Interpretation. stretches by 3 along the diagonal direction and leaves the anti-diagonal direction unchanged.

Sum of rank-one pieces

Multiplying out column by column gives

Each is the projection onto the line through (chapter 6). So is “project onto each eigen-direction, scale by its eigenvalue, add up”. For example 9.1:


9.3 Quadratic forms

Definition

A symmetric matrix defines a scalar function of a vector:

This is called a quadratic form: every term has degree two.

Worked example 9.2. For :

Reading a quadratic form off a matrix (and back)

  • Each diagonal entry gives the term .
  • Each off-diagonal pair gives the cross term (it appears twice).

Going backwards. : put and on the diagonal, and half the cross coefficient, , in both off-diagonal spots:

Eigenvector coordinates remove the cross terms

Substitute (so are the eigenvector coordinates):

No cross terms. In the right coordinates, a quadratic form is just a weighted sum of squares, and its shape is decided entirely by the signs of the eigenvalues.

For example 9.2: , where and .


9.4 Positive definite matrices

Definition

Definition: positive definite

A symmetric matrix is positive definite if

It is positive semidefinite if for every .

Think of as an “energy” or “cost”. Positive definite means every nonzero has positive energy.

Four equivalent tests

For a symmetric matrix, these are all equivalent. Any one of them proves positive definiteness:

TestPositive definite when
1. eigenvaluesall
2. pivotsall pivots in elimination (no row swaps)
3. leading minorsdeterminants of the top-left , , …, blocks are all
4. factorization for some with independent columns

Why test 1 works: from section 9.3, . If all , this is positive unless every , i.e. unless .

Why test 4 works: , and it is zero only if , which (for independent columns) means .

Which test to use by hand

For : the minor test. is positive definite exactly when and .
For bigger matrices: the pivot test (run elimination, check every pivot is positive).

Worked examples

Worked example 9.3. . Minors: and . Positive definite. (Eigenvalues agree.)

Worked example 9.4. . Minors: but . Not positive definite. Find a witness: gives .

Positive entries are not enough

Example 9.4 has all positive entries yet is not positive definite. What matters is that the diagonal “outweighs” the off-diagonal coupling.

Worked example 9.5 (3×3, pivot test).

Elimination: gives second pivot . Then gives third pivot . Pivots , all positive: positive definite. (This matrix appears whenever you discretize a second derivative, for example in physics simulations and smoothing.)


9.5 The picture: bowls, troughs and saddles

Plot over the plane. The signs of the eigenvalues decide the shape:

EigenvaluesNameSurface
all positive definitebowl: unique lowest point at the origin
all , some positive semidefinitetrough: flat along some direction
some , some indefinitesaddle: up one way, down another
all negative definitedome: unique highest point

Level sets are ellipses

For positive definite , the curves are ellipses (ellipsoids in 3-D and beyond):

  • The axes point along the eigenvectors.
  • The half-length along eigenvector is .

Why: in eigen-coordinates the curve is . Setting gives .

So a large eigenvalue means a steep wall and a short axis; a small eigenvalue means a gentle slope and a long axis.

Worked example 9.6. For , the ellipse has its short axis along , of half-length , and its long axis along , of half-length .


9.6 Why optimization cares: the Hessian

The second derivative test in many dimensions

For a function of one variable, a critical point () is a minimum if . For a function of many variables, the second derivative is a matrix, the Hessian:

It is symmetric. Near a critical point (where the gradient is zero), Taylor’s theorem says

So the function looks like a quadratic form near , and:

at the critical pointType
positive definitelocal minimum
negative definitelocal maximum
indefinitesaddle point
semidefinite (some zero eigenvalue)test is inconclusive

Worked example 9.7. .

  • Gradient: . Set to zero: , then , so , . Critical point .
  • Hessian: , positive definite (example 9.3).
  • So is a minimum, with value .

Worked example 9.8. . Critical point . , eigenvalues : a saddle. Moving along goes up; moving along goes down. Saddle points are extremely common in the loss landscapes of neural networks.

Conditioning: stretched bowls are slow

The ratio of the Hessian measures how stretched the bowl is. A round bowl (ratio 1) is easy for gradient descent: the steepest-descent direction points straight at the minimum. A long, narrow valley (large ratio) makes gradient descent zigzag across the steep walls while creeping along the flat floor.

The animation in 01 Math for Learning shows exactly this for , whose Hessian has eigenvalues 1 and 5. Chapter 12 quantifies it.


9.7 Cholesky factorization

Every positive definite matrix can be written as

with lower triangular with positive diagonal entries. Think of as a matrix square root of .

Worked example 9.9. For , try :

So , , .

Uses.

  • Solving about twice as fast as LU, and very stable.
  • Testing positive definiteness: Cholesky succeeds exactly when is positive definite.
  • Sampling correlated noise: if has independent standard normal entries, then has covariance (PS 07 The Multivariate Gaussian).

Summary

IdeaFact
symmetric
spectral theoremreal eigenvalues, orthonormal eigenvectors,
quadratic form in eigen-coordinates
positive definite; all ; all pivots ; all leading minors
level setsellipses with half-axes along eigenvectors
Hessian testPD: min; ND: max; indefinite: saddle
Cholesky for positive definite

Three facts to remember:

  1. Symmetric means a pure stretch along perpendicular axes.
  2. Positive definite means a bowl with a single bottom.
  3. The eigenvalues of the Hessian tell you min, max, or saddle, and how hard the bowl is to descend.

Exercises

Part A: warm-up

A1. Write the symmetric matrix for .

A2. Is positive definite? Use two different tests.

A3. Find the eigenvalues of and classify the shape of .

A4. Find and for .

Part B: core

B1. Find and classify the critical points of .

B2. For , describe the ellipse : axis directions and half-lengths.

B3. For which values of is positive definite?

B4. Find the Cholesky factor of .

B5. A covariance matrix is . Find the directions of greatest and least spread, and the standard deviation in each.

Part C: explain and prove

C1. Prove that if is positive definite then every diagonal entry is positive. (Hint: choose .)

C2. Prove that if is positive definite, it is invertible, and is also positive definite.

C3. Prove that is always positive semidefinite, for any matrix .

C4 (ridge regression). Prove that is positive definite for any matrix and any . Explain why this means ridge regression, which solves , always has exactly one solution, even when the columns of are dependent.

C5. Show that the eigenvalues of a symmetric matrix are real, for matrices, using the discriminant of the characteristic polynomial.

Part D: practise with code

D1. np.linalg.eigh(S) is the eigen-solver for symmetric matrices. Use it on example 9.5 and confirm all eigenvalues are positive. Check that the eigenvector matrix satisfies Q.T @ Q ≈ I.

D2. Use np.linalg.cholesky on a positive definite matrix and on . What happens in the second case?

D3. Draw contour plots (plt.contour) of for , , and . Label each as bowl, stretched bowl, tilted bowl, or saddle.

D4. Run gradient descent from on the bowls and , with the largest stable step size for each (). Count the steps needed to reach .


Where this is used

  • Covariance matrices and their uncertainty ellipses (PS 07 The Multivariate Gaussian, 04 Perception and State).
  • Control costs use positive definite weights so the cost has a unique minimum (03 Dynamics and Feedback).
  • Mass matrices of robots are positive definite, because kinetic energy is positive for any motion.
  • Second-order optimizers (Newton’s method) use the Hessian directly.

Next: LA 10 Singular Value Decomposition, which extends “stretch along perpendicular axes” to every matrix.