Gram-Schmidt Orthogonalization Calculator

Apply the Gram-Schmidt process to 2–4 vectors in R², R³, or R⁴. View step-by-step projections, orthonormal results, dot-product verification matrix, and norm comparison bars.

Gram-Schmidt Orthogonalization Calculator

Input Vectors

v1:
v2:
v3:
Orthogonal Set
✓ Verified
All pairwise dot products are zero — vectors are mutually orthogonal.
Orthonormal Set
✓ Yes
All output vectors have unit length.
u1 (orthogonal)
(1.0000, 1.0000, 1.0000)
‖u1‖ = 1.732051
u2 (orthogonal)
(0.3333, 0.3333, -0.6667)
‖u2‖ = 0.816497
u3 (orthogonal)
(0.5000, -0.5000, 0.0000)
‖u3‖ = 0.707107
ê1 (orthonormal)
(0.5774, 0.5774, 0.5774)
‖ê1‖ = 1.000000
ê2 (orthonormal)
(0.4082, 0.4082, -0.8165)
‖ê2‖ = 1.000000
ê3 (orthonormal)
(0.7071, -0.7071, 0.0000)
‖ê3‖ = 1.000000

Projection Steps

Stepproj(v onto u)Result‖proj‖
proju1(v2)v2 → u1(0.6667, 0.6667, 0.6667)1.1547
proju1(v3)v3 → u1(0.3333, 0.3333, 0.3333)0.5774
proju2(v3)v3 → u2(0.1667, 0.1667, -0.3333)0.4082

Orthogonal Vector Norms

u1
1.7321
u2
0.8165
u3
0.7071

Dot Product Verification

u1u2u3
u13.00000.00000.0000
u20.00000.66670.0000
u30.00000.00000.5000
Planning notes, formulas, and examples

About the Gram-Schmidt Orthogonalization Calculator

The Gram-Schmidt process is a fundamental algorithm in linear algebra that converts a set of linearly independent vectors into an orthogonal (or orthonormal) set spanning the same subspace. Given input vectors v₁, v₂, …, vₖ, it produces u₁, u₂, …, uₖ such that every pair uᵢ · uⱼ = 0 for i ≠ j. Optionally normalizing each uᵢ to unit length yields an orthonormal basis.

This calculator implements the classical Gram-Schmidt algorithm for vectors in R², R³, and R⁴ with up to four input vectors. Enter your vectors component-by-component or select from built-in presets that demonstrate common scenarios — standard bases, physics-motivated triples, and higher-dimensional examples.

Each step is displayed in a projections table showing which vector is being projected onto which orthogonal vector, the resulting projection vector, and its magnitude. After the process completes, the output shows the full orthogonal set with norms and, if requested, the orthonormal set with unit-length verification.

A color-coded dot-product verification matrix confirms orthogonality: off-diagonal entries should be zero (green), while diagonal entries (blue) show each vector's self-dot-product. Norm comparison bars let you quickly see relative magnitudes across the orthogonal set, revealing how the process redistributes length among the basis vectors.

The Gram-Schmidt process underpins QR decomposition, least-squares approximation, and many numerical methods. Understanding it visually through step-by-step projections builds intuition for how orthogonal bases simplify computations across mathematics, physics, and engineering.

When This Page Helps

The Gram-Schmidt process involves iterative projections and subtractions that accumulate rounding errors, especially with near-parallel input vectors. Keeping track of which projection has been subtracted from which vector quickly becomes overwhelming for more than two vectors. This calculator performs the full orthogonalization, displays every projection step, verifies orthogonality via a dot-product matrix, and normalizes the output to produce an orthonormal basis. It is essential for students learning QR decomposition, engineers constructing coordinate frames, and anyone building orthonormal bases for least-squares problems.

How to Use the Inputs

  1. Select the vector space dimension (R², R³, or R⁴)
  2. Choose how many vectors to orthogonalize (2, 3, or 4)
  3. Enter vector components in the input fields or click a preset
  4. View the orthogonal and orthonormal output vectors in the output cards
  5. Examine the projection steps table to understand each subtraction
  6. Check the dot-product verification matrix for confirmed orthogonality
Formula used
uₖ = vₖ − Σⱼ₌₁ᵏ⁻¹ proj_{uⱼ}(vₖ), where proj_u(v) = (v · u / u · u) u; êₖ = uₖ / ‖uₖ‖

Example Calculation

Result: u₁ = (1, 1, 1), u₂ = (⅓, ⅓, −⅔), u₃ = (½, −½, 0)

u₁ = v₁. u₂ = v₂ − proj_{u₁}(v₂) = (1,1,0) − (⅔)(1,1,1) = (⅓,⅓,−⅔). u₃ = v₃ − proj_{u₁}(v₃) − proj_{u₂}(v₃) = (½,−½,0). Dot products u₁·u₂ = 0, u₁·u₃ = 0, u₂·u₃ = 0 — confirmed orthogonal.

Tips & Best Practices

  • Linearly dependent vectors produce a zero vector in the output — this flags redundancy in the input set
  • For numerical stability with near-parallel vectors, consider the modified Gram-Schmidt variant
  • The order of input vectors matters: reordering produces a different (but equally valid) orthogonal basis
  • The first orthogonal vector u₁ always equals v₁ — no projection is needed for the first vector
  • Orthonormal bases simplify dot products to simple component sums: coordinates in an orthonormal basis are just projections

The Classical Gram-Schmidt Algorithm

Given input vectors v₁, v₂, …, vₖ, the classical Gram-Schmidt process computes orthogonal vectors u₁, u₂, …, uₖ iteratively. Set u₁ = v₁. For each subsequent vector vₖ, subtract its projections onto all previously computed orthogonal vectors: uₖ = vₖ − Σⱼ₌₁ᵏ⁻¹ proj_{uⱼ}(vₖ), where proj_u(v) = (v·u / u·u)u. Each subtraction removes the component of vₖ in the direction of uⱼ, leaving only the component orthogonal to all previous vectors. Normalizing each uₖ to unit length yields an orthonormal basis.

Modified Gram-Schmidt and Numerical Stability

The classical algorithm is numerically unstable for near-parallel vectors: accumulated floating-point errors cause the output vectors to lose orthogonality. The **modified Gram-Schmidt** variant improves stability by re-projecting against the partially orthogonalized vector after each subtraction rather than against the original vₖ. In exact arithmetic both versions produce identical results, but modified Gram-Schmidt maintains orthogonality to machine precision in practice. For even better stability, Householder reflections (used in QR factorization) are preferred.

Connection to QR Decomposition

Gram-Schmidt is the constructive proof behind **QR decomposition**: A = QR, where Q’s columns are the orthonormal vectors and R is upper triangular with entries rᵢⱼ = qᵢ · vⱼ. QR decomposition is used in least-squares regression (solving overdetermined systems), eigenvalue algorithms (QR iteration), and solving linear systems that are ill-conditioned. Understanding the Gram-Schmidt process provides concrete intuition for why orthonormal bases simplify so many computations — projections become dot products, and least-squares solutions reduce to back substitution.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • It is an algorithm that takes a set of linearly independent vectors and produces an orthogonal (or orthonormal) set spanning the same subspace by iteratively subtracting projections onto previously computed orthogonal vectors.