Gram-Schmidt calculator
📥 Export options
Exporting...
Transform any set of linearly independent vectors into an orthogonal or orthonormal basis with detailed step-by-step solutions
The Gram-Schmidt process is a fundamental algorithm in linear algebra that converts a set of linearly independent vectors into an orthogonal (perpendicular) or orthonormal (perpendicular with unit length) set. Our calculator performs both orthogonalization and orthonormalization, showing you every step of the transformation.
Quick Navigation
What is the Gram-Schmidt Process?
Definition
The Gram-Schmidt process is an algorithm that takes a set of linearly independent vectors {v₁, v₂, ..., vₙ} and produces an orthogonal set {u₁, u₂, ..., uₙ} that spans the same subspace. The process works by:
- Taking the first vector as is
- Making each subsequent vector orthogonal to all previous ones
- Optionally normalizing to create unit vectors (orthonormalization)
u₂ = v₂ - proj_{u₁}(v₂)
u₃ = v₃ - proj_{u₁}(v₃) - proj_{u₂}(v₃)
...
Key Concepts
📐 Orthogonality
Two vectors are orthogonal if their dot product is zero: u·v = 0. This means they're perpendicular in space.
🎯 Projection
The projection of vector v onto u is: proj_u(v) = ((v·u)/(u·u)) × u
📏 Normalization
A normalized vector has length 1. We normalize by dividing by the vector's magnitude: û = u/||u||
🔄 Basis Preservation
The resulting vectors span exactly the same space as the original vectors.
Orthogonal vs Orthonormal Bases
Property | Orthogonal Basis | Orthonormal Basis |
---|---|---|
Perpendicularity | All vectors perpendicular (u_i · u_j = 0 for i≠j) | All vectors perpendicular (same condition) |
Vector Length | Can be any non-zero length | All vectors have unit length (||u_i|| = 1) |
Dot Product Matrix | Diagonal matrix | Identity matrix |
Computation | Gram-Schmidt without normalization | Gram-Schmidt with normalization |
Use Cases | General orthogonal transformations | QR decomposition, rotations, reflections |
The Gram-Schmidt Algorithm
Classical Gram-Schmidt Process
- Initialize: Set u₁ = v₁
- For each vector vₖ (k = 2 to n):
- Calculate projections onto all previous orthogonal vectors
- Subtract all projections from vₖ
- Result is uₖ, orthogonal to all previous vectors
- Optional - Normalize: For orthonormal basis, divide each uₖ by its magnitude
Mathematical Formulation
For k = 1 to n: u_k = v_k For j = 1 to k-1: u_k = u_k - proj_{u_j}(v_k) where proj_{u_j}(v_k) = (v_k · u_j)/(u_j · u_j) × u_j If orthonormalization required: e_k = u_k / ||u_k||
Modified Gram-Schmidt (More Stable)
Numerical Stability
The modified Gram-Schmidt process reorthogonalizes at each step, providing better numerical stability for computer calculations:
- Instead of subtracting all projections at once, subtract them one by one
- Update the working vector after each projection subtraction
- Reduces accumulation of rounding errors
Step-by-Step Example: 3D Vectors
Given Vectors:
v₁ = [3, 1, 0] v₂ = [2, 2, 0] v₃ = [1, 1, 1]
Step 1 First Orthogonal Vector
Step 2 Second Orthogonal Vector
Calculate projection of v₂ onto u₁:
proj_{u₁}(v₂) = ((v₂·u₁)/(u₁·u₁)) × u₁ = ((2×3 + 2×1 + 0×0)/(3² + 1² + 0²)) × [3, 1, 0] = (8/10) × [3, 1, 0] = [2.4, 0.8, 0]
Step 3 Third Orthogonal Vector
Calculate projections onto u₁ and u₂:
proj_{u₁}(v₃) = ((4)/(10)) × [3, 1, 0] = [1.2, 0.4, 0] proj_{u₂}(v₃) = ((0.8)/(1.6)) × [-0.4, 1.2, 0] = [-0.2, 0.6, 0]
Step 4 Normalize (for Orthonormal Basis)
e₁ = u₁/||u₁|| = [3, 1, 0]/√10 ≈ [0.949, 0.316, 0] e₂ = u₂/||u₂|| = [-0.4, 1.2, 0]/√1.6 ≈ [-0.316, 0.949, 0] e₃ = u₃/||u₃|| = [0, 0, 1]/1 = [0, 0, 1]
Geometric Interpretation
Visual Understanding
The Gram-Schmidt process can be visualized as:
- Step 1: Take the first vector as your first axis direction
- Step 2: Find the component of the second vector perpendicular to the first
- Step 3: Find the component of the third vector perpendicular to the plane of the first two
- Continue: Each new vector is perpendicular to the subspace of all previous ones
🌐 Subspace Preservation
At each step k, the vectors {u₁, ..., uₖ} span the same subspace as {v₁, ..., vₖ}
📊 Dimension Reduction
Each new orthogonal vector explores a new dimension perpendicular to all previous ones
🎨 Coordinate System
The result forms a new coordinate system where all axes are perpendicular
🔄 Rotation Interpretation
Orthonormal bases represent pure rotations (and possibly reflections) of the standard basis
Connection to QR Decomposition
QR Factorization
The Gram-Schmidt process directly produces the QR decomposition of a matrix:
where Q is orthogonal (orthonormal columns) and R is upper triangular.
How It Works
- Matrix A: Original vectors as columns [v₁ | v₂ | ... | vₙ]
- Matrix Q: Orthonormalized vectors as columns [e₁ | e₂ | ... | eₙ]
- Matrix R: Upper triangular matrix with:
- Diagonal entries: R_ii = ||u_i|| (lengths before normalization)
- Upper entries: R_ij = e_i · v_j (projections)
- Lower entries: All zeros
Applications of Gram-Schmidt Process
Mathematical Applications
📐 QR Decomposition
Direct method for QR factorization, essential for solving linear systems and eigenvalue problems
📊 Least Squares
Solving overdetermined systems and finding best-fit solutions through orthogonal projections
🔢 Numerical Stability
Creating stable bases for numerical computations in finite-precision arithmetic
Real-World Applications
🎯 Signal Processing
Creating orthogonal signal bases, wavelet transforms, and Fourier analysis foundations
🖼️ Computer Graphics
Constructing orthonormal coordinate frames, camera matrices, and view transformations
🤖 Machine Learning
Feature decorrelation, whitening transformations, and independent component analysis
🛰️ Communications
CDMA systems, orthogonal frequency-division multiplexing (OFDM), and channel coding
⚛️ Quantum Computing
Creating orthonormal quantum states and implementing quantum gates
📈 Data Science
Principal Component Analysis (PCA) preparation and multicollinearity handling
Numerical Considerations
Method | Stability | Operations | When to Use |
---|---|---|---|
Classical GS | Can be unstable | 2mn² flops | Small matrices, educational purposes |
Modified GS | More stable | 2mn² flops | General purpose, moderate sizes |
GS with Reorthogonalization | Very stable | 4mn² flops | High precision requirements |
Householder QR | Most stable | 2mn² - 2n³/3 flops | Professional applications |
Frequently Asked Questions
Ready to Orthogonalize Your Vectors?
Use our Gram-Schmidt calculator to transform any set of vectors into an orthogonal or orthonormal basis instantly!
Tips for Using Gram-Schmidt Process
- Start with vectors that are already somewhat orthogonal for better numerical stability
- Normalize at the end rather than at each step to avoid accumulating division errors
- For hand calculations, work with fractions to maintain exact values
- Check orthogonality frequently: u_i · u_j should equal zero for i ≠ j
- Remember that the order of input vectors matters - different orders give different results
- Use our Gram-Schmidt calculator to verify your manual calculations
- For large vectors or many dimensions, consider using numerical software