What the Gram–Schmidt process does
Given linearly independent vectors v₁, …, vk, the Gram–Schmidt process produces vectors u₁, …, uk that are mutually perpendicular and span exactly the same subspace at every stage: span(u₁, …, uᵢ) = span(v₁, …, vᵢ). Dividing each uᵢ by its length gives an orthonormal basis, whose vectors are perpendicular and of length 1.
Orthonormal bases make linear algebra easy: coordinates are just dot products, projections are simple formulas and the matrix of orthonormal columns satisfies QᵀQ = I. The process is the theoretical core of the QR decomposition used in least squares and eigenvalue algorithms.
The formulas
Start with u₁ = v₁. For each later vector subtract its projections onto the earlier u: uᵢ = vᵢ − Σj<i projuⱼ(vᵢ), where proju(v) = ((v·u)/(u·u))·u. The subtracted part is the component of vᵢ that already lies in the span of the previous vectors, so what remains is perpendicular to all of them. The calculator prints the numerator v·u, the denominator u·u and the resulting coefficient for each projection.
Exact results with radicals
Normalization needs square roots. Instead of rounding, this calculator writes each normalized vector as an exact expression: either a rational vector when the length is rational, or √r times a rational vector when it is not, with r square-free. For example (1, 1, 0) normalizes to √2 · (1/2, 1/2, 0), and a decimal approximation is printed beside it. Every orthogonality relation is verified exactly with fractions, never with a tolerance.
Dependent vectors and rank
A quick example by hand: for v₁ = (1, 1) and v₂ = (1, 0), set u₁ = (1, 1). The projection coefficient is (v₂·u₁)/(u₁·u₁) = 1/2, so u₂ = (1, 0) − (1/2)(1, 1) = (1/2, −1/2), which is perpendicular to u₁ because their dot product is 1/2 − 1/2 = 0. Dividing by the lengths √2 and √2/2 gives the orthonormal vectors (1/√2, 1/√2) and (1/√2, −1/√2).
If a vector is a combination of the earlier ones, the subtraction leaves the zero vector. The calculator tells you so and skips it, so the number of orthogonal vectors equals the rank of your input. Classical Gram–Schmidt on floating-point data can lose orthogonality for nearly dependent vectors; with exact fractions this problem does not occur.
Worked examples
These examples are computed by the same engine as the calculator above, so you can compare each step with your own working.
Three vectors in ℝ³
- Vectors:
[[1, 1, 0], [1, 0, 1], [0, 1, 1]]
Orthogonal vectors u
(1, 1, 0), (1/2, −1/2, 1), (−2/3, 2/3, 2/3)
Orthonormal vectors e
√2 · (1/2, 1/2, 0), √6 · (1/6, −1/6, 1/3), √3 · (−1/3, 1/3, 1/3)
exact; radicals shown as √r · (rational vector)
The 3 orthonormal vectors form an orthonormal basis of ℝ3; the matrix with them as columns is an orthogonal matrix.
Step-by-step solution
Formula used
u₁ = v₁, uᵢ = vᵢ − Σ_{j<i} ((vᵢ·uⱼ)/(uⱼ·uⱼ))·uⱼ
eᵢ = uᵢ / ‖uᵢ‖, ‖u‖ = √(u·u)
NoteInput vectors
v1 = (1, 1, 0)
v2 = (1, 0, 1)
v3 = (0, 1, 1)
Method: u₁ = v₁ and uᵢ = vᵢ − Σ proj_{uⱼ}(vᵢ) for j < i, where proj_u(v) = ((v·u)/(u·u))·u.
CalculateVector 1: start with u₁ = v₁
uᵢ = vᵢ − Σ ((vᵢ·uⱼ)/(uⱼ·uⱼ))·uⱼ
u1 = v1 = (1, 1, 0)
CalculateVector 2: subtract projections onto earlier u
uᵢ = vᵢ − Σ ((vᵢ·uⱼ)/(uⱼ·uⱼ))·uⱼ
v2·u1 = 1, u1·u1 = 2 ⇒ coefficient = 1/2
u2 = v2 − (1/2)·u1 = (1/2, −1/2, 1)
CalculateVector 3: subtract projections onto earlier u
uᵢ = vᵢ − Σ ((vᵢ·uⱼ)/(uⱼ·uⱼ))·uⱼ
v3·u1 = 1, u1·u1 = 2 ⇒ coefficient = 1/2
v3·u2 = 1/2, u2·u2 = 3/2 ⇒ coefficient = 1/3
u3 = v3 − (1/2)·u1 − (1/3)·u2 = (−2/3, 2/3, 2/3)
ResultOrthogonal basis
u1 = (1, 1, 0)
u2 = (1/2, −1/2, 1)
u3 = (−2/3, 2/3, 2/3)
CalculateNormalize: eᵢ = uᵢ / ‖uᵢ‖
‖u‖ = √(u·u)
‖u1‖² = 2 ⇒ ‖u1‖ = √2 ≈ 1.4142136
‖u2‖² = 3/2 ⇒ ‖u2‖ = √6/2 ≈ 1.2247449
‖u3‖² = 4/3 ⇒ ‖u3‖ = 2√3/3 ≈ 1.1547005
ResultOrthonormal basis
e1 = √2 · (1/2, 1/2, 0) ≈ (0.707107, 0.707107, 0)
e2 = √6 · (1/6, −1/6, 1/3) ≈ (0.408248, -0.408248, 0.816497)
e3 = √3 · (−1/3, 1/3, 1/3) ≈ (-0.57735, 0.57735, 0.57735)
CheckVerification (exact)
uᵢ·uⱼ = 0 for all i ≠ j ✓
each vᵢ equals uᵢ plus its projections onto the earlier u (reconstructed exactly) ✓
the number of orthogonal vectors (3) equals rank of the input (3) ✓
each eᵢ has length exactly 1 ✓
Two vectors in ℝ²
- Vectors:
[[3, 1], [2, 2]]
Orthogonal vectors u
(3, 1), (−2/5, 6/5)
Orthonormal vectors e
√10 · (3/10, 1/10), √10 · (−1/10, 3/10)
exact; radicals shown as √r · (rational vector)
The 2 orthonormal vectors form an orthonormal basis of ℝ2; the matrix with them as columns is an orthogonal matrix.
Step-by-step solution
Formula used
u₁ = v₁, uᵢ = vᵢ − Σ_{j<i} ((vᵢ·uⱼ)/(uⱼ·uⱼ))·uⱼ
eᵢ = uᵢ / ‖uᵢ‖, ‖u‖ = √(u·u)
NoteInput vectors
v1 = (3, 1)
v2 = (2, 2)
Method: u₁ = v₁ and uᵢ = vᵢ − Σ proj_{uⱼ}(vᵢ) for j < i, where proj_u(v) = ((v·u)/(u·u))·u.
CalculateVector 1: start with u₁ = v₁
uᵢ = vᵢ − Σ ((vᵢ·uⱼ)/(uⱼ·uⱼ))·uⱼ
u1 = v1 = (3, 1)
CalculateVector 2: subtract projections onto earlier u
uᵢ = vᵢ − Σ ((vᵢ·uⱼ)/(uⱼ·uⱼ))·uⱼ
v2·u1 = 8, u1·u1 = 10 ⇒ coefficient = 4/5
u2 = v2 − (4/5)·u1 = (−2/5, 6/5)
ResultOrthogonal basis
u1 = (3, 1)
u2 = (−2/5, 6/5)
CalculateNormalize: eᵢ = uᵢ / ‖uᵢ‖
‖u‖ = √(u·u)
‖u1‖² = 10 ⇒ ‖u1‖ = √10 ≈ 3.1622777
‖u2‖² = 8/5 ⇒ ‖u2‖ = 2√10/5 ≈ 1.2649111
ResultOrthonormal basis
e1 = √10 · (3/10, 1/10) ≈ (0.948683, 0.316228)
e2 = √10 · (−1/10, 3/10) ≈ (-0.316228, 0.948683)
CheckVerification (exact)
uᵢ·uⱼ = 0 for all i ≠ j ✓
each vᵢ equals uᵢ plus its projections onto the earlier u (reconstructed exactly) ✓
the number of orthogonal vectors (2) equals rank of the input (2) ✓
each eᵢ has length exactly 1 ✓
Integer lengths (exact rational result)
- Vectors:
[[3, 4, 0], [1, 0, 2]]
Orthogonal vectors u
(3, 4, 0), (16/25, −12/25, 2)
Orthonormal vectors e
(3/5, 4/5, 0), √29 · (8/145, −6/145, 5/29)
exact; radicals shown as √r · (rational vector)
Step-by-step solution
Formula used
u₁ = v₁, uᵢ = vᵢ − Σ_{j<i} ((vᵢ·uⱼ)/(uⱼ·uⱼ))·uⱼ
eᵢ = uᵢ / ‖uᵢ‖, ‖u‖ = √(u·u)
NoteInput vectors
v1 = (3, 4, 0)
v2 = (1, 0, 2)
Method: u₁ = v₁ and uᵢ = vᵢ − Σ proj_{uⱼ}(vᵢ) for j < i, where proj_u(v) = ((v·u)/(u·u))·u.
CalculateVector 1: start with u₁ = v₁
uᵢ = vᵢ − Σ ((vᵢ·uⱼ)/(uⱼ·uⱼ))·uⱼ
u1 = v1 = (3, 4, 0)
CalculateVector 2: subtract projections onto earlier u
uᵢ = vᵢ − Σ ((vᵢ·uⱼ)/(uⱼ·uⱼ))·uⱼ
v2·u1 = 3, u1·u1 = 25 ⇒ coefficient = 3/25
u2 = v2 − (3/25)·u1 = (16/25, −12/25, 2)
ResultOrthogonal basis
u1 = (3, 4, 0)
u2 = (16/25, −12/25, 2)
CalculateNormalize: eᵢ = uᵢ / ‖uᵢ‖
‖u‖ = √(u·u)
‖u1‖² = 25 ⇒ ‖u1‖ = 5 ≈ 5
‖u2‖² = 116/25 ⇒ ‖u2‖ = 10√29/25 ≈ 2.1540659
ResultOrthonormal basis
e1 = (3/5, 4/5, 0)
e2 = √29 · (8/145, −6/145, 5/29) ≈ (0.297113, -0.222834, 0.928477)
CheckVerification (exact)
uᵢ·uⱼ = 0 for all i ≠ j ✓
each vᵢ equals uᵢ plus its projections onto the earlier u (reconstructed exactly) ✓
the number of orthogonal vectors (2) equals rank of the input (2) ✓
each eᵢ has length exactly 1 ✓
Dependent vector detected
- Vectors:
[[1, 2, 3], [2, 4, 6], [0, 1, 1]]
Orthogonal vectors u
(1, 2, 3), (−5/14, 2/7, −1/14)
Orthonormal vectors e
√14 · (1/14, 1/7, 3/14), √42 · (−5/42, 2/21, −1/42)
exact; radicals shown as √r · (rational vector)
1 input vector was linearly dependent on the earlier ones and skipped, so the basis has 2 vectors.
Step-by-step solution
Formula used
u₁ = v₁, uᵢ = vᵢ − Σ_{j<i} ((vᵢ·uⱼ)/(uⱼ·uⱼ))·uⱼ
eᵢ = uᵢ / ‖uᵢ‖, ‖u‖ = √(u·u)
NoteInput vectors
v1 = (1, 2, 3)
v2 = (2, 4, 6)
v3 = (0, 1, 1)
Method: u₁ = v₁ and uᵢ = vᵢ − Σ proj_{uⱼ}(vᵢ) for j < i, where proj_u(v) = ((v·u)/(u·u))·u.
CalculateVector 1: start with u₁ = v₁
uᵢ = vᵢ − Σ ((vᵢ·uⱼ)/(uⱼ·uⱼ))·uⱼ
u1 = v1 = (1, 2, 3)
CalculateVector 2: subtract projections
v2·u1 = 28, u1·u1 = 14 ⇒ coefficient = 2
u2 = 0: v2 is a linear combination of the earlier vectors, so it adds nothing new and is skipped.
CalculateVector 3: subtract projections onto earlier u
uᵢ = vᵢ − Σ ((vᵢ·uⱼ)/(uⱼ·uⱼ))·uⱼ
v3·u1 = 5, u1·u1 = 14 ⇒ coefficient = 5/14
u3 = v3 − (5/14)·u1 = (−5/14, 2/7, −1/14)
ResultOrthogonal basis
u1 = (1, 2, 3)
u3 = (−5/14, 2/7, −1/14)
CalculateNormalize: eᵢ = uᵢ / ‖uᵢ‖
‖u‖ = √(u·u)
‖u1‖² = 14 ⇒ ‖u1‖ = √14 ≈ 3.7416574
‖u3‖² = 3/14 ⇒ ‖u3‖ = √42/14 ≈ 0.46291005
ResultOrthonormal basis
e1 = √14 · (1/14, 1/7, 3/14) ≈ (0.267261, 0.534522, 0.801784)
e3 = √42 · (−5/42, 2/21, −1/42) ≈ (-0.771517, 0.617213, -0.154303)
CheckVerification (exact)
uᵢ·uⱼ = 0 for all i ≠ j ✓
each vᵢ equals uᵢ plus its projections onto the earlier u (reconstructed exactly) ✓
the number of orthogonal vectors (2) equals rank of the input (2) ✓
each eᵢ has length exactly 1 ✓
Frequently asked questions
What is the difference between orthogonal and orthonormal?
Orthogonal vectors are mutually perpendicular (dot product 0). Orthonormal vectors are orthogonal and each has length 1.
Does the order of the vectors matter?
Yes. Different orders give different orthogonal bases of the same subspace. The first vector always stays in its direction.
How is Gram–Schmidt related to QR decomposition?
If the vectors are the columns of A, then A = QR where the columns of Q are the orthonormal vectors and R is upper triangular with the projection coefficients and lengths.
What if my vectors are dependent?
The calculator detects a zero remainder, skips that vector with an explanation and continues with the rest.