ML Study Hub

Home / MLF / Week 5

Week 5 · Symmetric matrices: the well-behaved ones

Official syllabus line: Linear Algebra - Symmetric matrices
About 80 minQuiz 2 material (see exam radar)BSCS2004 · Harish Guruprasad Ramaswamy, Arun Rajkumar, Prashanth LA
Before you start: Week 4 (eigenvalues and eigenvectors, diagonalisation).
Watch first: the animated story of this weekAbout 1-2 minutes of real 3D animation with a friendly voice. Pause any time.
Read the words of the video
  1. Last week, some math shapes had crooked special directions. This week, we meet the well-behaved ones! Imagine a matrix that's a mirror image across its middle line. It's like stretching a grid, such as a window pane, perfectly straight in two directions, with no strange twisting. Everything stays neat and tidy.
  2. For these special symmetric matrices, everything is tidy! Their special numbers, called eigenvalues, are always real. Even better, their special directions, or eigenvectors, are always perfectly perpendicular to each other. This neat behaviour is why these matrices are super important in machine learning, making data analysis much simpler.
  3. Let's try one! A symmetric matrix like 'two, one; one, two' has two special numbers: three and one. And its special directions? They are indeed perfectly perpendicular. We can rewrite the matrix using these perpendicular directions and the special numbers, making it much easier to understand and work with. It's a neat trick!
  4. For your exams, remember that symmetric matrices always have real eigenvalues and perpendicular eigenvectors. Also, positive definite matrices have all positive eigenvalues, like a bowl shape! This tidy family is super important for understanding data in machine learning, helping us solve complex problems with confidence and clarity. You've got this!

The one-minute story

Think of it like this

Last week you met matrices whose special directions can be crooked: two eigenvectors could lean towards each other at any odd angle, and some matrices had no real special directions at all.

This week is about the well-behaved family. Imagine a matrix that is a mirror image of itself across its diagonal: the number in row 1, column 2 equals the number in row 2, column 1. That is a symmetric matrix. It is like stretching a sheet along two perpendicular axes, like the grid of a window, with no weird shearing.

Everything is tidy for symmetric matrices: all the eigenvalues are real numbers, the special directions are perpendicular, and the matrix can always be rewritten using a clean rotation. Because data analysis keeps producing symmetric matrices (covariance, similarity, curvature), this tidy family is the one that matters most in machine learning.

By the end of this week you can:

  • state and use the spectral theorem for symmetric matrices;
  • recognise orthogonal matrices and why they are special;
  • decide whether a quadratic form or symmetric matrix is positive definite, semi-definite, negative definite or indefinite;
  • handle the complex cousins: Hermitian and unitary matrices.

Words you need

Words you need
  • Symmetric matrix - A=ATA=A^T.
  • Orthogonal matrix QQ - square, with perpendicular unit-length columns: QTQ=IQ^TQ=I. It rotates or reflects without stretching.
  • Orthonormal - perpendicular and length 1.
  • Quadratic form - the expression xTAx\mathbf x^TA\mathbf x, a "squared" function of the entries of x\mathbf x.
  • Positive definite (PD) - xTAx>0\mathbf x^TA\mathbf x>0 for every non-zero x\mathbf x.
  • Conjugate - of a complex number a+bia+bi is a−bia-bi.
  • Hermitian matrix - A∗=AA^*=A, where A∗A^* means "transpose and conjugate". The complex version of symmetric.
  • Unitary matrix - U∗U=IU^*U=I. The complex version of orthogonal.

Idea 1: Symmetric matrices and the spectral theorem

The idea

Spectral theorem. If AA is a real symmetric matrix, then

  1. all its eigenvalues are real;
  2. eigenvectors for different eigenvalues are perpendicular;
  3. AA is always diagonalisable, and with orthonormal eigenvectors:
A=QΛQT,QTQ=IA=Q\Lambda Q^T,\qquad Q^TQ=I

Here QQ has the unit-length eigenvectors as columns and Λ\Lambda holds the eigenvalues. Compare with week 4: A=PDP−1A=PDP^{-1}. For symmetric matrices the awkward P−1P^{-1} turns into the easy QTQ^T.

