Last verified · v1.0
Calculator · math
Gram Schmidt Orthonormalization Calculator
Compute orthonormal basis vectors from any two linearly independent 2D or 3D vectors using the Gram-Schmidt process. Ideal for linear algebra, machine learning, and physics.
Inputs
Selected Gram-Schmidt Result
—
Explain my result
Get a plain-English breakdown of your result with practical next steps.
The formula
How the
result is
computed.
What Is Gram-Schmidt Orthonormalization?
The Gram-Schmidt process transforms a set of linearly independent vectors into an orthonormal basis — a collection of mutually perpendicular unit vectors that span the same subspace. Named after Danish mathematician Jorgen Pedersen Gram and German mathematician Erhard Schmidt, this algorithm is fundamental to numerical linear algebra, quantum mechanics, signal processing, and machine learning. The Harvey Mudd College Calculus Tutorials identify it as one of the most essential algorithms for constructing orthonormal sets from arbitrary vector collections.
The Gram-Schmidt Formula Explained
For two input vectors v1 and v2, orthonormalization proceeds in three well-defined stages. First, the initial vector is normalized to unit length. Second, the component of the second vector lying along the first is subtracted out. Third, the orthogonal remainder is normalized.
- Stage 1 — Normalize the first vector: e1 = v1 / ‖v1‖
- Stage 2 — Remove the projection of v2 onto v1: u2 = v2 − [(v2 · v1) / (v1 · v1)] v1
- Stage 3 — Normalize the orthogonal remainder: e2 = u2 / ‖u2‖
The scalar ratio (v2 · v1) / (v1 · v1) is the orthogonal projection coefficient. Subtracting that scaled multiple of v1 from v2 guarantees u2 is perpendicular to v1. After normalization, the resulting pair satisfies e1 · e2 = 0 (orthogonality) and ‖e1‖ = ‖e2‖ = 1 (unit length), as established in the University of Connecticut Mathematics orthogonality and least squares notes.
Input Variable Reference
- v1x, v1y, v1z — X, Y, and Z components of the first input vector. Set v1z = 0 for 2D problems.
- v2x, v2y, v2z — X, Y, and Z components of the second input vector. Set v2z = 0 for 2D problems.
- e1 — First orthonormal basis vector, obtained by dividing v1 by its magnitude.
- u2 — Intermediate vector equal to v2 minus its projection onto v1.
- e2 — Second orthonormal basis vector, obtained by normalizing u2.
- Output selector — Specifies which scalar component of the orthonormal result to return (e.g., e1x, e1y, e2x, e2y).
Worked Numerical Example
Take the 2D vectors v1 = (1, 1, 0) and v2 = (1, 0, 0) and apply all three stages to obtain an orthonormal basis for the xy-plane.
Stage 1 — Normalize v1
Magnitude: ‖v1‖ = √(1² + 1²) = √2 ≈ 1.4142. First orthonormal vector: e1 = (1/√2, 1/√2, 0) ≈ (0.7071, 0.7071, 0).
Stage 2 — Subtract the Projection
Dot product: v2 · v1 = (1)(1) + (0)(1) = 1. Self-dot: v1 · v1 = 1 + 1 = 2. Projection coefficient = 1/2 = 0.5. Intermediate vector: u2 = (1, 0, 0) − 0.5 × (1, 1, 0) = (0.5, −0.5, 0).
Stage 3 — Normalize u2
Magnitude: ‖u2‖ = √(0.25 + 0.25) = 1/√2 ≈ 0.7071. Second orthonormal vector: e2 = (1/√2, −1/√2, 0) ≈ (0.7071, −0.7071, 0). Verification: e1 · e2 = (0.7071)(0.7071) + (0.7071)(−0.7071) = 0.5 − 0.5 = 0 ✓. Both vectors carry unit length ✓.
Classical vs. Modified Gram-Schmidt
The classical formulation above is mathematically exact but can accumulate floating-point rounding errors when input vectors are nearly parallel. The modified Gram-Schmidt algorithm updates projection coefficients sequentially after each subtraction step, dramatically reducing numerical error in ill-conditioned cases. For well-separated input vectors, both variants yield identical results. The University of Southern Mississippi study on numerical Gram-Schmidt orthonormalization and the Duke University Math 218D worksheet solutions provide rigorous treatment of both variants and their stability properties across higher-dimensional matrices.
Real-World Applications
- Machine Learning (PCA): Principal Component Analysis uses orthonormal eigenvectors to decorrelate features and reduce dimensionality in datasets with thousands of variables.
- QR Decomposition: Factoring a matrix A into orthogonal Q and upper-triangular R — central to least-squares regression and eigenvalue solvers — directly applies Gram-Schmidt to A's column vectors.
- Quantum Mechanics: Valid quantum state vectors must form orthonormal sets; Gram-Schmidt constructs admissible basis states from arbitrary wave functions in Hilbert space.
- Computer Graphics: Tangent-space normal mapping and per-frame camera orientation matrices require orthonormal frames recomputed via this process every render cycle.
- Signal Processing: Orthonormal filter banks and wavelet transforms depend on orthonormal bases for efficient, lossless decomposition of audio and image signals used in MP3 and JPEG compression.
Reference