TExcelTAD
Home › Linear Algebra & Matrix Theory › Orthogonality

Orthogonality

Two vectors are orthogonal when their inner product is zero. Orthogonal sets are the most convenient bases there are: coordinates come from inner products instead of solving a system, and they never interfere with each other.

Orthogonal and orthonormal sets

In an inner product space, u\mathbf{u} and v\mathbf{v} are orthogonal, written u⊥v\mathbf{u} \perp \mathbf{v}, if ⟨u,v⟩=0\langle \mathbf{u}, \mathbf{v} \rangle = 0. A set {v1,…,vk}\{\mathbf{v}_1, \ldots, \mathbf{v}_k\} is

Term Condition
orthogonal ⟨vi,vj⟩=0\langle \mathbf{v}_i, \mathbf{v}_j \rangle = 0 whenever i≠ji \ne j
orthonormal orthogonal, and every ∥vi∥=1\lVert \mathbf{v}_i \rVert = 1

Any orthogonal set of nonzero vectors can be made orthonormal by dividing each vector by its length.

Pythagoras. If u⊥v\mathbf{u} \perp \mathbf{v} then ∥u+v∥2=∥u∥2+2⟨u,v⟩+∥v∥2=∥u∥2+∥v∥2\lVert \mathbf{u} + \mathbf{v} \rVert^2 = \lVert \mathbf{u} \rVert^2 + 2\langle \mathbf{u}, \mathbf{v} \rangle + \lVert \mathbf{v} \rVert^2 = \lVert \mathbf{u} \rVert^2 + \lVert \mathbf{v} \rVert^2. The same works for any number of mutually orthogonal vectors.

Orthogonal sets are independent

Theorem. An orthogonal set of nonzero vectors is linearly independent.

Proof. Suppose c1v1+⋯+ckvk=0c_1\mathbf{v}_1 + \cdots + c_k\mathbf{v}_k = \mathbf{0}. Take the inner product of both sides with vj\mathbf{v}_j. Every term with i≠ji \ne j vanishes, leaving cj⟨vj,vj⟩=0c_j\langle \mathbf{v}_j, \mathbf{v}_j \rangle = 0. Since vj≠0\mathbf{v}_j \ne \mathbf{0}, ⟨vj,vj⟩>0\langle \mathbf{v}_j, \mathbf{v}_j \rangle > 0, so cj=0c_j = 0. This holds for every jj.

So nn mutually orthogonal nonzero vectors in an nn-dimensional space automatically form a basis.

Coordinates for free

If {v1,…,vn}\{\mathbf{v}_1, \ldots, \mathbf{v}_n\} is an orthogonal basis and w=c1v1+⋯+cnvn\mathbf{w} = c_1\mathbf{v}_1 + \cdots + c_n\mathbf{v}_n, the same trick (inner product with vj\mathbf{v}_j) gives each coefficient directly:

cj=⟨w,vj⟩⟨vj,vj⟩(orthogonal basis)cj=⟨w,vj⟩(orthonormal basis)\begin{aligned} c_j &= \frac{\langle \mathbf{w}, \mathbf{v}_j \rangle}{\langle \mathbf{v}_j, \mathbf{v}_j \rangle} && \text{(orthogonal basis)} \\ c_j &= \langle \mathbf{w}, \mathbf{v}_j \rangle && \text{(orthonormal basis)} \end{aligned}

No row reduction needed. Compare with an arbitrary basis, where finding coordinates means solving a linear system.

python · try it yourself
import numpy as np

v1 = np.array([1.0, 1.0, 1.0])
v2 = np.array([1.0, -1.0, 0.0])
v3 = np.array([1.0, 1.0, -2.0])
B = [v1, v2, v3]

print("pairwise inner products:", [float(B[i] @ B[j]) for i in range(3) for j in range(i + 1, 3)])

w = np.array([4.0, 2.0, -3.0])
c = [float(w @ v) / float(v @ v) for v in B]
print("coefficients:", [round(x, 4) for x in c])
print("rebuilt w:", c[0] * v1 + c[1] * v2 + c[2] * v3)
print("same as solve():", np.round(np.linalg.solve(np.column_stack(B), w), 4))
pairwise inner products: [0.0, 0.0, 0.0]
coefficients: [1.0, 1.0, 2.0]
rebuilt w: [ 4.  2. -3.]
same as solve(): [1. 1. 2.]

