Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Eigendecomposition and Orthonormal Eigenvectors of Symmetric Matrices

Welcome back. Last time, you computed distances between points and used the fact that an orthogonal matrix preserves lengths. This lesson asks a complementary question: can a matrix have orthogonal directions that it stretches without turning? For every real symmetric matrix, the answer is yes. You will compute those directions and stretch factors by hand, then verify the result in PyTorch. This tool will later help describe preferred directions in 3D data.

Allow about 40 minutes, including the video, reading, and code.


What symmetry guarantees

A real square matrix is symmetric when . An eigenvector is a nonzero vector satisfying

The number is its eigenvalue. Along the direction , applying changes only the vector’s scale or sign, not its line of action.

The spectral theorem says that a real symmetric matrix has orthonormal eigenvectors that form a basis of . Put these vectors in the columns of , and their corresponding eigenvalues on the diagonal of . Then

Watch the opening of Linear Algebra - Spectral Decomposition from Arnold Yim for the theorem and an interpretation of the final equation.

Linear Algebra - Spectral Decomposition

Arnold Yim’s Linear Algebra - Spectral Decomposition introduces the spectral theorem and shows how an orthonormal eigenbasis reconstructs a symmetric matrix.

Watch the theorem for the guarantees about real eigenvalues and orthogonal eigenspaces. Continue through the decomposition; focus on why the inverse of the eigenvector matrix is its transpose, and how the matrix product becomes a sum of eigenvector outer products.

The distinction between orthogonal and orthonormal matters. Orthogonal vectors have zero dot product with one another; orthonormal vectors also each have length one. Thus checks both properties at once: its off-diagonal entries are dot products between different columns, and its diagonal entries are their squared lengths. Because there are orthonormal columns in , they are an orthonormal basis, not merely an orthonormal set.


Compute a decomposition by hand

Consider

First find the eigenvalues by solving :

The eigenvalues are and . For each one, solve . When , the equations give two equal components, so is an eigenvector. When , they give opposite components, so is an eigenvector.

These vectors have dot product zero, but each has length . Normalize them and place them in columns, keeping each eigenvalue in the matching diagonal position:

Directly checking the dot products gives , , and . Hence . Checking the eigenvector equations gives ; multiplying on the right by recovers .

That last equation describes the action of on any vector. In the -basis, its two coordinates are scaled independently—by and —before the result is expressed in the original coordinates.


Why the orthogonality check works

The hand calculation showed orthogonality for one matrix. Symmetry explains why it happens whenever eigenvalues are distinct. If and , then lets us calculate the same scalar in two ways:

Substituting the eigenvector equations yields

If , their eigenvectors must therefore have zero dot product. The following reading develops this proof alongside a worked decomposition.

8.2: Orthogonal Diagonalization

Read 8.2: Orthogonal Diagonalization on LibreTexts to see a three-dimensional calculation and the reason symmetry makes eigenvectors for distinct eigenvalues orthogonal.

In Section 8.2, read Example 4, beginning “Find an orthogonal matrix,” through its final diagonalization statement: the worked example. Track the order of its eigenvalues against the columns of its normalized eigenvector matrix. Then read the discussion immediately after Example 4, including Theorems 3 and 4, from “Actually, the fact that the eigenvectors in Example 8.2.4 are orthogonal is no coincidence” up to the introduction of Example 5: the orthogonality proof. Focus on where the proof uses A^\top=A.

There is an important qualification: two arbitrary eigenvectors with the same eigenvalue need not be orthogonal. For example, if has the value in both of its first two diagonal positions, then both and are eigenvectors with eigenvalue , but their dot product is . Within that shared eigenspace, you can choose an orthonormal basis instead. The spectral theorem guarantees a choice of orthonormal eigenvectors, not that every possible choice is already orthogonal.


Verify a 3D decomposition in PyTorch

For larger matrices, calculating a characteristic polynomial by hand quickly becomes cumbersome. For a real symmetric matrix, torch.linalg.eigh computes real eigenvalues and orthonormal eigenvectors directly. It returns eigenvalues in ascending order and places the corresponding eigenvectors in the columns of its second output.

import torch

A = torch.tensor(
    [[2., 1., 0.],
     [1., 2., 0.],
     [0., 0., 4.]],
    dtype=torch.float64,
)

eigenvalues, Q = torch.linalg.eigh(A)
Lambda = torch.diag(eigenvalues)
I = torch.eye(3, dtype=A.dtype)

print("eigenvalues:", eigenvalues)  # approximately [1., 3., 4.]
print("eigenvectors in columns:\n", Q)

assert torch.allclose(A, A.T)
assert eigenvalues.shape == (3,)
assert Q.shape == (3, 3)

# Orthonormality: all pairwise column dot products
assert torch.allclose(Q.T @ Q, I, atol=1e-12)

# Eigenvector equations, with each column matched to its eigenvalue
assert torch.allclose(A @ Q, Q @ Lambda, atol=1e-12)

# Reconstruction of the original matrix
assert torch.allclose(Q @ Lambda @ Q.T, A, atol=1e-12)

The upper-left block is the matrix you decomposed by hand. Its eigenvalues and appear again, while the third coordinate direction has eigenvalue . Your printed eigenvectors may have signs opposite to those you wrote by hand: if is an eigenvector, so is . A sign change does not invalidate any of the three checks.

The checks catch different mistakes. verifies an orthonormal basis; verifies that each column is paired with the right eigenvalue; and verifies the full decomposition. Use a tolerance because floating-point outputs are approximate, even when the mathematical identities are exact.

For a 3D point cloud, a symmetric matrix constructed from its centered coordinates can describe how strongly the points vary along different directions. Its orthonormal eigenvectors provide directions in 3D space, while its eigenvalues quantify the associated variation. The computation you have learned here is the linear-algebra core of that geometric interpretation.


A real symmetric matrix can be decomposed as , with real eigenvalues in and an orthonormal eigenbasis in the columns of . To compute one by hand, find each eigenvalue, solve for its eigenvectors, and choose normalized, mutually orthogonal vectors within any repeated-eigenvalue eigenspace. In code, verify orthonormality, eigenvector equations, and reconstruction rather than trusting a printed result alone.

Next, you will move from matrix operations to calculus: computing the gradient of a scalar field with respect to spatial coordinates and checking it with PyTorch autograd.

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

Sign up