TExcelTAD
Home › Linear Algebra & Matrix Theory › Orthogonal Functions and Orthogonal Matrices

Orthogonal Functions and Orthogonal Matrices

A linear map that preserves inner products moves things around without stretching or bending them. In Rn\mathbb{R}^n such maps are given by orthogonal matrices, the rotations and reflections; between function spaces they are changes to an orthonormal basis of functions.

Maps that preserve the inner product

Let VV and WW be inner product spaces. A linear map T ⁣:V→WT\colon V \to W is orthogonal (an isometry) if ⟨Tu,Tv⟩=⟨u,v⟩\langle T\mathbf{u}, T\mathbf{v} \rangle = \langle \mathbf{u}, \mathbf{v} \rangle for all u,v\mathbf{u}, \mathbf{v}. Then TT also preserves lengths, distances and angles. Conversely, a linear map that preserves all lengths preserves inner products too, because of the polarization identity

⟨u,v⟩=14(∥u+v∥2−∥u−v∥2)\langle \mathbf{u}, \mathbf{v} \rangle = \frac{1}{4} \left(\lVert \mathbf{u} + \mathbf{v} \rVert^2 - \lVert \mathbf{u} - \mathbf{v} \rVert^2\right)

Orthogonal functions. In a function space, an orthonormal list like {1/2π,cos⁡x/π,sin⁡x/π,…}\{1/\sqrt{2\pi}, \cos x/\sqrt{\pi}, \sin x/\sqrt{\pi}, \ldots\} from Fourier series, or the normalized Legendre polynomials from Gram-Schmidt, plays the role of the standard basis. The map that sends a function to its list of coefficients is orthogonal: inner products of functions become dot products of coefficient vectors (Parseval's identity). That is why we can compute with Fourier coefficients instead of integrals.

Orthogonal matrices

A real n×nn \times n matrix QQ is orthogonal if QTQ=IQ^TQ = I. The following are equivalent:

Condition Meaning
QTQ=IQ^TQ = I the columns are orthonormal
QQT=IQQ^T = I the rows are orthonormal
Q−1=QTQ^{-1} = Q^T inverting is free
∥Qx∥=∥x∥\lVert Q\mathbf{x} \rVert = \lVert \mathbf{x} \rVert for all x\mathbf{x} lengths are preserved
(Qx)⋅(Qy)=x⋅y(Q\mathbf{x}) \cdot (Q\mathbf{y}) = \mathbf{x} \cdot \mathbf{y} for all x,y\mathbf{x}, \mathbf{y} angles are preserved

The proof of "QTQ=I  ⟹  dot products are preservedQ^TQ = I \implies \text{dot products are preserved}" is one line: (Qx)⋅(Qy)=(Qx)TQy=xTQTQy=xTy(Q\mathbf{x}) \cdot (Q\mathbf{y}) = (Q\mathbf{x})^TQ\mathbf{y} = \mathbf{x}^TQ^TQ\mathbf{y} = \mathbf{x}^T\mathbf{y}.

Further facts:

  • det⁡Q=±1\det Q = \pm 1, since det⁡(QTQ)=(det⁡Q)2=1\det(Q^TQ) = (\det Q)^2 = 1. det⁡=+1\det = +1 means a rotation, det⁡=−1\det = -1 includes a reflection.
  • Products and inverses of orthogonal matrices are orthogonal (they form the group O(n)\mathrm{O}(n); rotations form SO(n)\mathrm{SO}(n)).
  • Every real eigenvalue is ±1\pm 1, and complex eigenvalues have ∣λ∣=1\lvert \lambda \rvert = 1 (see Unitary and Hermitian Matrices).

Note: The name is slightly misleading: an "orthogonal matrix" has orthonormal columns. A matrix with merely orthogonal columns satisfies QTQ=diagonalQ^TQ = \text{diagonal}, not II.

python · try it yourself
import numpy as np

th = np.radians(30)
R = np.array([[np.cos(th), -np.sin(th), 0],
              [np.sin(th),  np.cos(th), 0],
              [0,           0,          1]])          # rotate 30° about z
n = np.array([1.0, 2.0, 2.0]) / 3                      # unit normal
H = np.eye(3) - 2 * np.outer(n, n)                     # reflection in the plane n·x = 0

for name, Q in [("rotation", R), ("reflection", H), ("product", R @ H)]:
    print(f"{name:10s} Q^T Q = I: {np.allclose(Q.T @ Q, np.eye(3))}   det = {np.linalg.det(Q):+.4f}")

x, y = np.array([3.0, -1.0, 2.0]), np.array([0.5, 4.0, 1.0])
print("|x| =", round(float(np.linalg.norm(x)), 4), " |Rx| =", round(float(np.linalg.norm(R @ x)), 4))
print("x.y =", float(x @ y), " (Hx).(Hy) =", round(float((H @ x) @ (H @ y)), 4))
rotation   Q^T Q = I: True   det = +1.0000
reflection Q^T Q = I: True   det = -1.0000
product    Q^T Q = I: True   det = -1.0000
|x| = 3.7417  |Rx| = 3.7417
x.y = -0.5  (Hx).(Hy) = -0.5

Householder reflections

The matrix H=I−2nnTH = I - 2\mathbf{n}\mathbf{n}^T (with ∥n∥=1\lVert \mathbf{n} \rVert = 1) used above reflects across the plane orthogonal to n\mathbf{n}. It is symmetric and orthogonal, so H−1=HH^{-1} = H. Given any two vectors x,y\mathbf{x}, \mathbf{y} of the same length, choosing n=(x−y)/∥x−y∥\mathbf{n} = (\mathbf{x} - \mathbf{y})/\lVert \mathbf{x} - \mathbf{y} \rVert gives Hx=yH\mathbf{x} = \mathbf{y}. Numerical libraries use this to zero out a whole column below the diagonal in one step; repeating it column by column produces the QR factorization.

python · try it yourself
import numpy as np

x = np.array([3.0, 4.0, 0.0, 12.0])
y = np.array([np.linalg.norm(x), 0, 0, 0])        # target: same length, along e1
n = (x - y) / np.linalg.norm(x - y)
H = np.eye(4) - 2 * np.outer(n, n)
print("|x| =", float(np.linalg.norm(x)))
print("Hx =", np.round(H @ x, 10) + 0.0)
print("H symmetric:", np.allclose(H, H.T), "  H^2 = I:", np.allclose(H @ H, np.eye(4)))
|x| = 13.0
Hx = [13.  0.  0.  0.]
H symmetric: True   H^2 = I: True

Orthogonal matrices and changes of basis

If the columns of QQ form an orthonormal basis BB, then the coordinates of a vector v\mathbf{v} in that basis are QTvQ^T\mathbf{v}, and going back is v=Q(QTv)\mathbf{v} = Q(Q^T\mathbf{v}). This is the special case of the matrix of a transformation where the change-of-basis matrix is inverted by transposing, which is what makes orthonormal bases so popular in code.

In software

  • 3D engines. The rotation part of a model or view matrix is orthogonal, so its inverse is its transpose: the view matrix is computed as a transpose, not a general inverse (Inverse, Graphics Transforms).
  • Normals. Surface normals are transformed by (M−1)T(M^{-1})^T; when MM is a pure rotation that is MM itself.
  • Drift. After thousands of multiplications, floating-point rotations stop being orthogonal; engines re-orthonormalize them or switch to quaternions.
  • Deep learning. Orthogonal weight initialization keeps signal norms stable through many layers, because ∥Qx∥=∥x∥\lVert Q\mathbf{x} \rVert = \lVert \mathbf{x} \rVert.
  • Numerics. QR and SVD are built from orthogonal matrices because they never amplify rounding errors (cond⁡(Q)=1\operatorname{cond}(Q) = 1).

Exercises

Exercise 1: Complete the matrix

Find aa and bb so that Q=[35a45b]Q = \begin{bmatrix} \frac{3}{5} & a \\ \frac{4}{5} & b \end{bmatrix} is a rotation matrix.

Answer

a=−45a = -\frac{4}{5}, b=35b = \frac{3}{5}.

Solution

The second column must be a unit vector orthogonal to (35,45)\left(\frac{3}{5}, \frac{4}{5}\right): either (−45,35)\left(-\frac{4}{5}, \frac{3}{5}\right) or (45,−35)\left(\frac{4}{5}, -\frac{3}{5}\right). The determinant is 35b−45a\frac{3}{5}b - \frac{4}{5}a; with (−45,35)\left(-\frac{4}{5}, \frac{3}{5}\right) it is 925+1625=1\frac{9}{25} + \frac{16}{25} = 1 (rotation), with the other it is −1 (reflection).

Exercise 2: Is it orthogonal?

Is M=[11−11]M = \begin{bmatrix} 1 & 1 \\ -1 & 1 \end{bmatrix} orthogonal? If not, fix it.

Answer

No, MTM=2IM^TM = 2I. M/2M/\sqrt{2} is orthogonal (a rotation by −45∘-45^\circ).

Solution

The columns (1,−1)(1, -1) and (1,1)(1, 1) are orthogonal but have length 2\sqrt{2}, so MTM=[2002]M^TM = \begin{bmatrix} 2 & 0 \\ 0 & 2 \end{bmatrix}. Dividing by 2\sqrt{2} normalizes them; det⁡(M/2)=(1+1)/2=1\det(M/\sqrt{2}) = (1 + 1)/2 = 1.

Exercise 3: Inverse for free

Q=13[12221−22−21]Q = \frac{1}{3}\begin{bmatrix} 1 & 2 & 2 \\ 2 & 1 & -2 \\ 2 & -2 & 1 \end{bmatrix}. Find Q−1Q^{-1} and det⁡Q\det Q.

Answer

Q−1=QT=QQ^{-1} = Q^T = Q (it is symmetric), det⁡Q=−1\det Q = -1.

Solution

The rows are the orthonormal vectors from Orthogonality Exercise 1, so Q−1=QTQ^{-1} = Q^T, and QQ is symmetric. A symmetric orthogonal matrix satisfies Q2=IQ^2 = I, so it is a reflection-type matrix.

python · try it yourself
from sympy import Matrix, Rational
Q = Rational(1, 3) * Matrix([[1, 2, 2], [2, 1, -2], [2, -2, 1]])
print(Q.T * Q == Matrix.eye(3), Q.inv() == Q.T, Q.det())
True True -1

Exercise 4: A Householder mirror (code)

Build the Householder matrix that sends x=(1,1)\mathbf{x} = (1, 1) to (2,0)(\sqrt{2}, 0) and check its determinant.

Answer

H≈[0.70710.70710.7071−0.7071]H \approx \begin{bmatrix} 0.7071 & 0.7071 \\ 0.7071 & -0.7071 \end{bmatrix}, det⁡H=−1\det H = -1.

Solution

n=(x−y)/∥x−y∥\mathbf{n} = (\mathbf{x} - \mathbf{y})/\lVert \mathbf{x} - \mathbf{y} \rVert with y=(2,0)\mathbf{y} = (\sqrt{2}, 0). Every Householder matrix has det⁡=−1\det = -1 (it flips one direction, n\mathbf{n}, and fixes a hyperplane).

python · try it yourself
import numpy as np
x = np.array([1.0, 1.0]); y = np.array([np.sqrt(2), 0.0])
n = (x - y) / np.linalg.norm(x - y)
H = np.eye(2) - 2 * np.outer(n, n)
print(np.round(H, 4), round(float(np.linalg.det(H)), 4))
[[ 0.7071  0.7071]
 [ 0.7071 -0.7071]] -1.0

Test yourself

For an orthogonal matrix QQ, Q−1Q^{-1} equals…

  1. QQ
  2. −Q-Q
  3. QTQ^T
  4. Q2Q^2

Which number can NOT be the determinant of a real orthogonal matrix?

  1. 1
  2. −1
  3. 2
  4. All three are possible

Why do numerical algorithms like QR prefer orthogonal transformations?

  1. They are always diagonal
  2. They preserve lengths, so they do not amplify rounding errors
  3. They have integer entries
  4. They commute with every matrix