Skip to main content
© 2026 ePowerAI — free, open courseware. No login required.
CoursesContact
ePOWERAI
CoursesContact
Week 12: Symmetric and Positive Definite Matrices
Linear Algebra

Foundations

  1. 01Start Here: Python and the Math the Labs Use
  1. 02Week 1: Vectors and Linear Combinations
  2. 03Week 2: Linear Transformations and Matrices
  3. 04Week 3: Elimination and LU Factorization
  4. 05Week 4: Determinants
  5. 06Week 5: Vector Spaces, Independence, and Basis
  6. 07Week 6: The Four Fundamental Subspaces
  7. 08Week 7: Orthogonality and Projections
  8. 09Week 8: Least Squares and QR
  9. 10Week 9: Eigenvalues and Eigenvectors
  10. 11Week 10: Diagonalization and Markov Matrices
  11. 12Week 11: Differential Equations
  12. 13Week 12: Symmetric and Positive Definite Matrices
  13. 14Week 13: The SVD and Complex Matrices
  14. 15Week 14: PCA, the Fourier Matrix and the FFT
Week 12· Linear Algebra7 min read

Week 12: Symmetric and Positive Definite Matrices

Learning Outcomes
  • State the spectral theorem for symmetric matrices
  • Explain why the eigenvectors of a symmetric matrix can be chosen orthogonal
  • Test a matrix for positive definiteness using eigenvalues, pivots, or leading determinants
  • Read the surface z=xTAxz = x^TAxz=xTAx and its level sets as a bowl, a trough or a saddle from the signs of the eigenvalues
Prerequisites

Background knowledge assumed:

  • Eigenvalues and eigenvectors
  • Orthogonality

Recommended: Review Week 9: Eigenvalues and Eigenvectors and Week 7: Orthogonality and Projections before starting.

You fill in a covariance matrix by hand, call np.linalg.cholesky, and get LinAlgError: Matrix is not positive definite. The matrix, (1221)\begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix}(12​21​), is symmetric with every entry positive. It is still no covariance. The signs of the eigenvalues decide that, and they set the shape of z=xTAxz = x^TAxz=xTAx.

The surface f(x) = xᵀAx over a disc of radius 1.5, with the level set xᵀAx = 1 drawn on it. Along q₁ = (1, 1)/√2 the surface rises as 3t². Along q₂ = (1, −1)/√2 it follows λ₂t², which the slider sets. λ₂ = 1. A = [[2, 1], [1, 2]]. Eigenvalues 3 and 1. Pivots 2 and 1.5. Leading determinants 2 and 3. Positive definite, so the surface is a bowl.

λ₂ = 1. A = [[2, 1], [1, 2]]. Eigenvalues 3 and 1. Pivots 2 and 1.5. Leading determinants 2 and 3. Positive definite, so the surface is a bowl.

The surface is z=xTAxz = x^TAxz=xTAx for a symmetric AAA with eigenvalues 333 and λ2\lambda_2λ2​. The slider moves λ2\lambda_2λ2​: above 000 a bowl, at 000 a trough, below 000 a saddle. The solid contour is xTAx=1x^TAx = 1xTAx=1. The caption prints the three tests.

The spectral theorem#

A real matrix is symmetric when A=ATA = A^TA=AT, as covariance matrices and Hessians are. The spectral theorem says that every real symmetric n×nn \times nn×n matrix has nnn real eigenvalues and an orthonormal basis of eigenvectors:

A=QΛQT,QTQ=I.A = Q\Lambda Q^T, \qquad Q^TQ = I.A=QΛQT,QTQ=I.

Against A=SΛS−1A = S\Lambda S^{-1}A=SΛS−1 from Week 10, no eigenvalue is complex, and S−1S^{-1}S−1 is just QTQ^TQT.

Why the eigenvectors are orthogonal. Take Aq1=λ1q1Aq_1 = \lambda_1 q_1Aq1​=λ1​q1​ and Aq2=λ2q2Aq_2 = \lambda_2 q_2Aq2​=λ2​q2​ with λ1≠λ2\lambda_1 \neq \lambda_2λ1​=λ2​. Then

λ1q2Tq1=q2TAq1=(Aq2)Tq1=λ2q2Tq1,\lambda_1 q_2^T q_1 = q_2^T A q_1 = (A q_2)^T q_1 = \lambda_2 q_2^T q_1,λ1​q2T​q1​=q2T​Aq1​=(Aq2​)Tq1​=λ2​q2T​q1​,

so (λ1−λ2) q2Tq1=0(\lambda_1 - \lambda_2)\, q_2^T q_1 = 0(λ1​−λ2​)q2T​q1​=0 and q2Tq1=0q_2^T q_1 = 0q2T​q1​=0. The middle step uses AT=AA^T = AAT=A. Within a repeated eigenvalue, Gram–Schmidt (Week 8) picks an orthonormal basis.