Orthogonal complements

For a subspace WW of VV, the orthogonal complement is

W⊥={v∈V:⟨v,w⟩=0 for every w∈W}W^\perp = \{\mathbf{v} \in V : \langle \mathbf{v}, \mathbf{w} \rangle = 0 \text{ for every } \mathbf{w} \in W\}

It is always a subspace, W∩W⊥={0}W \cap W^\perp = \{\mathbf{0}\}, and in a finite-dimensional space dim⁡W+dim⁡W⊥=dim⁡V\dim W + \dim W^\perp = \dim V. To test v∈W⊥\mathbf{v} \in W^\perp it is enough to check v\mathbf{v} against a spanning set of WW.

For matrices this gives the clean picture behind the four fundamental subspaces: Ax=0A\mathbf{x} = \mathbf{0} says x\mathbf{x} is orthogonal to every row of AA, so

null⁡(A)=(row space of A)⊥null⁡(AT)=(column space of A)⊥\operatorname{null}(A) = (\text{row space of } A)^\perp \qquad \operatorname{null}(A^T) = (\text{column space of } A)^\perp

SymPy can compute a complement exactly: put a basis of WW in the rows of a matrix and take its null space.

python · try it yourself
from sympy import Matrix

W = Matrix([[1, 2, 0, -1],
            [0, 1, 1, 1]])          # rows span W in R^4
perp = W.nullspace()
for v in perp:
    print("basis vector of W⊥:", list(v), "  check:", list(W * v))
print("dim W + dim W⊥ =", W.rank(), "+", len(perp), "=", W.rank() + len(perp))
basis vector of W⊥: [2, -1, 1, 0]   check: [0, 0]
basis vector of W⊥: [3, -1, 0, 1]   check: [0, 0]
dim W + dim W⊥ = 2 + 2 = 4

Note: The two basis vectors of W⊥W^\perp returned here are not orthogonal to each other. They only have to be orthogonal to WW. Making them orthogonal to each other is the job of Gram-Schmidt.

In software

  • Graphics. A camera's right, up and forward vectors form an orthonormal basis; converting a world point into camera coordinates is just three dot products (see Look Rotation).
  • Collision. The separating axis test projects shapes onto edge normals, vectors orthogonal to the edges (SAT).
  • Signal processing and ML. Orthogonal features carry non-overlapping information; PCA picks orthogonal directions on purpose (PCA).
  • Error correction. A codeword is valid exactly when it is orthogonal (mod 2) to every row of the parity-check matrix (Error Correcting Codes).

Exercises

Exercise 1: Is the set orthogonal?

Are (1,2,2)(1, 2, 2), (2,1,−2)(2, 1, -2) and (2,−2,1)(2, -2, 1) mutually orthogonal? Make them orthonormal.

Answer

Yes. Each has length 3, so dividing by 3 gives an orthonormal basis of R3\mathbb{R}^3.

Solution
(1,2,2)⋅(2,1,−2)=2+2−4=0(1,2,2)⋅(2,−2,1)=2−4+2=0(2,1,−2)⋅(2,−2,1)=4−2−2=0∥each∥=1+4+4=3\begin{aligned} (1, 2, 2) \cdot (2, 1, -2) &= 2 + 2 - 4 = 0 \\ (1, 2, 2) \cdot (2, -2, 1) &= 2 - 4 + 2 = 0 \\ (2, 1, -2) \cdot (2, -2, 1) &= 4 - 2 - 2 = 0 \\ \lVert \text{each} \rVert &= \sqrt{1 + 4 + 4} = 3 \end{aligned}

Exercise 2: Coordinates without solving

Using the orthonormal basis from Exercise 1, find the coordinates of w=(3,0,3)\mathbf{w} = (3, 0, 3).

Answer

(3,0,3)=3q1+0q2+3q3(3, 0, 3) = 3\mathbf{q}_1 + 0\mathbf{q}_2 + 3\mathbf{q}_3, where qi\mathbf{q}_i are the basis vectors divided by 3.

Solution

cj=w⋅qjc_j = \mathbf{w} \cdot \mathbf{q}_j:

