Create your own
Lesson illustration

Eigendecomposition of Symmetric Matrices: Directions and Scales

Hello. In the previous lesson, you connected vector operations to geometry: lengths, alignment, and projections. Those ideas now become a way to understand a matrix as a transformation with certain preferred directions.

For a general vector, multiplying by a matrix changes both its length and direction. An eigenvector is exceptional: the matrix may stretch it, shrink it, flip it, or collapse it to zero, but it does not move it off its original line. For a real symmetric matrix, these special directions form an orthonormal coordinate system, giving a particularly clean decomposition. This is the version that appears throughout ML, especially with covariance matrices and later PCA.

By the end of this lesson, you should be able to find the eigenvalues and eigenvectors of a small symmetric matrix, assemble its eigendecomposition, and explain it as “change coordinates, scale independently, then change back.”


Eigenvectors: directions a transformation preserves

Let be a square matrix. A nonzero vector is an eigenvector of if there is a scalar such that

The scalar is the corresponding eigenvalue.

This equation says that applying to has exactly the same effect as multiplying by one number:

  • If , the vector is stretched.
  • If , it is shrunk.
  • If , it is flipped through the origin and scaled by .
  • If , it is collapsed to the zero vector.

The key word is direction. An eigenvector is not a unique arrow of a particular length. If is an eigenvector, then every nonzero scalar multiple of it is also an eigenvector with the same eigenvalue:

So eigenvectors represent invariant lines through the origin.

21. Eigenvalues and Eigenvectors

Watch “21. Eigenvalues and Eigenvectors” from MIT OpenCourseWare for a precise visual and algebraic introduction. It emphasizes the distinction between a typical vector, whose direction changes under a matrix, and an eigenvector, whose direction is preserved.

Watch the definition first. Focus on the meaning of A\mathbf{x}=\lambda\mathbf{x}, including why a negative or zero eigenvalue is valid. Then watch the symmetric example, where the characteristic equation and null spaces produce two orthogonal eigenvector directions.

For this lesson, we focus on a real symmetric matrix:

For example,

is symmetric because its entries mirror across the main diagonal.

Symmetry provides powerful guarantees:

  1. Every eigenvalue is real.
  2. Eigenvectors belonging to distinct eigenvalues are orthogonal.
  3. We can choose unit-length eigenvectors that form an orthonormal basis.

Those guarantees are what make eigendecomposition geometrically transparent and numerically useful in ML.


Finding eigenvalues, then eigenvectors

Consider the symmetric matrix

We want nonzero vectors and scalars satisfying

Move everything to the left:

Because , where is the identity matrix, this becomes

For a nonzero solution to exist, the matrix must be singular. Therefore,

This is the characteristic equation.

Step 1: Find the eigenvalues

For the example matrix,

Set its determinant to zero:

Expanding and factoring gives:

Therefore, the two eigenvalues are

A useful check for a matrix is:

Also,

These checks do not replace the calculation, but they can catch an arithmetic mistake during an interview or implementation review.

Step 2: Find the eigenvector for

Substitute into

Let

Then the first row gives

so . One valid eigenvector is

Verify it directly:

So the direction along the line is stretched by a factor of .

Step 3: Find the eigenvector for

Now use :

The equation is

so . One valid eigenvector is

Again, verify:

So the direction along is stretched by a factor of .

Notice the two eigenvectors are orthogonal:

That is not an accident. Distinct eigenvectors of a real symmetric matrix are orthogonal.


From eigenpairs to eigendecomposition

To form the standard symmetric eigendecomposition, normalize the eigenvectors to have unit length:

Put these unit eigenvectors into the columns of a matrix:

Place their corresponding eigenvalues on the diagonal:

Because the columns of are orthonormal,

Thus , and the eigendecomposition is

For this example,

The order matters: the first column of must correspond to the first diagonal entry of . Reordering eigenvectors is valid only if you make the identical reordering of eigenvalues.


The geometry: rotate into eigenvector coordinates, scale, rotate back

The decomposition

