Gram-Schmidt turns independent vectors into orthogonal ones with the same span. Keep the first vector; from each next one subtract its projections onto the orthogonal vectors already built.
Recognize the task
The problem asks for an orthogonal or orthonormal basis of a span, a column space or a subspace given by a basis, or for Q in A=QR. Forms: orthogonalize (1,1,0),(2,0,1),(1,1,3); find an orthonormal basis of ColA; orthogonalize 1,x,x2 on [−1,1]. Test: the inputs must be independent; a zero vector during the process means they are not.
Check orthogonality.Every pair of new vectors must have dot product zero; an arithmetic slip shows up here at once.
u1⋅u2=u1⋅u3=u2⋅u3=0 ✓
5
Normalize for an orthonormal basis.Divide each ui by its length (normalization). Rescaling a ui early, for example to clear fractions, does not change the later vectors.
Each step removes the shadow that vj casts on the vectors already built. What remains sticks straight out of their span, so it is perpendicular to all of them, and because the inputs are independent something always remains. Watch the shadows being removed in the Gram-Schmidt visualizer.
Common mistakes
Projecting onto the original vectors
✗u3=v3−projv1v3−projv2v3
✓u3=v3−proju1v3−proju2v3
Dropping the denominator
✗u2=(2,0,1)−(v2⋅u1)u1=(0,−2,1)
✓u2=(2,0,1)−22(1,1,0)=(1,−1,1)
You may skip the division only when u1 is a unit vector.
Normalizing the inputs instead of the outputs
✗normalize v1,v2,v3 and call the result orthonormal
✓orthogonalize first, then divide each ui by ∥ui∥