Orthogonal bases make coordinates and projections easy, but the bases you meet in practice (columns of a matrix, solutions of a system) are rarely orthogonal. The Gram-Schmidt process fixes that: it turns any basis of a subspace into an orthogonal basis of the same subspace, one vector at a time, using nothing but projections.
The idea with two vectors
Suppose W=Span{x1,x2} with x1,x2 independent but not orthogonal. Keep the first vector: v1=x1. From x2, subtract its projection onto v1:
v2=x2−v1⋅v1x2⋅v1v1.
This is the component of x2 orthogonal to v1, so v1⋅v2=0. It is still in W, being a combination of x2 and x1. And it isn't 0, because x2 is not a multiple of x1. So {v1,v2} is an orthogonal basis for W.
Worked example: Two vectors in R³
Find an orthogonal basis for W=Span{x1,x2}, where x1=(1,2,2) and x2=(4,5,2).
Let v1=x1. Then x2⋅v1=4+10+4=18 and v1⋅v1=9, so
v2=(4,5,2)−918(1,2,2)=(4,5,2)−(2,4,4)=(2,1,−2).
Check: v1⋅v2=2+2−4=0. So {(1,2,2),(2,1,−2)} is an orthogonal basis for W.
The general process
For more vectors, keep going: each new xk has its projection onto the span of all the earlier v's removed. Because those earlier v's are already orthogonal, that projection is just a sum of one-line projections.
The Gram-Schmidt process
Given a basis {x1,…,xp} of a subspace W of Rn, define
Then {v1,…,vp} is an orthogonal basis for W. Moreover, for each k, Span{v1,…,vk}=Span{x1,…,xk}.
In the language of the last lesson, vk=xk−projWk−1xk, where Wk−1=Span{x1,…,xk−1}. By the orthogonal decomposition theorem, vk is orthogonal to Wk−1, hence to all earlier v's.
Tip
You may rescale any vk before moving on, for example to clear fractions. Scaling doesn't change orthogonality or the span, and it keeps later arithmetic clean. Just be sure to use the rescaled vector consistently in every later step.
Worked example: Three vectors in R⁴
Apply Gram-Schmidt to x1=(1,0,1,0), x2=(1,1,1,1), x3=(0,1,2,1).
Check all pairs: v1⋅v2=0, v1⋅v3=−1+1=0, v2⋅v3=0. The orthogonal basis is {(1,0,1,0),(0,1,0,1),(−1,0,1,0)}.
Common mistake
In step k, project xk onto the new vectors v1,…,vk−1, not onto the original x1,…,xk−1. The one-line projections only add up correctly because the v's are orthogonal; the x's are not.
Orthonormal bases
To get an orthonormal basis, run Gram-Schmidt and then normalize each vk. Normalize at the end, not along the way: dividing by square roots mid-process fills every later step with radicals.
For the first example, ∥v1∥=∥v2∥=3, so an orthonormal basis for W is
q1=31(1,2,2),q2=31(2,1,−2).
If the input vectors are dependent, Gram-Schmidt reveals it: some vk comes out as 0, meaning xk was already in the span of the earlier vectors. Drop it and continue.
QR factorization
Gram-Schmidt, written in matrix form, is a factorization.
QR factorization
If A is an m×n matrix with linearly independent columns, then A=QR, where Q is m×n with orthonormal columns forming a basis of ColA, and R is an n×n upper triangular invertible matrix with positive diagonal entries.
To build it, apply Gram-Schmidt to the columns of A and normalize to get the columns of Q. Then, since QTQ=I, multiplying A=QR on the left by QT gives
R=QTA.
R is upper triangular because, by the span property, column k of A is a combination of q1,…,qk only, so its inner products with qk+1,qk+2,… are all 0.
Worked example: A QR factorization
Find a QR factorization of A=122452.
The columns are x1 and x2 from the first example, so
Check: column 2 of QR is 6q1+3q2=(2,4,4)+(2,1,−2)=(4,5,2), which is column 2 of A.
The diagonal entries of R have a meaning: rkk=∥vk∥, the length of the new direction found at step k. Computers use QR factorizations to solve least-squares problems stably, as you'll see in the next lesson.
Practice
Practice 1
Apply Gram-Schmidt to x1=(2,1,2) and x2=(4,−1,1). Find v2.
Enter a point like (2, -3)
Practice 2
Apply Gram-Schmidt to x1=(1,−1,1) and x2=(4,0,2), then normalize. Find the second orthonormal vector q2. Give exact values (you may type sqrt).
Enter a point like (2, -3)
Practice 3
Apply Gram-Schmidt to x1=(3,4,0) and x2=(1,1,1). Rescale v2 to clear fractions: enter the multiple of v2 whose third entry is 25.
Enter a point like (2, -3)
Practice 4
Apply Gram-Schmidt to x1=(1,1,1,1), x2=(2,0,2,0), x3=(4,2,2,0). Find v3.
Enter a point like (2, -3)
Practice 5
Let A=12215−1 and A=QR be its QR factorization. Find the entry r22 of R as an exact value.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 6
You apply Gram-Schmidt to x1,x2,x3 and find v3=0. What does that tell you?
Practice 7
A is a 5×3 matrix with linearly independent columns and A=QR. Which statement is true?