Math

Gram-Schmidt & QR

Gram-Schmidt takes independent vectors and subtracts their projections one by one. The result is an orthonormal basis, the first step toward a QR factorization.

7 minLevel 3/3The interactive stage stays ad-free.
q₁ · q₂0.000|q₁|, |q₂|1, 1Remainder1.15Angle90.0°

The amber projection is the part of v₂ already pointing along q₁. Subtracting it leaves the rose remainder, which is perpendicular to q₁. Normalizing gives q₂, so Q = [q₁ q₂] is orthonormal.

What you are seeing

1

Normalize the first vector to get q₁. It keeps the original direction but has length one.

2

Subtract from v₂ its projection onto q₁. The remainder is orthogonal to q₁.

3

Normalize the remainder to get q₂. The matrix Q = [q₁ q₂] is orthogonal, and A = QR with R upper triangular.

Why it matters

Orthogonal bases make projection, least squares, and solving linear systems numerically stable. QR is a workhorse of scientific computing.

Complexity & details

Classical Gram-Schmidt costs O(m n²) for an m×n matrix. Modified Gram-Schmidt is more stable in floating point.

Frequently asked questions

Why subtract the projection?+

The projection is the part of v₂ already explained by q₁. Removing it leaves only the new, orthogonal component.

Why is numerical stability an issue?+

When vectors are nearly dependent, classical Gram-Schmidt can lose orthogonality. Modified Gram-Schmidt and Householder QR reduce this error.