BetaFree coursewareRewritten from MIT OpenCourseWareCC BY-NC-SA 4.0
Open CosmologyPhysics & cosmology, from high school to a graduate year

Orthogonal matrices and Gram–Schmidt

Orthonormal vectors q₁, …, qₙ are perpendicular unit vectors: qᵢᵀqⱼ = 0 for i ≠ j and 1 for i = j. Put them in the columns of Q and the whole statement becomes QᵀQ = I, whether Q is square or rectangular. A square Q is called an orthogonal matrix, and then Qᵀ = Q⁻¹. Examples: permutation matrices; the rotation with columns (cos θ, sin θ) and (−sin θ, cos θ); the matrices of ±1 named after Hadamard, divided by √2 or 2; and (1, 2, 2)/3 with (−2, −1, 2)/3. Orthonormal columns make projections easy: P = QQᵀ (the identity if Q is square), the normal equations become x̂ = Qᵀb, and each component is a dot product, x̂ᵢ = qᵢᵀb. Gram–Schmidt turns independent vectors a, b, c into orthonormal ones: keep A = a, subtract from b its projection onto A, B = b − (Aᵀb/AᵀA)A, subtract from c its projections onto A and B, then divide each by its length. For a = (1, 1, 1), b = (1, 0, 2) it gives B = (0, −1, 1) and q₁ = (1, 1, 1)/√3, q₂ = (0, −1, 1)/√2, spanning the same plane. In matrix form A = QR, with R upper triangular because each later q is perpendicular to the earlier a's.

You need this first

Full reading path (18 pages)
  1. Vectors (8.01)
  2. Vectors and the dot product (18.02)
  3. Determinants and the cross product (18.02)
  4. Planes through three points, and matrices (18.02)
  5. Equations of planes and square systems (18.02)
  6. The geometry of linear equations (18.06)
  7. Elimination with matrices (18.06)
  8. Matrix multiplication and inverse matrices (18.06)
  9. Factorization into A = LU (18.06)
  10. Transposes, permutations and vector spaces (18.06)
  11. Column space and nullspace (18.06)
  12. Solving Ax = 0: pivot variables and special solutions (18.06)
  13. Solving Ax = b: the complete solution (18.06)
  14. Independence, basis and dimension (18.06)
  15. The four fundamental subspaces (18.06)
  16. Orthogonal vectors and subspaces (18.06)
  17. Projections onto subspaces (18.06)
  18. Projection matrices and least squares (18.06)
On this page · 5 sections
  1. Orthonormal vectors and the matrix Q
  2. Why orthonormal columns help
  3. Gram–Schmidt
  4. A = QR
  5. Summary

The last lecture of the orthogonality chapter: orthogonal bases and orthogonal matrices, and how to make a basis orthonormal (transcript, p. 1). It continues projection matrices and least squares.

Orthonormal vectors and the matrix Q#

Vectors q1,…,qnq_1, \dots, q_n are orthonormal when each is perpendicular to the others and has length one (transcript, p. 1):

Orthonormal vectors
qiTqj={0i≠j (orthogonal)1i=j (normalized)q_i^Tq_j = \begin{cases} 0 & i \ne j \text{ (orthogonal)} \\ 1 & i = j \text{ (normalized)} \end{cases}
In words

q sub i ^ capital T q sub j equals 0 when i is not equal to j (orthogonal); or 1 when i equals j (normalized)

Much of numerical linear algebra is built on orthonormal vectors, because they never overflow or underflow (p. 1). Put them in the columns of QQ. Then QTQQ^TQ collects all the dot products, and gives the best possible answer (pp. 2–3):

Orthonormal columns
QTQ=IQ^TQ = I
In words

capital Q ^ capital T capital Q equals capital I

QQ need not be square: it might have two columns with many components (p. 3). Only when it is square is it called an orthogonal matrix (Strang would prefer "orthonormal matrix", but the convention is fixed, pp. 3–4), and then (p. 4)

Orthogonal matrix
Q square: QT=Q−1Q \text{ square: } Q^T = Q^{-1}
In words

capital Q square: capital Q ^ capital T equals capital Q to the power minus 1

Examples (pp. 4–8). Any permutation matrix, such as the one with columns (0,1,0)(0, 1, 0), (0,0,1)(0, 0, 1), (1,0,0)(1, 0, 0); its transpose is another permutation, and the product is II (p. 4). The rotation-type matrix (p. 5)

Two by two
Q=(cos⁡θ−sin⁡θsin⁡θcos⁡θ),Q=12(111−1)Q = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}, \qquad Q = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}
In words

