Orthogonal matrices
正交矩阵
Change orthonormal coordinates while preserving Euclidean lengths and angles; distinguish rotations, reflections, and rectangular embeddings.
orthogonal-matricesTurn the coordinate frame without changing distances
Place a point at on squared paper. Rotating it counterclockwise by a quarter turn gives . 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
Original vector
(3, 4) · ‖v‖ = 5
90° counterclockwise
(-4, 3) · ‖v‖ = 5
Reflect across vertical axis
(-3, 4) · ‖v‖ = 5
The columns must be orthonormal
For a real square matrix , orthogonality means
The entry of is the inner product of columns and . Diagonal entries one require unit lengths; off-diagonal entries zero require perpendicular columns. Merely making columns perpendicular is insufficient: 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 , its columns are independent and the square matrix is invertible. Multiplying by its inverse proves that the left inverse is also the right inverse. Now check what happens to two vectors:
The first identity preserves inner products; choosing preserves squared lengths. Apply the same reasoning to 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 , use
Its column norms are one because , and their inner product cancels. At , this is the quarter turn in the opening example. The reflection 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 describe a new orthonormal basis in old coordinates, gives the coordinates of in that basis, and reconstructs it. Check the direction of a basis change before deciding whether to use or .
Verify the geometry numerically
This complete standard-library example computes the largest entrywise error in . 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 arithmetic operations. This implementation accumulates entries without storing the Gram matrix, so its checker needs additional storage beyond the input. Applying a dense to a vector costs . 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 and . Its columns are orthonormal, so , but . 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
- Does a reflection preserve the distance between two points? Answer: yes; orthogonality does not require preserving orientation.
- Are the columns of enough to make it orthogonal? Answer: no; the first column has length two.
- Apply the rectangular example’s to . Answer: ; the missing component cannot be reconstructed.
- If and are square orthogonal matrices of the same size, is orthogonal? Answer: yes: . 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?
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
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020 - 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:
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft) · Definition 3.8, printed p.78 / PDF p.84; rotations pp.93–94
- Deep Learning — Chapter 2: Linear Algebra · §2.6, orthonormal columns, transpose inverse and square-matrix convention
Related topics