Study and Productivity

The Gram-Schmidt Process Explained, with Exact Answers

How Gram-Schmidt turns any set of vectors into an orthonormal basis, why each projection works, and how to get exact square-root answers you can check.

Saizul Amin
Saizul Amin7 Nov 2026 · 4 min read
The Gram-Schmidt Process Explained, with Exact Answers

The Gram-Schmidt process is a short algorithm with a big reputation for messy arithmetic. The idea fits in one sentence: take your vectors one at a time and remove from each the parts that point along the vectors you have already processed. The mess comes from fractions and square roots. This guide explains the idea, works a full example and shows how to check every coefficient with the free Gram-Schmidt Orthonormalization Calculator.

Why perpendicular vectors are worth the effort

In an orthonormal basis every vector has length 1 and every pair is perpendicular. Coordinates then become dot products: the component of any vector x along a basis vector e is simply x·e, with no system of equations to solve. Projections, least-squares fits and Fourier series all rely on this. Gram-Schmidt is the standard way to get such a basis from vectors that are merely independent.

The one formula you need

The projection of a vector v onto a direction u is (v·u / u·u) times u. It is the shadow of v on the line through u. Subtracting it from v leaves a vector perpendicular to u. Gram-Schmidt applies this repeatedly:

The first orthogonal vector u1 is the first input v1. The second is u2 = v2 minus its projection on u1. The third is u3 = v3 minus its projections on u1 and on u2. Continue until every input has been processed. At the end divide each u by its length to make it a unit vector.

A complete example

Start with v1 = (1, 1, 0), v2 = (1, 0, 1) and v3 = (0, 1, 1).

The first vector is kept: u1 = (1, 1, 0), and u1·u1 = 2.

For the second, v2·u1 = 1, so the coefficient is 1/2. Then u2 = (1, 0, 1) − (1/2)(1, 1, 0) = (1/2, −1/2, 1). Its squared length is 1/4 + 1/4 + 1 = 3/2.

For the third, v3·u1 = 1, so the first coefficient is 1/2. Next v3·u2 = −1/2 + 1 = 1/2, and dividing by 3/2 gives 1/3. So u3 = (0, 1, 1) − (1/2)(1, 1, 0) − (1/3)(1/2, −1/2, 1) = (−2/3, 2/3, 2/3), with squared length 4/3.

Now normalize. Dividing by √2, √(3/2) and √(4/3) gives e1 = (√2/2, √2/2, 0), e2 = (√6/6, −√6/6, √6/3) and e3 = (−√3/3, √3/3, √3/3). The calculator prints exactly these surds, along with each coefficient as a fraction, so you can compare line by line.

Checking your answer

Two quick tests catch almost every error. First, every pair of u vectors must have dot product zero; the tool lists all of them. Second, each e vector must have length 1, which follows automatically if the squared lengths were right. If a dot product is not zero, the mistake is usually in a projection coefficient, so recompute that ratio.

When a vector disappears

If one input is a combination of earlier ones, subtracting its projections leaves the zero vector. That is not an error; it is the algorithm telling you the vector adds nothing new. The calculator marks it as skipped and carries on, and the number of vectors kept is the dimension of the span. Try the example where the second vector is twice the first.

Classical versus modified

The modified version subtracts one projection at a time and uses the updated vector for the next dot product. With exact arithmetic it gives the same answer. With floating-point numbers it keeps the vectors much closer to perpendicular, which is why software libraries use it. The calculator offers both so you can see that the steps differ but the results agree.

From Gram-Schmidt to QR

If you put the original vectors into the columns of a matrix A, the orthonormal vectors form a matrix Q and the coefficients form an upper triangular R with A = QR. The diagonal of R holds the lengths of the u vectors, here √2, √6/2 and 2√3/3. The calculator shows both factors whenever the vectors are independent.

Weighted inner products

Some courses define orthogonality with weights, ⟨x, y⟩ = Σ wᵢxᵢyᵢ. Type positive weights in the box and every projection and length uses them instead of the ordinary dot product.

Your vectors are saved in the browser with undo and redo, and you can copy the bases, download decimal values as CSV or print the full working.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages