Eigenvalues & eigenvectors

Week 2 — Eigenvalues & eigenvectors

Quantitative biology and integrative omics

About this lecture

In Matrices as transformations, a matrix is a function that moves vectors around — it stretches, rotates, mixes the axes. Today we hunt for the special directions a matrix leaves alone.

  • Most vectors get rotated by a matrix. A few special ones only get scaled — those are eigenvectors.
  • The amount of scaling is the eigenvalue \lambda, and the whole idea is one equation: A\mathbf{v} = \lambda\mathbf{v}.
  • How to find them by hand for a 2\times2: the characteristic equation \det(A - \lambda I) = 0 gives the eigenvalues, and you check each answer by multiplying. Shortcuts: diagonal or triangular matrices, the symmetric pattern, and geometry. Bigger matrices: eigen() in R.
  • Why symmetric matrices (like a covariance matrix) are special: real eigenvalues, orthogonal eigenvectors.
  • Biology: the eigenvectors of a covariance matrix point along the main axes of variation in a dataset — the seed of PCA (later this week).

This is a concept day. Practise on paper with 2\times2 matrices: find the eigenvalues, find the eigenvectors, check by multiplying.

Problem: where do the tilted axes of a cell cloud come from?

Measure two genes across many cells and plot each cell as a point (gene 1 on x, gene 2 on y).

  • The two genes are co-regulated, so the cloud is a tilted, elongated ellipse.
  • There is one direction along which the cells spread the most — the long axis of the cloud.
  • And a perpendicular direction with the least spread — the short axis.

These two axes are not the x- and y-axes. They are tilted. Where do they come from?

They are the eigenvectors of the data’s covariance matrix. Today we learn what that sentence means.

A matrix turns most vectors but only stretches a few

Take a matrix A and feed it different input vectors. Watch the direction of the output.

A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}

  • A\begin{pmatrix}1\\0\end{pmatrix} = \begin{pmatrix}2\\1\end{pmatrix} — pointed along x, came out tilted up. Direction changed.
  • A\begin{pmatrix}0\\1\end{pmatrix} = \begin{pmatrix}1\\2\end{pmatrix} — pointed along y, came out tilted. Direction changed.
  • A\begin{pmatrix}1\\1\end{pmatrix} = \begin{pmatrix}3\\3\end{pmatrix} — pointed along the diagonal, came out on the same line, just longer!

That last one is special: A only scaled it (by 3), without rotating it.

An eigenvector is only stretched, never turned

A nonzero vector \mathbf{v} is an eigenvector of A if A only scales it:

A\mathbf{v} = \lambda\mathbf{v}

  • \lambda (a scalar) is the eigenvalue — the stretch factor for that direction.
  • “Eigen” is German for own / characteristic: these are the matrix’s own special directions.

Reading the equation: transforming \mathbf{v} with A gives the same thing as just multiplying \mathbf{v} by the number \lambda. The matrix acts like a plain number on that direction.

From the previous slide: A\begin{pmatrix}1\\1\end{pmatrix} = \begin{pmatrix}3\\3\end{pmatrix} = 3\begin{pmatrix}1\\1\end{pmatrix}, so \mathbf{v}=(1,1) is an eigenvector with eigenvalue \lambda = 3.

Any multiple of an eigenvector is also an eigenvector

If \mathbf{v} is an eigenvector, so is 2\mathbf{v}, -\mathbf{v}, 0.5\mathbf{v} — any nonzero multiple:

A(2\mathbf{v}) = 2(A\mathbf{v}) = 2(\lambda\mathbf{v}) = \lambda(2\mathbf{v})

  • An eigenvector defines a direction (a line through the origin), not one specific arrow.
  • So we are free to pick a convenient representative — usually the simplest integers, or a unit vector (length 1).
  • R will hand you the unit vector by default; on paper we keep nice whole numbers like (1,1).

Test a candidate: just multiply

To check whether a given \mathbf v is an eigenvector, compute A\mathbf v and ask: is the output a multiple of the input?

With A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}:

  • \mathbf v = \begin{pmatrix}1\\-1\end{pmatrix}: \ A\mathbf v = \begin{pmatrix}2-1\\1-2\end{pmatrix} = \begin{pmatrix}1\\-1\end{pmatrix} = 1\cdot\mathbf v. Yes, eigenvector with \lambda = 1.
  • \mathbf v = \begin{pmatrix}1\\2\end{pmatrix}: \ A\mathbf v = \begin{pmatrix}2+2\\1+4\end{pmatrix} = \begin{pmatrix}4\\5\end{pmatrix}. Is \begin{pmatrix}4\\5\end{pmatrix} = \lambda\begin{pmatrix}1\\2\end{pmatrix}? It would need \lambda = 4 and \lambda = 2.5. No.

The eigenvalue is read off by comparing entries: divide each entry of A\mathbf v by the matching entry of \mathbf v. Both ratios must agree, and they equal \lambda.