The scene builds AAA from this formula. It fixes q1=(1,1)/2q_1 = (1, 1)/\sqrt{2}q1​=(1,1)/2​ with λ1=3\lambda_1 = 3λ1​=3, and q2=(1,−1)/2q_2 = (1, -1)/\sqrt{2}q2​=(1,−1)/2​ with eigenvalue λ2\lambda_2λ2​:

A=3 q1q1T+λ2 q2q2T=12(3+λ23−λ23−λ23+λ2).A = 3\,q_1q_1^T + \lambda_2\,q_2q_2^T = \frac{1}{2}\begin{pmatrix} 3 + \lambda_2 & 3 - \lambda_2 \\ 3 - \lambda_2 & 3 + \lambda_2 \end{pmatrix}.A=3q1​q1T​+λ2​q2​q2T​=21​(3+λ2​3−λ2​​3−λ2​3+λ2​​).

At the default λ2=1\lambda_2 = 1λ2​=1 this is A=(2112)A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}A=(21​12​). Trace 444 and determinant 333 give λ2−4λ+3=0\lambda^2 - 4\lambda + 3 = 0λ2−4λ+3=0, so the eigenvalues are 333 and 111.

The quadratic form in eigen-coordinates#

The quadratic form of a symmetric A=(abbc)A = \begin{pmatrix} a & b \\ b & c \end{pmatrix}A=(ab​bc​) is

xTAx=a x12+2b x1x2+c x22.x^TAx = a\,x_1^2 + 2b\,x_1 x_2 + c\,x_2^2.xTAx=ax12​+2bx1​x2​+cx22​.

Change to eigen-coordinates y=QTxy = Q^Txy=QTx, so x=Qyx = Qyx=Qy. The cross term disappears:

xTAx=yTQTAQ y=yTΛy=λ1y12+λ2y22.x^TAx = y^T Q^TAQ\, y = y^T \Lambda y = \lambda_1 y_1^2 + \lambda_2 y_2^2.xTAx=yTQTAQy=yTΛy=λ1​y12​+λ2​y22​.

In the scene that is 3y12+λ2y223y_1^2 + \lambda_2 y_2^23y12​+λ2​y22​. Two parabolas are drawn on the surface. The dashed one, along q1q_1q1​, is z=3t2z = 3t^2z=3t2 at every setting. The amber one, along q2q_2q2​, is z=λ2t2z = \lambda_2 t^2z=λ2​t2, which goes flat and then opens down as the slider crosses 000.

Three tests for positive definiteness#

AAA is positive definite (A≻0A \succ 0A≻0) when xTAx>0x^TAx > 0xTAx>0 for every x≠0x \neq 0x=0. It is positive semidefinite when xTAx≥0x^TAx \ge 0xTAx≥0, and indefinite when the form takes both signs. A Hessian that is positive definite everywhere makes a function strictly convex (Optimization Week 2). Three tests agree for every real symmetric AAA (Strang, §6.4):

  1. Eigenvalues. Every λi>0\lambda_i > 0λi​>0. Use xTAx=∑λiyi2x^TAx = \sum \lambda_i y_i^2xTAx=∑λi​yi2​ with ∥y∥=∥x∥\|y\| = \|x\|∥y∥=∥x∥.
  2. Pivots. Elimination without row exchanges gives positive pivots. Equivalently, A=LDLTA = LDL^TA=LDLT has a positive DDD, and Cholesky succeeds.
  3. Leading determinants. Every upper-left k×kk \times kk×k determinant is positive (Sylvester's criterion). For 2×22 \times 22×2 that is a>0a > 0a>0 and ac−b2>0ac - b^2 > 0ac−b2>0.

In the scene, a=(3+λ2)/2a = (3 + \lambda_2)/2a=(3+λ2​)/2 and det⁡A=3λ2\det A = 3\lambda_2detA=3λ2​, so the second pivot is

d2=det⁡Aa=6λ23+λ2.d_2 = \frac{\det A}{a} = \frac{6\lambda_2}{3 + \lambda_2}.d2​=adetA​=3+λ2​6λ2​​.

At λ2=1\lambda_2 = 1λ2​=1 the pivots are 222 and 1.51.51.5, the determinants are 222 and 333, and all three tests pass. All three change sign at the same slider setting, λ2=0\lambda_2 = 0λ2​=0, because each one carries the factor λ2\lambda_2λ2​.

Positive entries prove nothing. Set the slider to λ2=−1\lambda_2 = -1λ2​=−1. Then A=(1221)A = \begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix}A=(12​21​), the matrix from the opening. Every entry is positive, and the surface is a saddle: at x=(1,−1)x = (1, -1)x=(1,−1) the form is 1−4+1=−21 - 4 + 1 = -21−4+1=−2. A positive diagonal is necessary, since a=e1TAe1a = e_1^TAe_1a=e1T​Ae1​, but not sufficient.

Level sets: ellipse, lines, hyperbola#