capital Q equals cos theta minus sine theta; sine theta cos theta, capital Q equals 1 over the square root of 2 1 1; 1 minus 1

where the second has orthogonal columns of length 2\sqrt2 until divided by 2\sqrt2 (p. 5). Repeating its pattern in blocks, with a minus sign in the corner block, gives a 4×44 \times 4 example (p. 6; Strang describes it in words, and the entries below are written out from that description):

Four by four
Q=12(11111−11−111−1−11−1−11)Q = \frac{1}{2}\begin{pmatrix} 1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1 \\ 1 & 1 & -1 & -1 \\ 1 & -1 & -1 & 1 \end{pmatrix}
In words

capital Q equals one half 1 1 1 1; 1 minus 1 1 minus 1; 1 1 minus 1 minus 1; 1 minus 1 minus 1 1

Matrices of ±1\pm1 with orthogonal columns are named after Hadamard (the transcript spells it "Adhemar"). Strang lists sizes 2, 4, 16, 64; the block construction in fact gives every power of 2 (8 and 32 too). He thinks there is none of size 5, and for some sizes nobody knows (p. 6). (Not from the lecture: the size must be 1, 2 or a multiple of 4, and whether every multiple of 4 is possible is still an open question.) A rectangular example without square roots (pp. 7–8): (1,2,2)/3(1, 2, 2)/3 and (−2,−1,2)/3(-2, -1, 2)/3 are orthonormal, and they are an orthonormal basis for the plane they span. Strang then finds a third column from the entries 1, 2, 2 with suitable signs, for instance (2,−2,1)/3(2, -2, 1)/3 (p. 8). Orthonormal vectors are automatically independent (p. 8).

Why orthonormal columns help#

Projection onto the column space of QQ (transcript, pp. 8–11). The general formula has QTQ=IQ^TQ = I in the middle (p. 9):

Projection with orthonormal columns
P=Q(QTQ)−1QT=QQTP = Q(Q^TQ)^{-1}Q^T = QQ^T
In words

capital P equals capital Q ( capital Q ^ capital T capital Q ) to the power minus 1 capital Q ^ capital T equals capital Q capital Q ^ capital T

If QQ is square, its column space is everything and QQT=IQQ^T = I (p. 10). Otherwise QQTQQ^T is a genuine projection: symmetric, and (QQT)(QQT)=Q(QTQ)QT=QQT(QQ^T)(QQ^T) = Q(Q^TQ)Q^T = QQ^T (pp. 10–11). The normal equations lose their matrix (p. 11):

Normal equations with Q
QTQx^=QTb  ⇒  x^=QTb,x^i=qiTbQ^TQ\hat x = Q^Tb \;\Rightarrow\; \hat x = Q^Tb, \qquad \hat x_i = q_i^Tb
In words

capital Q ^ capital T capital Q x hat equals capital Q ^ capital T b which gives x hat equals capital Q ^ capital T b, x sub i hat equals q sub i ^ capital T b

No inversion, no system to solve: the component along the ii-th basis vector is just a dot product, a formula Strang ranks among the most important in several branches of mathematics (pp. 11–12).

Gram–Schmidt#