Where eigenvalues come from: \det(A - \lambda I) = 0

Where do eigenvalues come from in general? From (A - \lambda I)\mathbf{v} = \mathbf{0}: we need a nonzero \mathbf{v} that A-\lambda I sends to zero. A matrix can only crush a nonzero vector to zero if it is singular (no inverse), and that is exactly when its determinant is zero (week 1):

\boxed{\ \det(A - \lambda I) = 0\ }

For a 2\times2, \det\begin{pmatrix} a & b \\ c & d \end{pmatrix} = ad - bc, so

\det(A - \lambda I) = (a-\lambda)(d-\lambda) - bc = 0,

a quadratic in \lambda.

The characteristic equation: a worked example

A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}

1. Subtract \lambda from the diagonal: \quad A - \lambda I = \begin{pmatrix} 2-\lambda & 1 \\ 1 & 2-\lambda \end{pmatrix}

2. Determinant ad - bc, set to zero: \quad (2-\lambda)(2-\lambda) - 1\cdot 1 = 0

3. Move the 1 to the right-hand side: \quad (2-\lambda)^2 = 1

4. Which numbers square to 1? Both 1 and -1, so there are two cases:

2 - \lambda = 1 \quad\Rightarrow\quad \lambda = 2 - 1 = 1

2 - \lambda = -1 \quad\Rightarrow\quad \lambda = 2 + 1 = 3

The eigenvalues are \lambda_1 = 3 (the stretch of (1,1) we saw at the start) and \lambda_2 = 1.

Check the answer, and matrices without a pattern

Three cheap checks for A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix} with \lambda = 3 and \lambda = 1:

  • Multiply: A\begin{pmatrix}1\\1\end{pmatrix} = \begin{pmatrix}2+1\\1+2\end{pmatrix} = \begin{pmatrix}3\\3\end{pmatrix} = 3\begin{pmatrix}1\\1\end{pmatrix} ✓
  • Sum of eigenvalues = trace (sum of the diagonal): 3 + 1 = 4 = 2 + 2 ✓
  • Product of eigenvalues = \det A: 3 \cdot 1 = 3 = 2\cdot2 - 1\cdot1 ✓

No pattern? For B = \begin{pmatrix} 2 & 1 \\ 1 & 0 \end{pmatrix}: \ (2-\lambda)(0-\lambda) - 1\cdot1 = \lambda^2 - 2\lambda - 1 = 0. Use the quadratic formula:

\lambda = \frac{2 \pm \sqrt{(-2)^2 - 4\cdot1\cdot(-1)}}{2} = \frac{2 \pm \sqrt 8}{2} = 1 \pm \sqrt 2, \quad\text{so}\quad \lambda \approx 2.41 \ \text{ and } \ \lambda \approx -0.41

A rotation by 90^\circ gives \lambda^2 + 1 = 0, i.e. \lambda^2 = -1: no real number squares to -1, so no real eigenvalue.

Triangular matrices show eigenvalues on the diagonal

Diagonal matrix: each axis is only scaled, so the axes are the eigenvectors and the diagonal entries are the eigenvalues.

\begin{pmatrix} 4 & 0 \\ 0 & 2 \end{pmatrix}: \quad \lambda = 4 \text{ for } (1,0), \qquad \lambda = 2 \text{ for } (0,1)

Triangular matrix (zeros below or above the diagonal): bc = 0, so the equation is (a-\lambda)(d-\lambda) = 0. A product is zero only when one of the factors is zero: a - \lambda = 0 or d - \lambda = 0, so \lambda = a or \lambda = d, the diagonal entries.

A = \begin{pmatrix} 3 & 1 \\ 0 & 2 \end{pmatrix}: \quad \lambda = 3 \text{ and } \lambda = 2

  • One eigenvector comes for free: A\begin{pmatrix}1\\0\end{pmatrix} = \begin{pmatrix}3\\0\end{pmatrix} = 3\begin{pmatrix}1\\0\end{pmatrix}.
  • The other is found on the next slide.

Finding the eigenvector for a known \lambda

Once you know \lambda, the eigenvector is a small linear system. Start from A\mathbf{v} = \lambda\mathbf{v} and move everything to one side (write \lambda\mathbf{v} = \lambda I\mathbf{v} so the shapes match):

(A - \lambda I)\mathbf{v} = \mathbf{0}, \qquad A - \lambda I = \text{$A$ with $\lambda$ subtracted from each diagonal entry.}

For A = \begin{pmatrix} 3 & 1 \\ 0 & 2 \end{pmatrix} and \lambda = 2:

A - 2I = \begin{pmatrix} 1 & 1 \\ 0 & 0 \end{pmatrix}

Write \mathbf v = (x, y).

Row 1 says x + y = 0, i.e. y = -x.

Pick x = 1: \ \mathbf v = (1, -1).

