Linear Algebra
Chapter 5/Orthogonality

5.6Gram–Schmidt

Orthonormal bases are wonderful; the problem is getting one. Gram–Schmidt manufactures an orthonormal basis from any basis by repeatedly subtracting projections — and its bookkeeping is the QR factorization.

What you must be able to do

  • ; then where projects onto the span of .
  • Each partial span is preserved: .
  • QR: with having orthonormal columns and upper triangular with positive diagonal. , .
  • Least squares becomes back substitution: .
Theorem 5.6.1 · Gram–Schmidt
Let be a basis for an inner product space . Define and, recursively,

Then is an orthonormal basis for , and each is orthogonal to everything built before it.

Shortcut
By hand, don't normalise as you go. Compute the un-normalised first — everything stays rational and the square roots only appear at the very end.
Theorem 5.6.2 · Gram–Schmidt QR
If is with rank , then where is with orthonormal columns and is upper triangular with positive diagonal entries.

is upper triangular precisely because is built only from , so it has no component along later inputs.

Theorem 5.6.3 · Least squares via QR
With of rank , the unique least squares solution of solves

Substituting into the normal equations: and , then cancel the nonsingular . is triangular, so finish with back substitution — no inverse anywhere.

Worked example

Gram–Schmidt and QR on a matrix

0/5 steps
Apply Gram–Schmidt to the columns of and write .
Check your work

Gram–Schmidt & QR

Columns of the matrix are the input vectors. The un-normalised vectors stay exact; Q and R are shown numerically because norms bring in square roots.

v₁ = x₁
1
1
1
1
‖v‖² = 4 , ‖v‖ = 2
v₂ = x₂ − (3/2)v₁
-5/2
5/2
5/2
-5/2
‖v‖² = 25 , ‖v‖ = 5
v₃ = x₃ − (1)v₁ − (-2/5)v₂
2
-2
2
-2
‖v‖² = 16 , ‖v‖ = 4
Q (orthonormal columns)
0.5-0.50.5
0.50.5-0.5
0.50.50.5
0.5-0.5-0.5
R (upper triangular, positive diagonal)
232
05-2
004

Check yourself

Q1
In Gram–Schmidt, the next vector is . What is ?
T / F
If is of rank and is its Gram–Schmidt factorization, then the least squares solution of satisfies .
T / F
Gram–Schmidt can be applied to any spanning set, independent or not, and always returns an orthonormal basis of the same size.