Now start from independent vectors that are not orthonormal and make them so (transcript, p. 12). The goal is not a triangular matrix, as in elimination, but orthonormal columns (p. 12). With two vectors aa and bb, first make orthogonal vectors AA and BB, then divide by their lengths: q1=A/∥A∥q_1 = A/\|A\|, q2=B/∥B∥q_2 = B/\|B\| (p. 13). (Strang jokes that dividing by the length was Schmidt's contribution; the transcript spells Gram as "Graham".) Keep A=aA = a. For BB, remove from bb its projection onto AA, leaving the error part ee from the first projection lecture (pp. 14–15):

The second vector
B=b−ATbATAA,ATB=ATb−ATbATAATA=0B = b - \frac{A^Tb}{A^TA}A, \qquad A^TB = A^Tb - \frac{A^Tb}{A^TA}A^TA = 0
In words

capital B equals b minus capital A ^ capital T b over the quantity capital A ^ capital T capital A, times capital A, capital A ^ capital T capital B equals capital A ^ capital T b minus capital A ^ capital T b over the quantity capital A ^ capital T capital A, times capital A ^ capital T capital A equals 0

BB is not zero because aa and bb are independent (p. 15). For a third vector cc, subtract its components in both directions found so far (pp. 16–18):

The third vector
C=c−ATcATAA−BTcBTBBC = c - \frac{A^Tc}{A^TA}A - \frac{B^Tc}{B^TB}B
In words

capital C equals c minus capital A ^ capital T c over the quantity capital A ^ capital T capital A, times capital A minus capital B ^ capital T c over the quantity capital B ^ capital T capital B, times capital B

and then q3=C/∥C∥q_3 = C/\|C\| (p. 18).

Example (pp. 19–21). a=(1,1,1)a = (1, 1, 1) and b=(1,0,2)b = (1, 0, 2): ATb=3A^Tb = 3 and ATA=3A^TA = 3, so B=(1,0,2)−(1,1,1)=(0,−1,1)B = (1, 0, 2) - (1, 1, 1) = (0, -1, 1), perpendicular to AA (pp. 19–20). Dividing by the lengths 3\sqrt3 and 2\sqrt2 (pp. 20–21):

Gram–Schmidt example
Q=(1/301/3−1/21/31/2)Q = \begin{pmatrix} 1/\sqrt{3} & 0 \\ 1/\sqrt{3} & -1/\sqrt{2} \\ 1/\sqrt{3} & 1/\sqrt{2} \end{pmatrix}
In words

capital Q equals 1 over the square root of 3 0; 1 over the square root of 3 minus 1 over the square root of 2; 1 over the square root of 3 1 over the square root of 2

QQ and the original matrix have the same column space, the same plane, since BB is a combination of aa and bb; the new basis is just better (pp. 21–22).

A = QR#

Elimination in matrix language was A=LUA = LU; Gram–Schmidt in matrix language is A=QRA = QR (transcript, p. 22). For two columns (pp. 23–24):

A=QRA = QR
(a1a2)=(q1q2)(a1Tq1a2Tq1a1Tq2a2Tq2),a1Tq2=0\begin{pmatrix} a_1 & a_2 \end{pmatrix} = \begin{pmatrix} q_1 & q_2 \end{pmatrix}\begin{pmatrix} a_1^Tq_1 & a_2^Tq_1 \\ a_1^Tq_2 & a_2^Tq_2 \end{pmatrix}, \qquad a_1^Tq_2 = 0
In words

a one a two equals q one q two a one ^ capital T q one a two ^ capital T q one; a one ^ capital T q two a two ^ capital T q two, a one ^ capital T q two equals 0

RR is upper triangular, because Gram–Schmidt makes each later qq perpendicular to all the earlier vectors (pp. 23–24). For the example, R=(3302)R = \begin{pmatrix} \sqrt3 & \sqrt3 \\ 0 & \sqrt2 \end{pmatrix} (completed here; Strang only sketches its entries).

Worked example

Gram–Schmidt of your own

(a) Apply Gram–Schmidt to a=(1,0,1)a = (1, 0, 1), b=(1,1,0)b = (1, 1, 0), c=(1,2,3)c = (1, 2, 3). (b) Use the result to write v=(2,0,0)v = (2, 0, 0) in the orthonormal basis.

(a) A and B

A=(1,0,1)A = (1, 0, 1). ATb/ATA=12A^Tb/A^TA = \frac{1}{2}, so B=(1,1,0)−12(1,0,1)=(12,1,−12)B = (1, 1, 0) - \frac{1}{2}(1, 0, 1) = (\frac{1}{2}, 1, -\frac{1}{2}).

(a) C

ATc/ATA=42=2A^Tc/A^TA = \frac{4}{2} = 2 and BTc/BTB=13/2=23B^Tc/B^TB = \frac{1}{3/2} = \frac{2}{3}. So C=(1,2,3)−2(1,0,1)−23(12,1,−12)=(−43,43,43)C = (1, 2, 3) - 2(1, 0, 1) - \frac{2}{3}(\frac{1}{2}, 1, -\frac{1}{2}) = (-\frac{4}{3}, \frac{4}{3}, \frac{4}{3}). Check: ATC=0A^TC = 0 and BTC=−23+43−23=0B^TC = -\frac{2}{3} + \frac{4}{3} - \frac{2}{3} = 0. Normalizing: q1=(1,0,1)/2q_1 = (1, 0, 1)/\sqrt2, q2=(1,2,−1)/6q_2 = (1, 2, -1)/\sqrt6, q3=(−1,1,1)/3q_3 = (-1, 1, 1)/\sqrt3.

(b) Components are dot products

q1Tv=2q_1^Tv = \sqrt2, q2Tv=2/6q_2^Tv = 2/\sqrt6, q3Tv=−2/3q_3^Tv = -2/\sqrt3. Then 2 q1+26q2−23q3=(1,0,1)+13(1,2,−1)+23(1,−1,−1)=(2,0,0)\sqrt2\,q_1 + \frac{2}{\sqrt6}q_2 - \frac{2}{\sqrt3}q_3 = (1, 0, 1) + \frac{1}{3}(1, 2, -1) + \frac{2}{3}(1, -1, -1) = (2, 0, 0).

Summary#

Symbols on this page

Show the 37 symbols used here
θ\theta theta.
An angle. Say it: “theta” (sounds like “thay-ta or thee-ta”).
≠\neq not equal.
Is not equal to. Say it: “is not equal to”.
⇒\Rightarrow implies.
Implies: what follows is a consequence of what came before. Say it: “which gives”.
±\pm plus or minus.
Plus or minus: both signs, or an uncertainty (67.3 ± 1.2). Say it: “plus or minus”.
×\times times.
Times (multiplication). Between two vectors: the cross product. Say it: “times”.
sin⁡\sin sine.
Sine of an angle. Say it: “sine”.
cos⁡\cos cosine.
Cosine of an angle. Say it: “cos”.
ı^\hat\imath hat.
A unit vector: a vector of length 1 that only gives a direction (î, r̂). Say it: “hat”.
aa a.
The first given vector in Gram–Schmidt. Say it: “a”.
cc c.
The third given vector in Gram–Schmidt. Say it: “c”.
TT T.
As a superscript: the transpose. Say it: “capital T”.
xx x.
The unknown; with a hat, the least-squares solution. Say it: “x”.
ii i.
An index for the vectors (or for the components of x̂). Say it: “i”.
jj j.
A second index for the vectors. Say it: “j”.
ee e.
The error part of a projection, from the earlier lecture. Say it: “e”.
vv v.
In the worked example, the vector (2, 0, 0) written in the orthonormal basis. Say it: “v”.
PP P.
The projection matrix QQᵀ. Say it: “capital P”.
QQ Q.
The matrix whose columns are orthonormal; square: an orthogonal matrix. Say it: “capital Q”.
AA A.
The first orthogonal vector in Gram–Schmidt (A = a); also the matrix of the given vectors in A = QR. Say it: “capital A”.
BB B.
The second orthogonal vector: b minus its projection onto A. Say it: “capital B”.
CC C.
The third orthogonal vector: c minus its projections onto A and B. Say it: “capital C”.
bb b.
In projections, the vector projected; in Gram–Schmidt, the second given vector. Say it: “b”.
qq q.
An orthonormal vector (one of the q's). Say it: “q”.
LL L.
The lower triangular factor in A = LU. Say it: “L”.
RR R.
The upper triangular factor in A = QR. Say it: “capital R”.
a1a_{1} a one.
The first column of A. Say it: “a one”.
a2a_{2} a two.
The second column of A. Say it: “a two”.
UU U.
The upper triangular factor in A = LU. Say it: “U”.
II I.
The identity matrix. Say it: “capital I”.
xix_{i} x i.
The i-th component of x̂ (with a hat): qᵢᵀb. Say it: “x sub i”.
aja_{j} a j.
The j-th column of A. Say it: “a sub j”.
q1q_{1} q one.
The first orthonormal vector. Say it: “q one”.
q2q_{2} q two.
The second orthonormal vector. Say it: “q two”.
qiq_{i} q sub i.
The i-th orthonormal vector. Say it: “q sub i”.
qjq_{j} q sub j.
The j-th orthonormal vector. Say it: “q sub j”.
q3q_{3} q three.
The third orthonormal vector. Say it: “q three”.
qnq_{n} q n.
The last orthonormal vector. Say it: “q n”.

Tap or click a symbol in a formula to see the same explanation. All symbols: symbols and notation.

Words on this page

Show the 30 words used here

New here

orthogonal matrix.
A square matrix whose columns are perpendicular unit vectors; it rotates or reflects without changing lengths, and its inverse is its transpose.
Hadamard matrix.
A square matrix whose entries are all +1 or −1 and whose columns are perpendicular to each other.
Gram–Schmidt.
A step-by-step method that turns independent vectors into perpendicular unit vectors that span the same space.

Also used

orthogonal.
At right angles; more generally, of two vectors or functions, having a dot product, or an integral of their product, of zero. Explained in Introduction to Fourier series.
basis.
A set of independent vectors from which every vector in a space can be built, in exactly one way, as a combination. Explained in Independence, basis and dimension.
orthonormal.
Of a set of vectors: each has length one and each is at right angles to all the others. Explained in Projection matrices and least squares.
p..
Page, in a reference to a source; pp. means pages, as in pp. 3–5.
projection matrix.
A matrix that sends every vector to its projection onto a fixed line, plane or subspace. Explained in Projection matrices and least squares.
least squares.
A way to fit a model to data by choosing it to make the sum of the squared errors as small as possible. Explained in Projection matrices and least squares.
vector.
A list of numbers written as a column, or more generally anything that can be added and multiplied by numbers. Explained in Orthogonal vectors and subspaces.
perpendicular.
At right angles to a line, a surface or another direction. Explained in Inclined planes.
linear.
Of a map, operator or equation: respecting sums and multiples, so that L(au + bv) = aL(u) + bL(v). Explained in The geometry of linear equations.
dot product.
A way of multiplying two vectors that gives a number: multiply matching components and add, or lengths times the cosine of the angle between them. Explained in Vectors and the dot product.
matrix.
A rectangular table of numbers, which acts on vectors to give new ones and so describes a linear change of coordinates. Explained in Planes through three points, and matrices.
permutation matrix.
A matrix made by reordering the rows of the identity matrix; multiplying by it reorders the rows of another matrix the same way. Explained in Elimination with matrices.
transpose.
The matrix made by writing the rows of a matrix as columns, flipping it across its main diagonal. Explained in Planes through three points, and matrices.
permutation.
A rearrangement of a list of things into a new order. Explained in Elimination with matrices.
orthonormal basis.
A set of basis vectors that are all at right angles to each other and all of length one. Explained in Basis vectors, the metric and 4-momentum.
span.
The span of some vectors is everything that can be made by combining them; vectors span a space when they fill all of it. Explained in Independence, basis and dimension.
projection.
The shadow of a vector on a line or plane: the nearest point to it there, found by dropping a perpendicular. Explained in Projections onto subspaces.
column space.
All the vectors made by combining the columns of a matrix; Ax = b can be solved exactly when b lies in it. Explained in Matrix multiplication and inverse matrices.
symmetric.
Unchanged by some swap, reflection or turn; for an expression in two quantities, unchanged when they are exchanged. Explained in Introduction to Fourier series.
normal equations.
The equations whose solution gives the least-squares best fit, found by making the error perpendicular to every column.
triangular matrix.
A square matrix with only zeros below its diagonal (upper triangular) or only zeros above it (lower triangular). Explained in Elimination with matrices.
elimination.
Solving equations by subtracting multiples of one from another until each unknown can be found in turn. Explained in The geometry of linear equations.

Academic

transcript.
A written record of exactly what was said in a recorded lecture, word for word.
numerically.
In terms of actual numbers rather than symbols; often worked out step by step, by computer, instead of from an exact formula.
convention.
An agreed choice, such as which direction counts as positive, that could have been made differently.
open question.
A question nobody has yet answered.
error.
The difference between a measured or computed value and the true one; often how large that difference may be.

Tap or click a word, here or in the text, for its meaning in this lesson. All words: the glossary. How many words are marked in the text: Reading options (the “Aa” button).

Where this leads

In cosmology

31 more cosmology pages that build on this

Pages that build on this

Practise

Check your understanding

  1. If QQ has orthonormal columns and is square, what is Q−1Q^{-1}?
  2. With orthonormal columns in QQ, the least-squares solution of Qx=bQx = b is…
  3. Why is RR upper triangular in A=QRA = QR?
0 of 3 answered

Flashcards

1 / 3