Why are the eigenvectors perpendicular? Take Av=λvA\mathbf v=\lambda\mathbf v and Aw=μwA\mathbf w=\mu\mathbf w with λ≠μ\lambda\ne\mu. Since AA is symmetric, (Av)⋅w=v⋅(Aw)(A\mathbf v)\cdot\mathbf w=\mathbf v\cdot(A\mathbf w). The left side is λ(v⋅w)\lambda(\mathbf v\cdot\mathbf w), the right side is μ(v⋅w)\mu(\mathbf v\cdot\mathbf w). So (λ−μ)(v⋅w)=0(\lambda-\mu)(\mathbf v\cdot\mathbf w)=0. Because λ≠μ\lambda\neq\mu, we must have v⋅w=0\mathbf v\cdot\mathbf w=0.

Orthogonal matrices

A matrix QQ with QTQ=IQ^TQ=I has these properties:

  • columns are perpendicular unit vectors, so Q−1=QTQ^{-1}=Q^T (inverting is free);
  • ∥Qx∥=∥x∥\|Q\mathbf x\|=\|\mathbf x\| and (Qx)⋅(Qy)=x⋅y(Q\mathbf x)\cdot(Q\mathbf y)=\mathbf x\cdot\mathbf y: lengths and angles are preserved;
  • det⁡Q=±1\det Q=\pm1, and every eigenvalue has ∣λ∣=1|\lambda|=1.

Rotations and reflections are the orthogonal matrices.

Solved example: 1. Orthogonally diagonalise a symmetric matrix

Question. Write S=(2112)S=\begin{pmatrix}2&1\\1&2\end{pmatrix} as QΛQTQ\Lambda Q^T.

Solution.

  1. Trace 44, determinant 33: λ2−4λ+3=0\lambda^2-4\lambda+3=0, so λ=3\lambda=3 and λ=1\lambda=1 (both real, as promised).
  2. λ=3\lambda=3: S−3I=(−111−1)S-3I=\begin{pmatrix}-1&1\\1&-1\end{pmatrix} gives (1,1)(1,1). λ=1\lambda=1: S−I=(1111)S-I=\begin{pmatrix}1&1\\1&1\end{pmatrix} gives (1,−1)(1,-1).
  3. They are perpendicular: 1⋅1+1⋅(−1)=01\cdot1+1\cdot(-1)=0. Normalise by dividing each by 2\sqrt2.
  4. Q=12(111−1)Q=\dfrac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}, Λ=(3001)\Lambda=\begin{pmatrix}3&0\\0&1\end{pmatrix}, and S=QΛQTS=Q\Lambda Q^T.

Check one entry: the top-left of QΛQTQ\Lambda Q^T is 12(3⋅1+1⋅1)=2\frac12(3\cdot1+1\cdot1)=2. ✓

Idea 2: Quadratic forms and definiteness

For a symmetric AA, the quadratic form q(x)=xTAxq(\mathbf x)=\mathbf x^TA\mathbf x is a function that curves like a bowl, a dome, or a saddle. For A=(abbc)A=\begin{pmatrix}a&b\\b&c\end{pmatrix} it is ax2+2bxy+cy2ax^2+2bxy+cy^2.

Think of it like this