Verify: A\begin{pmatrix}1\\-1\end{pmatrix} = \begin{pmatrix}3-1\\0-2\end{pmatrix} = \begin{pmatrix}2\\-2\end{pmatrix} = 2\begin{pmatrix}1\\-1\end{pmatrix}. ✓

Example: The symmetric 2\times2 pattern

For a symmetric matrix with equal diagonal entries, the eigenvectors are always the two diagonals of the plane:

A = \begin{pmatrix} a & b \\ b & a \end{pmatrix}: \qquad A\begin{pmatrix}1\\1\end{pmatrix} = (a+b)\begin{pmatrix}1\\1\end{pmatrix}, \qquad A\begin{pmatrix}1\\-1\end{pmatrix} = (a-b)\begin{pmatrix}1\\-1\end{pmatrix}

For our A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}:

  • \lambda_1 = 2 + 1 = 3 for (1,1) and
  • \lambda_2 = 2 - 1 = 1 for (1,-1).

Notice: \mathbf{v}_1\cdot\mathbf{v}_2 = (1)(1) + (1)(-1) = 0 … the two eigenvectors are orthogonal! (will be important later)

What a matrix does reveals its eigenvectors

Think about what the matrix does; the directions it leaves on their own line are the eigenvectors.

Matrix What it does Eigenvectors and eigenvalues
\begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} projects onto the x-axis (1,0): \lambda = 1 (kept); \ (0,1): \lambda = 0 (squashed)
\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} mirrors in the line y = x (1,1): \lambda = 1 (on the mirror); \ (1,-1): \lambda = -1 (flipped)
\begin{pmatrix} 1 & 0.5 \\ 0 & 1 \end{pmatrix} shear (1,0): \lambda = 1; no other direction
\begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix} rotates 90^\circ none: every direction is turned

Check your answer: the eigenvalues always add up to the trace (sum of the diagonal). For \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}: 3 + 1 = 4 = 2 + 2. ✓

Bigger than 2\times2: let R do it with eigen() (Eigenvalues in R).

Try it: hunt for eigen-directions

Symmetric matrices have perpendicular eigenvectors

A matrix is symmetric if A = A^\top (it equals its own transpose — mirror across the diagonal). Our example \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix} is symmetric (b = c = 1).

For symmetric matrices (a theorem — the spectral theorem):

  • All eigenvalues are real (no awkward complex numbers).
  • Eigenvectors for different eigenvalues are orthogonal (perpendicular).

This is exactly what we just saw: real eigenvalues 3, 1 and perpendicular eigenvectors (1,1) and (1,-1) (dot product 1\cdot1 + 1\cdot(-1) = 0).

This is not very important for this course; but there are plenty deep theories about linear algebra if you wish to learn this topic properly.

Covariance eigenvectors are the data’s main axes

For a dataset (e.g. expression of 2 genes, x and y, across many cells), the covariance matrix C summarises spread:

C = \begin{pmatrix} \text{var}(x) & \text{cov}(x,y) \\ \text{cov}(x,y) & \text{var}(y) \end{pmatrix}

C is symmetric (cov(x,y)= cov(y,x)), so by the spectral theorem:

  • its eigenvectors are orthogonal → they form clean perpendicular axes,
  • its eigenvalues are real and positive → the amount of variance along each axis.

The eigenvector with the largest eigenvalue points along the long axis of the data cloud — the direction of greatest variation. That is PCA (taught later this week). Today you built its engine.

Special cases & gotchas

  • Repeated eigenvalue: \begin{pmatrix} 2 & 0 \\ 0 & 2 \end{pmatrix} has \lambda = 2 twice. Every direction is an eigenvector (it scales everything equally).
  • Diagonal matrix: eigenvalues are just the diagonal entries; eigenvectors are the axes.
  • Complex eigenvalues: a pure rotation \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix} has no real eigenvector — it rotates everything, leaving no direction fixed. (This can’t happen for symmetric matrices.)
  • Scale freedom: eigenvectors are only defined up to length and sign.

Summary

Concept Key fact
Eigenvector direction A only scales, never rotates
Eigen relation A\mathbf{v} = \lambda\mathbf{v} (\mathbf{v}\neq\mathbf{0})
Eigenvalue the scaling factor \lambda
Find \lambda (2\times2) \det(A-\lambda I) = (a-\lambda)(d-\lambda) - bc = 0
Test a candidate compute A\mathbf{v}: a multiple of \mathbf{v}?
Diagonal / triangular eigenvalues = diagonal entries
Symmetric \begin{pmatrix} a & b \\ b & a \end{pmatrix} (1,1): a+b; \ (1,-1): a-b
Find \mathbf{v} for known \lambda solve (A-\lambda I)\mathbf{v}=\mathbf{0}, pick nice scale
Check multiply; sum of \lambdas = trace, product = \det A
Symmetric A real eigenvalues, orthogonal eigenvectors
Biology eigenvectors of covariance = axes of variation (PCA engine)

Next (Eigenvalues in R): compute all of this in R with eigen.