In eigen-coordinates the level set xTAx=1x^TAx = 1xTAx=1 is 3y12+λ2y22=13y_1^2 + \lambda_2 y_2^2 = 13y12​+λ2​y22​=1.

  • λ2>0\lambda_2 > 0λ2​>0: an ellipse with half-axes 1/31/\sqrt{3}1/3​ along q1q_1q1​ and 1/λ21/\sqrt{\lambda_2}1/λ2​​ along q2q_2q2​. A large eigenvalue gives a short axis.
  • λ2=0\lambda_2 = 0λ2​=0: two lines y1=±1/3y_1 = \pm 1/\sqrt{3}y1​=±1/3​, parallel to the trough's floor along q2q_2q2​.
  • λ2<0\lambda_2 < 0λ2​<0: a hyperbola. The form is positive near q1q_1q1​ and negative near q2q_2q2​.

Next week. For any BBB, BTBB^TBBTB is positive semidefinite, since xTBTBx=∥Bx∥2x^TB^TBx = \|Bx\|^2xTBTBx=∥Bx∥2.


Knowledge Check#

Exercise · Fill in the blank

Set the slider to λ₂ = 2. The caption shows A = [[2.5, 0.5], [0.5, 2.5]]. What is det A?

Question 1 of 3

Set the slider to λ₂ = 0. What does the level set xᵀAx = 1 look like?

A closed ellipse
A hyperbola
Two parallel lines
A single point

Browser lab: three tests at three slider settings#

Build the scene's matrix at three slider settings, run the three tests and Cholesky, and plot xTAx=1x^TAx = 1xTAx=1.

python · runs in browser
import numpy as np
import matplotlib.pyplot as plt

def scene_matrix(lam2):
    # 3 q1 q1ᵀ + lam2 q2 q2ᵀ with q1 = (1, 1)/√2 and q2 = (1, −1)/√2
    return 0.5 * np.array([[3 + lam2, 3 - lam2], [3 - lam2, 3 + lam2]])

u, v = np.meshgrid(np.linspace(-1.5, 1.5, 301), np.linspace(-1.5, 1.5, 301))
fig, axes = plt.subplots(1, 3, figsize=(10, 3.6))

for ax, lam2 in zip(axes, [1.0, 0.0, -1.0]):
    A = scene_matrix(lam2)
    eig = np.linalg.eigvalsh(A)
    det = A[0, 0] * A[1, 1] - A[0, 1] ** 2
    pivots = [A[0, 0], det / A[0, 0]]
    minors = [A[0, 0], det]
    try:
        np.linalg.cholesky(A)
        chol = "succeeds"
    except np.linalg.LinAlgError:
        chol = "fails"
    print(f"lam2 = {lam2:+.0f}  A = {A.round(2).tolist()}")
    print(f"   eigenvalues {eig.round(3)}  pivots {np.round(pivots, 3)}  minors {np.round(minors, 3)}  Cholesky {chol}")

    f = A[0, 0] * u**2 + 2 * A[0, 1] * u * v + A[1, 1] * v**2
    ax.contour(u, v, f, levels=[1.0])
    ax.set_aspect("equal")
    ax.set_title(f"λ₂ = {lam2:+.0f}: xᵀAx = 1")

plt.tight_layout()
plt.show()

The printed values match the caption at each setting. At 000 the exact second pivot is 000, so Cholesky's verdict there turns on rounding. Test a semidefinite matrix by its eigenvalues, with a tolerance. The plots show an ellipse, two lines and a hyperbola. Add -2.0 to the list and predict the second pivot first: 6λ2/(3+λ2)=−126\lambda_2/(3 + \lambda_2) = -126λ2​/(3+λ2​)=−12.

Key takeaways#

The signs of the eigenvalues of a symmetric AAA set the shape of z=xTAxz = x^TAxz=xTAx. With λ1=3\lambda_1 = 3λ1​=3, a positive λ2\lambda_2λ2​ gives a bowl, zero a trough, and negative a saddle. Eigenvalues, pivots and leading determinants agree, and in the scene all three flip at λ2=0\lambda_2 = 0λ2​=0. Positive entries prove nothing, since (1221)\begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix}(12​21​) is a saddle. The level set xTAx=1x^TAx = 1xTAx=1 is an ellipse with half-axes 1/λi1/\sqrt{\lambda_i}1/λi​​ only when every λi>0\lambda_i > 0λi​>0.

Further reading#

  • Strang, G. Introduction to Linear Algebra, 6th ed. — §6.2 Symmetric Matrices, §6.4 Positive Definite Matrices
  • Trefethen, L.N. & Bau, D. Numerical Linear Algebra — Lecture 25 (Spectral Theorem)

Reading is free. PDF and ePub unlock with the newsletter. Join once and every lesson opens in this browser.

← Previous
Week 11: Differential Equations
Next →
Week 13: The SVD and Complex Matrices
On this page
  • The spectral theorem
  • The quadratic form in eigen-coordinates
  • Three tests for positive definiteness
  • Level sets: ellipse, lines, hyperbola
  • Knowledge Check
  • Browser lab: three tests at three slider settings
  • Key takeaways
  • Further reading