JOVANA
Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
All guides

Gram-Schmidt: Building Right Angles

Take any tilted basis and straighten it into clean right angles. Gram-Schmidt subtracts away projections to remove overlap, then normalizes — and the result is exactly the Q in QR decomposition.

The problem: a tilted basis

A basis just needs to be independent; it does not have to be perpendicular. In practice you often start with a perfectly good but tilted basis whose vectors lean into one another. They still span the space, but coordinates are awkward and overlap muddies the picture. We would much rather have the orthonormal gold standard.

Subtract the overlap, then normalize

The trick is pure projection from the last guide. Keep the first vector as your first direction. For the second vector, ask: how much of it already points along the first direction? Subtract that projection off, and the leftover error is perpendicular to the first — exactly what we wanted. Repeat for each new vector, removing its overlap with every direction fixed so far.

  1. Set u1 = v1 (keep the first vector's direction).
  2. Set u2 = v2 - proj_u1(v2): subtract off v2's overlap with u1.
  3. Continue: each new u subtracts its projection onto all earlier u's.
  4. Finally divide each u by its norm to make it unit length: q = u / norm(u).
v1=(1,1), v2=(2,0)
u1 = (1,1)
proj_u1(v2) = ((u1 dot v2)/(u1 dot u1)) * u1
            = (2/2)*(1,1) = (1,1)
u2 = v2 - (1,1) = (1,-1)
check: u1 dot u2 = 1*1 + 1*(-1) = 0   (perpendicular!)
q1 = (1,1)/sqrt(2),  q2 = (1,-1)/sqrt(2)
Two tilted vectors straightened into a right angle, then normalized.

This is the Q in QR

Gram-Schmidt is not just a tidy exercise — it is a factory. Run it on the columns of a matrix A and the orthonormal vectors you produce become the columns of an orthogonal matrix Q. The bookkeeping of how much you subtracted and rescaled records itself in an upper-triangular matrix R, giving A = Q R, the QR decomposition.