About the Gram-Schmidt Calculator
This Gram-Schmidt calculator converts a list of vectors into an orthonormal basis for the space they span. Enter one vector per line — for example (1, 1, 0), (1, 0, 1), (0, 1, 1) — and it returns the orthogonal vectors u₁, u₂, … in exact fractions, the normalized vectors e₁, e₂, … as decimals and in exact form such as (1, −1, 2)/√6, and the length of each u.
It is built for linear algebra students working through Gram-Schmidt by hand, and for anyone preparing a QR decomposition, least-squares fit or projection onto a subspace. Because the arithmetic is done with exact rational numbers, the orthogonal vectors are the same fractions you would get on paper, and linearly dependent vectors are detected exactly rather than by a rounding threshold.
Vectors may have up to 8 components and you can enter up to 8 of them; entries can be integers, decimals or fractions like 1/2. Any vector that is a combination of the earlier ones produces a zero vector and is dropped, so the number of basis vectors equals the rank of the set. The standard dot product is used.
How to use the gram-schmidt calculator
- 1Type each vector on its own line, separating components with spaces or commas.
- 2Order matters: the first vector fixes the direction of e₁.
- 3Read the orthonormal basis in decimals and exact √ form.
- 4Check the orthogonal vectors and the steps table to follow each projection.
- 5Look at the rank to see whether any vectors were dependent.
Formula and method
The Gram-Schmidt process builds orthogonal vectors one at a time. The first is kept as it is. Each later vector has its projection onto every previous orthogonal vector subtracted, leaving only the part that points in a new direction. Dividing each orthogonal vector by its length ‖u‖ = √(u · u) makes it a unit vector, giving an orthonormal basis for the same span.
This calculator performs the projections with exact rational arithmetic, so the u vectors are exact fractions and a dependent input produces an exactly zero vector, which is dropped. The exact orthonormal form scales each u to the smallest whole-number vector w and writes e = w/√(w · w). The decimal basis is rounded to 6 places.
- vₖ
- The k-th input vector
- uₖ
- The k-th orthogonal vector
- eₖ
- The k-th orthonormal (unit) vector
- v · u
- Dot product
Worked examples
Three vectors in ℝ³
u₂ = v₂ − ½u₁ = (½, −½, 1) and u₃ = v₃ − ½u₁ − ⅓u₂ = (−⅔, ⅔, ⅔). Normalizing gives (1, 1, 0)/√2, (1, −1, 2)/√6 and (−1, 1, 1)/√3.
Two vectors in the plane
v₂ · u₁ = 8 and u₁ · u₁ = 10, so u₂ = (2, 2) − 0.8(3, 1) = (−0.4, 1.2). Dividing by the lengths √10 and √1.6 gives the rotated unit vectors shown.
A dependent set
(2, 4, 6) = 2 × (1, 2, 3), so subtracting its projection leaves the zero vector and it is dropped. The third vector gives u₂ = (1, 0, 1) − (4/14)(1, 2, 3) = (5/7, −4/7, 1/7).
Vectors in ℝ⁴
u₁ = (1, 1, 1, 1) has length 2. u₂ = (1, 2, 3, 4) − 2.5u₁ = (−1.5, −0.5, 0.5, 1.5) with length √5, and u₃ = (½, −½, −½, ½) with length 1.
Frequently asked questions
What does the Gram-Schmidt process do?+
It takes a set of linearly independent vectors and produces orthogonal (or orthonormal) vectors spanning the same subspace. Each new vector is the old one minus its projections onto the vectors already found.
What is the difference between orthogonal and orthonormal?+
Orthogonal vectors are mutually perpendicular: every pair has dot product 0. Orthonormal vectors are orthogonal and also have length 1. Gram-Schmidt gives orthogonal vectors u first; dividing each by its length gives the orthonormal e.
Does the order of the vectors matter?+
Yes. The span is the same, but the resulting basis changes with the order because e₁ always points along the first vector, e₂ lies in the plane of the first two, and so on. Reordering gives a different but equally valid orthonormal basis.
What happens if the vectors are linearly dependent?+
A vector that is a combination of earlier ones has nothing left after the projections are removed, so it becomes the zero vector. This calculator drops it and reports it, so the basis size equals the rank of the original set.
How is Gram-Schmidt related to QR decomposition?+
Applying Gram-Schmidt to the columns of a matrix A gives the orthonormal columns of Q, and the projection coefficients and lengths form the upper-triangular R, so that A = QR. QR is used for least-squares problems and eigenvalue algorithms.