Orthogonality
Orthogonal projections, bases, and distances
Orthogonalization
Projections & Decompositions
Distance Geometry
💡 Need Help?
- • Enter fractions like
1/2 - • Use decimals like
0.5 - • Click "Load Example" to try a preset
- • Click any step to copy LaTeX
Gram Schmidt Calculator
The Gram-Schmidt process converts a set of linearly independent vectors into an orthogonal (or orthonormal) basis that spans the same subspace. This is fundamental for QR decomposition, least squares, and many other linear algebra applications.
📑 Quick Navigation
What is the Gram-Schmidt Process?
The Gram-Schmidt process is a method for converting a set of linearly independent vectors into a set of orthogonal (or orthonormal) vectors that span the same subspace.
Core Idea: Starting with vectors {v₁, v₂, ..., vₖ}, the Gram-Schmidt process produces orthogonal vectors {u₁, u₂, ..., uₖ} where each uᵢ is orthogonal to all previous uⱼ (j < i).
💡 Memory Aid: "Gram-Schmidt takes a messy set of vectors and straightens them out into perpendicular directions."
Why Do We Need an Orthogonal Basis?
✅ Advantages of Orthogonal Bases
- Easy coordinates: Finding coefficients is simple dot products
- No linear dependencies: Each direction is independent
- Numerical stability: Less rounding error in computations
- QR decomposition: Foundation for solving least squares
- Projections become simple: Just dot products!
❌ Problems with Non-Orthogonal Bases
- Messy coordinates: Need to solve linear systems
- Redundancy: Vectors may be nearly dependent
- Numerical issues: Small errors become large
- Hard to visualize: Skewed coordinate axes
Simple Example: In ℝ², the standard basis e₁ = (1,0) and e₂ = (0,1) is orthonormal. Any vector (x,y) has coordinates x and y directly. Try finding coordinates in a non-orthogonal basis like (1,0) and (1,1)—much harder!
The Algorithm Step by Step
Given linearly independent vectors v₁, v₂, ..., vₖ, we produce orthogonal vectors u₁, u₂, ..., uₖ:
Step 1: Start with the first vector
Step 2: Remove projections onto previous vectors
Step 3: Continue for each vector
For Orthonormal Vectors: To get orthonormal vectors (unit length), normalize each uᵢ:
💡 Geometric Interpretation: At each step, you subtract the projections of the current vector onto all previously computed orthogonal vectors. What remains is perpendicular to all of them!
Complete Example
Problem: Apply Gram-Schmidt to vectors in ℝ³:
Step 1: Set u₁ = v₁
Step 2: Compute u₂
First, compute the projection of v₂ onto u₁:
Step 3: Compute u₃
Compute projections onto u₁ and u₂:
Step 4: Normalize (for orthonormal basis)
✅ Verification: Check that e₁·e₂ = 0, e₁·e₃ = 0, and e₂·e₃ = 0. All dot products should be zero!
Modified vs Classical Gram-Schmidt
Classical Gram-Schmidt
- Computes all projections using original vₖ
- More prone to rounding errors
- Loss of orthogonality in floating-point
Modified Gram-Schmidt
- Subtracts projections sequentially
- More numerically stable
- Better orthogonality in practice
⚠️ Numerical Note: For ill-conditioned vectors (nearly dependent), Modified Gram-Schmidt is significantly more accurate. Our calculator uses Modified Gram-Schmidt by default!
Key Properties
Span Preservation
The orthogonal set {u₁, u₂, ..., uₖ} spans the same subspace as the original vectors {v₁, v₂, ..., vₖ}.
Pythagorean Theorem
For any vector, the squared norm equals sum of squared projection lengths:
QR Decomposition
Gram-Schmidt is the foundation of QR decomposition:
where Q has orthonormal columns, R is upper triangular.
Real-World Applications
📊 Data Science & ML
- QR Decomposition: Solving least squares problems
- Principal Component Analysis (PCA): Finding orthogonal components
- Feature Engineering: Creating uncorrelated features
- Signal Processing: Separating mixed signals
🔬 Engineering & Physics
- Quantum Mechanics: Orthogonal quantum states
- Vibration Analysis: Normal modes are orthogonal
- Control Theory: Controllability and observability
- Structural Analysis: Orthogonal deformation modes
📐 Mathematics
- Orthogonal Polynomials: Legendre, Chebyshev, Hermite
- Functional Analysis: Orthogonal functions (Fourier series)
- Numerical Analysis: Stable basis construction
- Linear Algebra: Basis orthogonalization
🤖 Computer Graphics
- Coordinate Frames: Building orthonormal bases
- Camera Orientation: Orthogonal view axes
- 3D Rotations: Orthogonal rotation matrices
- Surface Normals: Computing perpendicular vectors
Special Cases & Limitations
| Scenario | What Happens | What to Do |
|---|---|---|
| Vectors are linearly dependent | Some uᵢ becomes zero | Detect dependence; cannot orthogonalize full set |
| Vectors nearly dependent | Numerical instability, loss of orthogonality | Use Modified Gram-Schmidt or reorthogonalization |
| Large number of vectors | Accumulated rounding errors | Use Householder QR for better stability |
| Complex vectors | Works the same with conjugate transpose | Use Hermitian inner product |
⚠️ Important: Gram-Schmidt requires linearly independent input vectors. If vectors are dependent, the process will produce a zero vector, indicating dependence.
Frequently Asked Questions
Q: Does Gram-Schmidt change the span of the vectors?
A: No! The orthogonal set spans exactly the same subspace as the original vectors. This is a key property—you lose no information.
Q: What's the difference between orthogonal and orthonormal?
A:
- Orthogonal: Vectors are perpendicular (dot product = 0)
- Orthonormal: Orthogonal + each vector has length 1
Q: Can Gram-Schmidt fail?
A: It fails (produces zero vectors) when the input vectors are linearly dependent. The process detects dependence naturally—if any uᵢ = 0, the original vectors were dependent.
Q: Why do we need orthogonal bases?
A: Orthogonal bases make computations much easier! In an orthonormal basis, the coordinates of any vector are simply dot products with the basis vectors. No linear system solving needed!
Q: What's the connection to QR decomposition?
A: Gram-Schmidt directly gives QR decomposition: Q contains the orthonormal vectors, and R contains the projection coefficients. This is foundational for solving least squares problems.
Q: Is Gram-Schmidt the most stable method?
A: Not for large or ill-conditioned problems. Householder transformations and Givens rotations are more stable, but Gram-Schmidt is simpler and sufficient for many applications.
Practice Problems
Beginner
- Apply Gram-Schmidt to
v₁ = (2,0),v₂ = (1,3)in ℝ². - Are
u₁ = (1,1)andu₂ = (1,-1)orthogonal? Orthonormal? - Normalize
u = (3,4)to get a unit vector.
Intermediate
- Apply Gram-Schmidt to
v₁ = (1,2,2),v₂ = (-1,0,2),v₃ = (0,0,1). - Check if
v₁ = (1,1,1),v₂ = (1,0,1),v₃ = (0,1,0)are linearly independent using Gram-Schmidt. - Find the QR decomposition of
A = [v₁, v₂]wherev₁ = (3,1),v₂ = (2,2).
Advanced
- Prove that Gram-Schmidt preserves the span of the original vectors.
- Why does Modified Gram-Schmidt have better numerical stability?
- Show that if vectors are linearly dependent, Gram-Schmidt produces a zero vector.
Click to reveal solutions
1. u₁ = (2,0), u₂ = (1,3) - (2,0)·(1,3)/(4) · (2,0) = (1,3) - 0.5·(2,0) = (0,3)
2. Dot product = 0 → orthogonal. Lengths = √2, not 1 → not orthonormal.
3. ê = (3/5, 4/5)
4. u₁ = (1,2,2), u₂ = (-4/3, -2/3, 2/3), u₃ = (1/2, 0, -1/2)
5. Independent (no zero vectors produced)
6. Q = [u₁/‖u₁‖, u₂/‖u₂‖], R = [‖u₁‖, projection coefficients]
7. Each uₖ is a linear combination of original v₁...vₖ, so span preserved.
8. Modified version removes projections earlier, reducing rounding error accumulation.
9. If dependent, some vₖ is combination of earlier vectors, making uₖ zero.
Summary
🎯 Key Takeaways
- Purpose: Convert any set of independent vectors into orthogonal/orthonormal vectors
- Formula: uₖ = vₖ - Σ (projection of vₖ onto previous uⱼ)
- Span preserved: Orthogonal set spans same subspace
- Normalization: Divide by length to get orthonormal
- Modified version: More numerically stable for real computations
- Applications: QR decomposition, least squares, PCA, quantum mechanics
💡 Quick Check: After Gram-Schmidt, always verify orthogonality: dot product between different uᵢ should be zero (or very close in floating-point)!
Try It Yourself!
Use the calculator above to orthogonalize your own vectors:
- Enter your vectors as rows or components
- Choose normalization (orthogonal vs orthonormal)
- Select algorithm (Classical vs Modified Gram-Schmidt)
- Click "Calculate" to see:
- Each orthogonalization step
- Projection calculations
- Final orthogonal/orthonormal basis
- Verification of orthogonality
Test these examples:
- ℝ² example:
v₁ = (2,0),v₂ = (1,3) - ℝ³ example:
v₁ = (1,1,0),v₂ = (1,0,1),v₃ = (0,1,1) - Dependent test:
v₁ = (1,2),v₂ = (2,4)(see what happens!) - Normalization test: Compare orthogonal vs orthonormal output
📐 Pro Tip: Use the "Load Example" dropdown to quickly try common cases. Watch how each step subtracts projections to create perpendicular vectors!