is best read right to left when applying to a vector :

  1. : express in the orthonormal eigenvector coordinate system.
  2. : scale each eigenvector coordinate independently.
  3. : express the result back in the original coordinate system.
The diagram shows a unit circle first expressed in the eigenvector coordinate system by \(Q^{\top}\), then independently scaled along those coordinate axes by \(\Lambda\), and finally returned to the original coordinates by \(Q\). The resulting ellipse has principal axes aligned with the matrix’s eigenvector directions.

For the example, take

First, express it in the eigenvector basis:

Then scale those coordinates:

Finally, transform back:

This agrees with direct multiplication:

More generally, if a vector is written as a combination of orthonormal eigenvectors,

then

The matrix does not mix the eigenvector components. It simply rescales each one.

For the unit circle, the transformed shape is an ellipse when both eigenvalues are nonzero. Its axis directions are the eigenvectors, and its semiaxis lengths are the absolute values of the eigenvalues. The provided diagram depicts the common positive-eigenvalue case. If an eigenvalue were negative, the corresponding axis would also flip; if it were zero, the circle would collapse onto a lower-dimensional shape.


Why symmetric eigendecomposition matters in ML

Many central ML objects are symmetric. The most important early example is a feature covariance matrix:

A covariance matrix is symmetric and positive semidefinite. Therefore, its eigenvalues satisfy

For a unit eigenvector ,

So the eigenvalue measures the variance of the centered data along its associated eigenvector direction. Large eigenvalues identify directions of large spread; small eigenvalues identify directions with comparatively little variation. This is the basis of PCA, which you will study later as a dimensionality-reduction method.

Two caveats are worth retaining:

  • Symmetry is doing real work. An arbitrary square matrix may have complex eigenvalues or may not have enough independent eigenvectors to form a basis.
  • Eigenvalues are not automatically positive. They are nonnegative for covariance matrices and other positive semidefinite matrices, but a general symmetric matrix can have negative eigenvalues.
  • Repeated eigenvalues make individual eigenvectors non-unique. If , every nonzero vector is an eigenvector with eigenvalue . In that situation, the eigenspace is well-defined, but no single direction within it is special.

PyTorch verification

In code, use torch.linalg.eigh for real symmetric matrices. The h refers to Hermitian, the complex-number generalization of symmetric. It returns eigenvalues in ascending order and returns eigenvectors as the columns of .

import torch

A = torch.tensor(
    [
        [3.0, 1.0],
        [1.0, 3.0],
    ]
)

eigenvalues, Q = torch.linalg.eigh(A)
Lambda = torch.diag(eigenvalues)

print(eigenvalues)
# tensor([2., 4.])

# Eigendecomposition reconstruction
A_reconstructed = Q @ Lambda @ Q.T

# Column-wise eigenvector equation: A q_i = lambda_i q_i
assert torch.allclose(A, A_reconstructed)
assert torch.allclose(A @ Q, Q @ Lambda)

# Orthonormality of the eigenvector matrix
assert torch.allclose(Q.T @ Q, torch.eye(2))

Do not expect PyTorch to return the exact signs used in the handwritten derivation. If is an eigenvector, then is equally valid, so an implementation may return either sign. The reconstruction and eigenvector equation are the reliable checks.

For an interview-level explanation, a concise and accurate version is:

For a real symmetric matrix, eigendecomposition writes , where 's columns are orthonormal eigenvectors and contains eigenvalues. Geometrically, the matrix changes into its eigenvector coordinates, scales each independent direction by its eigenvalue, and changes back. For a covariance matrix, the eigenvectors are principal directions of variation and the eigenvalues are variances along those directions.


You can now compute eigenpairs for a small symmetric matrix and interpret them correctly: eigenvectors are invariant directions, while eigenvalues are the signed scaling along those directions. Symmetry ensures these directions can be chosen orthonormal, yielding the clean form

Next, you will extend this “preferred directions and scales” idea to matrices that may be rectangular or nonsymmetric using singular value decomposition.

Can't find a good explanation? Sign up and we'll make it for you

Sign up