AI Wiki中文/EN

Orthogonal matrices

正交矩阵

Change orthonormal coordinates while preserving Euclidean lengths and angles; distinguish rotations, reflections, and rectangular embeddings.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Turn the coordinate frame without changing distances

Place a point at (3,4)(3,4) on squared paper. Rotating it counterclockwise by a quarter turn gives (−4,3)(-4,3). Its distance from the origin remains five. If every point undergoes the same rotation, pairwise distances and angles also remain unchanged. An orthogonal matrix expresses this sort of geometry-preserving linear map; reflections are included too.

This matters when a computation changes coordinates. You can express data in a more useful orthonormal basis without stretching some directions more than others. The transformation changes numerical coordinates, but preserves Euclidean information. Projection is different: dropping a coordinate can discard a component of a vector. MML, Definition 3.8

New coordinates, still length 5

Original vector

xy0

(3, 4) · ‖v‖ = 5

90° counterclockwise

xy0

(-4, 3) · ‖v‖ = 5

Reflect across vertical axis

xy0

(-3, 4) · ‖v‖ = 5

All panels use the same scale. Points on the circle are distance 5 from the origin; reflection also preserves length.

The columns must be orthonormal

For a real square matrix Q∈Rn×nQ\in\mathbb R^{n\times n}, orthogonality means

Q⊤Q=In,Q−1=Q⊤,QQ⊤=In.Q^\top Q=I_n,\qquad Q^{-1}=Q^\top,\qquad QQ^\top=I_n.

The (i,j)(i,j) entry of Q⊤QQ^\top Q is the inner product of columns ii and jj. Diagonal entries one require unit lengths; off-diagonal entries zero require perpendicular columns. Merely making columns perpendicular is insufficient: diag⁡(2,1)\operatorname{diag}(2,1) has perpendicular columns but stretches the first coordinate. The conventional name is “orthogonal matrix,” although its columns are orthonormal. Deep Learning, Section 2.6

Because Q⊤Q=InQ^\top Q=I_n, its columns are independent and the square matrix is invertible. Multiplying by its inverse proves that the left inverse Q⊤Q^\top is also the right inverse. Now check what happens to two vectors:

(Qx)⊤(Qy)=x⊤Q⊤Qy=x⊤y,∥Qx−Qy∥2=∥x−y∥2.(Qx)^\top(Qy)=x^\top Q^\top Qy=x^\top y,\qquad \|Qx-Qy\|_2=\|x-y\|_2.

The first identity preserves inner products; choosing y=xy=x preserves squared lengths. Apply the same reasoning to x−yx-y for distances. Angles follow by dividing an inner product by the two lengths, provided both vectors are nonzero. These claims refer to the ordinary Euclidean inner product; changing the metric changes the relevant matrix condition.

For a rotation through angle θ\theta, use

Q(θ)=[cos⁡θ−sin⁡θsin⁡θcos⁡θ].Q(\theta)=\begin{bmatrix}\cos\theta&-\sin\theta\\\sin\theta&\cos\theta\end{bmatrix}.

Its column norms are one because cos⁡2θ+sin⁡2θ=1\cos^2\theta+\sin^2\theta=1, and their inner product cancels. At θ=π/2\theta=\pi/2, this is the quarter turn in the opening example. The reflection diag⁡(−1,1)\operatorname{diag}(-1,1) also passes the orthogonality condition, but reverses orientation. Both preserve area magnitude; their determinants have opposite signs, +1 and −1. The determinant article explains this distinction.

If the columns of QQ describe a new orthonormal basis in old coordinates, Q⊤xQ^\top x gives the coordinates of xx in that basis, and Q(Q⊤x)=xQ(Q^\top x)=x reconstructs it. Check the direction of a basis change before deciding whether to use QQ or Q⊤Q^\top.

Verify the geometry numerically

This complete standard-library example computes the largest entrywise error in Q⊤Q−IQ^\top Q-I. It checks a proposed square matrix; it does not construct an orthogonal basis. The small apply and dot helpers assume the matching shapes supplied by the example.

import math

def check_orthogonal(q, tolerance=1e-10):
    n = len(q)
    if not n or any(len(row) != n for row in q):
        raise ValueError("a nonempty square matrix is required")
    if not math.isfinite(tolerance) or tolerance <= 0:
        raise ValueError("a positive finite tolerance is required")
    if any(not math.isfinite(x) for row in q for x in row):
        raise ValueError("finite entries required")
    error = 0.0
    for i in range(n):
        for j in range(n):
            gram = sum(q[k][i]*q[k][j] for k in range(n))
            if not math.isfinite(gram):
                raise ArithmeticError("nonfinite Gram entry")
            error = max(error, abs(gram-float(i == j)))
    return error <= tolerance, error