c1=(3+0+6)/3=3c2=(6+0−6)/3=0c3=(6+0+3)/3=3\begin{aligned} c_1 &= (3 + 0 + 6)/3 = 3 \\ c_2 &= (6 + 0 - 6)/3 = 0 \\ c_3 &= (6 + 0 + 3)/3 = 3 \end{aligned}

Check: 3⋅(1,2,2)/3+3⋅(2,−2,1)/3=(1,2,2)+(2,−2,1)=(3,0,3)3 \cdot (1, 2, 2)/3 + 3 \cdot (2, -2, 1)/3 = (1, 2, 2) + (2, -2, 1) = (3, 0, 3).

Exercise 3: A complement in R3\mathbb{R}^3

Find W⊥W^\perp when WW is the plane spanned by (1,0,1)(1, 0, 1) and (0,1,1)(0, 1, 1).

Answer

W⊥W^\perp is the line spanned by (1,1,−1)(1, 1, -1).

Solution

v=(a,b,c)\mathbf{v} = (a, b, c) must satisfy a+c=0a + c = 0 and b+c=0b + c = 0, so a=b=−ca = b = -c. Taking c=−1c = -1 gives (1,1,−1)(1, 1, -1). Alternatively, the cross product (1,0,1)×(0,1,1)=(−1,−1,1)(1, 0, 1) \times (0, 1, 1) = (-1, -1, 1) points the same way.

Exercise 4: Pythagoras check (code)

Verify numerically that ∥u+v+w∥2=∥u∥2+∥v∥2+∥w∥2\lVert \mathbf{u} + \mathbf{v} + \mathbf{w} \rVert^2 = \lVert \mathbf{u} \rVert^2 + \lVert \mathbf{v} \rVert^2 + \lVert \mathbf{w} \rVert^2 for the three vectors of Exercise 1.

Answer

Both sides equal 27.

Solution

∥u+v+w∥2=∥(5,1,1)∥2=27\lVert \mathbf{u} + \mathbf{v} + \mathbf{w} \rVert^2 = \lVert (5, 1, 1) \rVert^2 = 27, and 9+9+9=279 + 9 + 9 = 27.

python · try it yourself
import numpy as np
u, v, w = np.array([1, 2, 2]), np.array([2, 1, -2]), np.array([2, -2, 1])
s = u + v + w
print(int(s @ s), int(u @ u + v @ v + w @ w))
27 27

Exercise 5: Orthogonal functions

On [−1,1][-1, 1] with ⟨f,g⟩=∫f g dx\langle f, g \rangle = \int f\,g\,dx, show that every odd function is orthogonal to every even function.

Answer

The product of an odd and an even function is odd, and the integral of an odd function over [−1,1][-1, 1] is 0.

Solution

If f(−x)=−f(x)f(-x) = -f(x) and g(−x)=g(x)g(-x) = g(x), then h=fgh = fg satisfies h(−x)=−h(x)h(-x) = -h(x). Splitting the integral and substituting x→−xx \to -x on [−1,0][-1, 0] gives ∫−10h=−∫01h\int_{-1}^0 h = -\int_0^1 h, so the total is 0. For example ⟨x,x2⟩=∫−11x3 dx=0\langle x, x^2 \rangle = \int_{-1}^1 x^3\,dx = 0.

Test yourself

Why is an orthogonal set of nonzero vectors linearly independent?

  1. Because it has at most nn vectors
  2. Taking the inner product of a dependence relation with vj\mathbf{v}_j forces cj=0c_j = 0
  3. Because orthogonal vectors have length 1
  4. It is not always independent

In an orthonormal basis q1,…,qn\mathbf{q}_1, \ldots, \mathbf{q}_n, the coordinate of w\mathbf{w} along qj\mathbf{q}_j is…

  1. w⋅qj\mathbf{w} \cdot \mathbf{q}_j
  2. ∥w∥/∥qj∥\lVert \mathbf{w} \rVert / \lVert \mathbf{q}_j \rVert
  3. the jj-th entry of A−1wA^{-1}\mathbf{w} for some matrix AA you must invert
  4. w⋅qj/n\mathbf{w} \cdot \mathbf{q}_j / n

The null space of a matrix AA is the orthogonal complement of…

  1. its column space
  2. its row space
  3. the null space of ATA^T
  4. Rn\mathbb{R}^n