Chapter 9: Symmetric and positive definite matrices
Previous: LA 08 Eigenvalues and Eigenvectors | LA 00 Course Map | Next: LA 10 Singular Value Decomposition
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.
- State the spectral theorem and explain it with a picture.
- Diagonalize a symmetric matrix with an orthogonal matrix, .
- Write and read a quadratic form .
- Test whether a matrix is positive definite in four different ways.
- Use the Hessian to classify minima, maxima and saddle points.
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
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:
| Source | Why symmetric |
|---|---|
| for any | |
| covariance matrix | |
| Hessian (second derivatives) | |
| distance or similarity matrix | |
| undirected graph’s adjacency matrix | edges have no direction |
| robot mass (inertia) matrix | from kinetic energy |
9.2 The spectral theorem
Every real symmetric matrix
- has only real eigenvalues, and
- 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 matrix | Symmetric matrix |
|---|---|
| eigenvalues may be complex | always real |
| eigenvectors may be skewed | always perpendicular |
| may not be diagonalizable | always diagonalizable |
| need to compute | , free |
“Spectral” refers to the spectrum, the set of eigenvalues.
The picture
says acts in three steps:
- rotates space so the eigenvector directions line up with the coordinate axes.
- stretches along each axis by its eigenvalue.
- 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:
- Find the eigenvalues and orthonormal eigenvectors of .
- Find the eigenvalues of . Are the eigenvectors perpendicular?
Answers. 1. with , with . 2. and , with and : perpendicular, as the theorem promises.
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
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:
| Test | Positive definite when |
|---|---|
| 1. eigenvalues | all |
| 2. pivots | all pivots in elimination (no row swaps) |
| 3. leading minors | determinants 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 .
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 .
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.)
- Is positive definite?
- For which is positive definite?
- Is positive definite? Semidefinite?
Answers. 1. , : yes. 2. , so . 3. Minor , not definite. Eigenvalues and : semidefinite. gives .
9.5 The picture: bowls, troughs and saddles
Plot over the plane. The signs of the eigenvalues decide the shape:
| Eigenvalues | Name | Surface |
|---|---|---|
| all | positive definite | bowl: unique lowest point at the origin |
| all , some | positive semidefinite | trough: flat along some direction |
| some , some | indefinite | saddle: up one way, down another |
| all | negative definite | dome: 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 point | Type |
|---|---|
| positive definite | local minimum |
| negative definite | local maximum |
| indefinite | saddle 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
| Idea | Fact |
|---|---|
| symmetric | |
| spectral theorem | real eigenvalues, orthonormal eigenvectors, |
| quadratic form | in eigen-coordinates |
| positive definite | ; all ; all pivots ; all leading minors |
| level sets | ellipses with half-axes along eigenvectors |
| Hessian test | PD: min; ND: max; indefinite: saddle |
| Cholesky | for positive definite |
Three facts to remember:
- Symmetric means a pure stretch along perpendicular axes.
- Positive definite means a bowl with a single bottom.
- 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 .
A1. .
A2. Minors: and . Eigenvalues: trace 4, det 2, , both positive. Yes.
A3. and : indefinite, a saddle.
A4. Eigenvalues and with eigenvectors and . , .
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.
B1. Gradient at and . Hessian . At : , minimum. At : , saddle.
B2. Eigenvalues along and along . Half-lengths along and along .
B3. Leading minors: ; ; full determinant . So .
B4. so ; so ; so . .
B5. Eigenvalues along and along . Standard deviations and . The data spreads most along the diagonal: the two variables are positively correlated.
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.
C1. , and this must be positive.
C2. All eigenvalues are positive, so none is zero and is invertible. has eigenvalues .
C3. .
C4. . The first term is at least 0 and the second is strictly positive when . Positive definite matrices are invertible, so the system has exactly one solution. Adding lifts every eigenvalue of by , so none can be zero.
C5. For : . Discriminant , a sum of squares. So the roots are real.
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 .
D2. It raises LinAlgError: Matrix is not positive definite. That is a practical positive-definiteness test.
D4. The round bowl converges in a few steps; the stretched bowl takes many more, because the safe step size is limited by the steep direction while progress is limited by the flat one.
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.