def apply(a, x):
    return [sum(v*w for v,w in zip(row,x)) for row in a]

def dot(x, y):
    return sum(a*b for a,b in zip(x,y))

q = [[0.,-1.],[1.,0.]]
x, y = [3.,4.], [2.,-1.]
qx, qy = apply(q,x), apply(q,y)
assert qx == [-4.,3.]
assert dot(qx,qx) == dot(x,x) == 25
assert dot(qx,qy) == dot(x,y) == 2
assert apply(list(zip(*q)),qx) == x
assert check_orthogonal(q) == (True,0.)
assert check_orthogonal([[-1.,0.],[0.,1.]])[0]  # reflection
assert not check_orthogonal([[2.,0.],[0.,1.]])[0]
assert check_orthogonal([[-1.]])[0]
for bad in ([], [[1.,0.]], [[float('nan')]]):
    try:
        check_orthogonal(bad)
    except ValueError:
        pass
    else:
        raise AssertionError("invalid matrix accepted")

A direct Gram check uses O(n3)O(n^3) arithmetic operations. This implementation accumulates entries without storing the Gram matrix, so its checker needs O(1)O(1) additional storage beyond the input. Applying a dense QQ to a vector costs O(n2)O(n^2). A tolerance reports numerical agreement, not an exact mathematical proof. Choose tolerances according to precision, dimension, and the computation that produced the matrix.

Rectangular columns and discarded information

Consider the 3×2 matrix with columns (1,0,0)(1,0,0) and (0,1,0)(0,1,0). Its columns are orthonormal, so Q⊤Q=I2Q^\top Q=I_2, but QQ⊤=diag⁡(1,1,0)≠I3QQ^\top=\operatorname{diag}(1,1,0)\ne I_3. It embeds a two-dimensional vector into three dimensions without changing length; going the other direction discards the third component. Calling it a square orthogonal matrix would hide that distinction.

Orthogonal coordinates do not guarantee statistically independent features. Nor does orthogonality by itself make a neural network train well: nonlinearities, losses, data, and later transformations still matter. Repeated floating-point updates can also accumulate departures from exact orthogonality.

Predict, then check

  1. Does a reflection preserve the distance between two points? Answer: yes; orthogonality does not require preserving orientation.
  2. Are the columns of diag⁡(2,1)\operatorname{diag}(2,1) enough to make it orthogonal? Answer: no; the first column has length two.
  3. Apply the rectangular example’s QQ⊤QQ^\top to (2,3,4)(2,3,4). Answer: (2,3,0)(2,3,0); the missing component cannot be reconstructed.
  4. If QQ and RR are square orthogonal matrices of the same size, is QRQR orthogonal? Answer: yes: (QR)⊤QR=R⊤Q⊤QR=I(QR)^\top QR=R^\top Q^\top QR=I. Their multiplication order can still matter.

Where the same structure returns

QR factorization constructs orthogonal directions for solving linear systems. The spectral theorem chooses them to diagonalize real symmetric matrices; SVD uses separate orthonormal bases for input and output spaces. Follow which geometry a method preserves, which coordinates it changes, and which components it removes. These are different operations even when all three are drawn as arrows on a plane.

Make a prediction, then check

For a 3×2 Q with orthonormal columns, what must QQᵀ be?

Choose one answer

Learning objectives

  • Derive the inverse and preservation of lengths and angles from column inner products.
  • Distinguish square orthogonality, reflection, and rectangular orthonormal embeddings.

Prerequisites & connections

Explore related knowledge →

References

  1. Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
    Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020
  2. Deep Learning — Chapter 2: Linear Algebra
    Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-05 · Codex technical check: cited-source comparison, derivation and numerical checks, bilingual argument comparison, and executed Python assertions; no independent human peer review.

  • Recomputed rotations and reflections of (3,4), checked 100 rotation/reflection and inner-product cases, and distinguished rectangular column orthogonality from square orthogonality.
  • Checked the figure coordinates, common scale, radius five and bilingual descriptions; a tolerance check is not treated as an exact proof.
  • Compared claims, assumptions, examples, exercises and citations across languages; structural validation additionally compares display equations, code and source lists.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.