Put a marble on a surface. If the surface curves up in every direction, the marble settles at the bottom: positive definite (a bowl). If it curves down in every direction, the marble rolls off the top: negative definite (a dome). If it curves up one way and down another, you have a saddle (a horse's saddle, or a Pringle): indefinite.

Positive definite: a bowllevel curves are closed ovals Indefinite: a saddlelevel curves are open, hyperbola-like
Level curves (contour lines) of two quadratic forms, seen from above.
The idea
NameConditionAll eigenvaluesShape
Positive definite (PD)xTAx>0\mathbf x^TA\mathbf x>0 for all x≠0\mathbf x\ne0all >0>0bowl
Positive semi-definite (PSD)xTAx≥0\mathbf x^TA\mathbf x\ge0all ≥0\ge0bowl with a flat valley
Negative definitexTAx<0\mathbf x^TA\mathbf x<0all <0<0dome
Negative semi-definite≤0\le0all ≤0\le0dome with a flat ridge
Indefinitetakes both signsmixed signssaddle

Why do eigenvalues decide it? Write A=QΛQTA=Q\Lambda Q^T and let y=QTx\mathbf y=Q^T\mathbf x. Then xTAx=yTΛy=λ1y12+⋯+λnyn2\mathbf x^TA\mathbf x=\mathbf y^T\Lambda\mathbf y=\lambda_1y_1^2+\dots+\lambda_ny_n^2. A sum of squares weighted by the λi\lambda_i. If every λi>0\lambda_i>0 it is positive whatever y\mathbf y is; if some are negative you can choose y\mathbf y to make it negative.

Quick tests that avoid finding eigenvalues

  • 2×22\times2: PD   ⟺  \iff a>0a>0 and det⁡A>0\det A>0. Indefinite if det⁡A<0\det A<0.
  • Leading minors (Sylvester): PD   ⟺  \iff all leading principal minors (the determinants of the top-left 1×11\times1, 2×22\times2, 3×33\times3, ... blocks) are >0>0.
  • PSD is subtler: all principal minors must be ≥0\ge0, not just the leading ones.
  • A PD matrix has a positive diagonal, and every PD matrix is invertible.
Solved example: 2. Classify three quadratic forms

Question. Decide the definiteness of A=(2112)A=\begin{pmatrix}2&1\\1&2\end{pmatrix}, B=(1221)B=\begin{pmatrix}1&2\\2&1\end{pmatrix} and C=(1224)C=\begin{pmatrix}1&2\\2&4\end{pmatrix}.

Solution.

  • AA: a=2>0a=2>0 and det⁡=4−1=3>0\det=4-1=3>0, so PD. (Its eigenvalues are 3 and 1.)
  • BB: det⁡=1−4=−3<0\det=1-4=-3<0, so indefinite. (Eigenvalues 33 and −1-1.)
  • CC: det⁡=4−4=0\det=4-4=0 and trace =5=5, so eigenvalues 55 and 00: positive semi-definite, not definite, because x=(2,−1)\mathbf x=(2,-1) gives xTCx=0\mathbf x^TC\mathbf x=0.
Solved example: 3. Leading minors for a 3×33\times3

Question. Is M=(2−10−12−10−12)M=\begin{pmatrix}2&-1&0\\-1&2&-1\\0&-1&2\end{pmatrix} positive definite?

Solution. Leading minors: det⁡[2]=2>0\det[2]=2>0; det⁡(2−1−12)=3>0\det\begin{pmatrix}2&-1\\-1&2\end{pmatrix}=3>0; det⁡M=4>0\det M=4>0. All positive, so yes, PD. (Its eigenvalues are 2−2,  2,  2+22-\sqrt2,\;2,\;2+\sqrt2, all positive.)

Where you will see this again.

  • The Hessian of a function is PD at a minimum (week 7).
  • A function is convex exactly when its Hessian is PSD everywhere (week 8).
  • A covariance matrix is always PSD (it measures variances, which cannot be negative), which is why PCA works (week 6).
  • A function is a valid kernel exactly when its Gram matrix is PSD (MLT week 2).

Idea 3: The complex family

Some papers use complex numbers. All you need: ii is a number with i2=−1i^2=-1; a complex number is z=a+biz=a+bi; its conjugate is zˉ=a−bi\bar z=a-bi; and zzˉ=a2+b2=∣z∣2z\bar z=a^2+b^2=|z|^2, a real non-negative number.

For a complex matrix, the conjugate transpose A∗A^* flips the matrix over its diagonal and conjugates every entry. The real-world matrices you know are the special case where conjugating changes nothing.

RealComplexDefinitionKey properties
symmetricHermitianA∗=AA^*=Adiagonal entries real; eigenvalues real; eigenvectors for different eigenvalues orthogonal; unitarily diagonalisable
orthogonalunitaryU∗U=IU^*U=I∥Ux∥=∥x∥\|U\mathbf x\|=\|\mathbf x\|; every eigenvalue has ∣λ∣=1|\lambda|=1; columns orthonormal

Schur's theorem (appears in Quiz 2): every square matrix can be written A=UTU∗A=UTU^* with UU unitary and TT upper triangular, and the eigenvalues of AA sit on the diagonal of TT. Hermitian and unitary matrices are special cases where TT turns out to be diagonal.

Solved example: 4. Hermitian, unitary, neither?

Question. Classify H=(21+i1−i3)H=\begin{pmatrix}2&1+i\\1-i&3\end{pmatrix} and U=12(1ii1)U=\dfrac1{\sqrt2}\begin{pmatrix}1&i\\i&1\end{pmatrix}.

Solution.

  • H∗H^*: transpose gives (21−i1+i3)\begin{pmatrix}2&1-i\\1+i&3\end{pmatrix}, then conjugate gives (21+i1−i3)=H\begin{pmatrix}2&1+i\\1-i&3\end{pmatrix}=H. So HH is Hermitian. Its eigenvalues: trace 5, determinant 6−(1+i)(1−i)=6−2=46-(1+i)(1-i)=6-2=4, so λ2−5λ+4=0\lambda^2-5\lambda+4=0, giving 1 and 4: real, as promised.
  • U∗=12(1−i−i1)U^*=\dfrac1{\sqrt2}\begin{pmatrix}1&-i\\-i&1\end{pmatrix}. Then U∗U=12(1+1i−i−i+i1+1)=IU^*U=\frac12\begin{pmatrix}1+1&i-i\\-i+i&1+1\end{pmatrix}=I. So UU is unitary. But U∗≠UU^*\ne U, so it is not Hermitian: a "unitary but not Hermitian" matrix, a favourite exam object.

Your turn

Your turn: 1. Spectral theorem

Which are guaranteed for a real symmetric matrix? (a) real eigenvalues (b) orthogonal eigenvectors for different eigenvalues (c) at least one eigenvalue is positive (d) diagonalisable.

Need a hint?

Think about the three clauses of the spectral theorem.

Show the full solution

(a), (b), (d) are guaranteed. (c) is not: (−100−2)\begin{pmatrix}-1&0\\0&-2\end{pmatrix} is symmetric with only negative eigenvalues.

Your turn: 2. Definiteness

Is (3111)\begin{pmatrix}3&1\\1&1\end{pmatrix} positive definite? And (1331)\begin{pmatrix}1&3\\3&1\end{pmatrix}?

Need a hint?

Check a>0a>0 and det⁡>0\det>0.

Show the full solution

First: a=3>0a=3>0, det⁡=3−1=2>0\det=3-1=2>0: PD. Second: det⁡=1−9=−8<0\det=1-9=-8<0: indefinite.

Your turn: 3. Orthogonal facts

QQ is orthogonal and x=(3,4)\mathbf x=(3,4). What is ∥Qx∥\|Q\mathbf x\|? If det⁡Q=−1\det Q=-1, what kind of transformation could QQ be?

Need a hint?

Orthogonal matrices preserve length.

Show the full solution

∥Qx∥=∥x∥=5\|Q\mathbf x\|=\|\mathbf x\|=5. A determinant of −1-1 means a reflection (it flips orientation). A rotation has determinant +1+1.

Your turn: 4. Parameter in a quadratic form

For which values of aa is (2aa2)\begin{pmatrix}2&a\\a&2\end{pmatrix} positive definite?

Need a hint?

The 2×22\times2 test: 2>02>0 and det⁡>0\det>0.

Show the full solution

det⁡=4−a2>0  ⟺  ∣a∣<2\det=4-a^2>0\iff|a|<2. So PD exactly when −2<a<2-2<a<2. At a=±2a=\pm2 it is PSD (determinant 0).

Your turn: 5. Hermitian or not?

Is (1ii1)\begin{pmatrix}1&i\\i&1\end{pmatrix} Hermitian?

Need a hint?

Compute A∗A^*: transpose, then conjugate.

Show the full solution

Transpose gives the same matrix (it is symmetric as a table), conjugating turns ii into −i-i: A∗=(1−i−i1)≠AA^*=\begin{pmatrix}1&-i\\-i&1\end{pmatrix}\neq A. Not Hermitian, even though it is symmetric as a table of numbers. Being symmetric is not enough in the complex world.

Exam radar

Exam radar

MLF Quiz 2 summaries (30 of the 53 papers have one) mention quadratic forms in 19 papers, positive definite matrices in 12 + 10, Hermitian matrices in 10, unitary matrices in 9, Schur's theorem in 6. Real symmetric properties and PD properties appear as MSQs in nearly every cycle of the End Term, as does the "unitary but not Hermitian" question.

Typical MSQ: "Which of the following is true for a real symmetric matrix / positive definite matrix / Hermitian matrix?" Memorise the table in Idea 3 and the spectral theorem's three clauses.

Watch out - real exam trap
  • "Symmetric" is a real-matrix word. For complex matrices the test is A∗=AA^*=A.
  • PSD allows zero eigenvalues; PD does not. A PD matrix is invertible, a merely PSD one need not be.
  • Leading minors prove PD. They do not prove PSD.
  • Orthogonal ≠\ne projection. P2=PP^2=P projections squash lengths; orthogonal matrices preserve them.
  • "Orthogonal matrix" means perpendicular unit columns, not just perpendicular columns.

Quick quiz

Quick quiz

A real symmetric matrix has eigenvalues 2, 5 and 7. Which word describes it?

  • positive definite
  • negative definite
  • indefinite
  • orthogonal
All eigenvalues are positive. Orthogonal would need all eigenvalues of absolute value 1.

Which is always TRUE for a real symmetric matrix?

  • It has a zero eigenvalue.
  • Eigenvectors for different eigenvalues are perpendicular.
  • It has complex eigenvalues.
  • It is not invertible.
That is the second clause of the spectral theorem.

The matrix [[4, 2], [2, 1]] is...

  • positive definite
  • positive semi-definite but not positive definite
  • indefinite
  • negative definite
trace 5, determinant 4 - 4 = 0, so eigenvalues 5 and 0. A zero eigenvalue means semi-definite only.

Select all TRUE statements about an orthogonal matrix Q. (select all that apply)

  • Q transpose times Q equals the identity.
  • It preserves lengths of vectors.
  • Its determinant must be exactly 1.
  • It can have eigenvalue 3.
The determinant is 1 or -1. Every eigenvalue has absolute value 1, so 3 is impossible.

Recap

Remember this
  • Symmetric: real eigenvalues, perpendicular eigenvectors, A=QΛQTA=Q\Lambda Q^T.
  • Orthogonal: QTQ=IQ^TQ=I, Q−1=QTQ^{-1}=Q^T, preserves lengths, det⁡=±1\det=\pm1, ∣λ∣=1|\lambda|=1.
  • Definiteness is decided by eigenvalue signs. 2×22\times2: PD   ⟺  a>0\iff a>0 and det⁡>0\det>0. Leading minors all positive   ⟺  \iff PD.
  • Hermitian == complex symmetric (A∗=AA^*=A, real eigenvalues). Unitary == complex orthogonal (U∗U=IU^*U=I, ∣λ∣=1|\lambda|=1).
Formulas to keep
  • Spectral theorem: A=AT⇒A=QΛQTA=A^T\Rightarrow A=Q\Lambda Q^T, QTQ=IQ^TQ=I, λi∈R\lambda_i\in\mathbb R
  • Quadratic form q(x)=xTAx=∑λiyi2q(\mathbf x)=\mathbf x^TA\mathbf x=\sum\lambda_iy_i^2
  • PD   ⟺  \iff all λ>0\lambda>0   ⟺  \iff all leading minors >0>0; PSD   ⟺  \iff all λ≥0\lambda\ge0
  • Orthogonal: QTQ=IQ^TQ=I, ∥Qx∥=∥x∥\|Q\mathbf x\|=\|\mathbf x\|, det⁡Q=±1\det Q=\pm1
  • Hermitian: A∗=AA^*=A; unitary: U∗U=IU^*U=I; Schur: A=UTU∗A=UTU^*
Connected weeks (learn them together)

Practise with real exam questions

These come straight from past papers (with the real figures and the official answer key). Open 50 real questions on this week   All Quiz 2 papers