Gram-Schmidt Orthogonalization Calculator
Transform a set of linearly independent vectors into an orthonormal basis using the Gram-Schmidt process. Essential for QR decomposition, least-squares problems, and numerical linear algebra.
About this calculator
The Gram-Schmidt process converts a set of linearly independent vectors {v₁, v₂, …} into a set of orthonormal vectors {e₁, e₂, …} that span the same subspace. The first orthonormal vector is simply e₁ = v₁ / ‖v₁‖, where ‖v₁‖ = √(v₁ₓ² + v₁ᵧ² + v₁_z²). For the second vector, the component of v₂ along e₁ is projected out: u₂ = v₂ − (v₂·e₁)e₁, then normalized to e₂ = u₂ / ‖u₂‖. This projection formula proj_{e₁}(v₂) = (v₂·e₁)e₁ ensures orthogonality. The process repeats for each additional vector. The resulting basis satisfies eᵢ·eⱼ = 0 for i ≠ j and ‖eᵢ‖ = 1 for all i. It underpins QR decomposition and is widely used in numerical methods and signal processing.
How to use
Let v₁ = (3, 0, 0) and v₂ = (1, 1, 0). Step 1: ‖v₁‖ = √(9+0+0) = 3, so e₁ = (1, 0, 0). Step 2: project v₂ onto e₁: (v₂·e₁) = 1·1 + 1·0 + 0·0 = 1, so u₂ = (1,1,0) − 1·(1,0,0) = (0,1,0). Step 3: ‖u₂‖ = 1, so e₂ = (0,1,0). The orthonormal basis is {(1,0,0), (0,1,0)}.
Frequently asked questions
What is the difference between orthogonal and orthonormal vectors?
Orthogonal vectors are simply perpendicular to each other, meaning their dot product is zero. Orthonormal vectors are both orthogonal and each has a magnitude of exactly 1. The Gram-Schmidt process produces an orthonormal basis by first removing shared components between vectors (achieving orthogonality) and then dividing each result by its own length (achieving unit norm). An orthonormal basis is particularly useful because coordinates in that basis are trivially computed using dot products.
How does the Gram-Schmidt process relate to QR decomposition?
QR decomposition factors a matrix A into a product A = QR, where Q is an orthogonal matrix and R is upper triangular. The columns of Q are precisely the orthonormal vectors produced by applying Gram-Schmidt to the columns of A. The entries of R record the projections and norms computed during the process. QR decomposition is used to solve least-squares problems, compute eigenvalues via the QR algorithm, and perform stable numerical computations.
When does the Gram-Schmidt process fail or produce inaccurate results?
The classical Gram-Schmidt process fails if the input vectors are linearly dependent, because at some step a zero vector appears after projection, making normalization impossible. Numerically, it can also lose orthogonality when vectors are nearly parallel, due to floating-point cancellation. The modified Gram-Schmidt algorithm reorders the subtractions to improve numerical stability. For highly ill-conditioned sets, Householder reflections or Givens rotations are preferred alternatives in production software.