Gram-Schmidt Calculator | Orthogonalization, Orthonormal Basis & QR Decomposition
Apply the Gram-Schmidt process to 2–4 linearly independent vectors in R²–R⁴ to produce an orthogonal basis and orthonormal basis. Displays the full QR decomposition Q·R = A and verifies orthogonality via dot products.
Gram-Schmidt Orthogonalization
What Is the Gram-Schmidt Calculator | Orthogonalization, Orthonormal Basis & QR Decomposition?
The Gram-Schmidt process converts a set of linearly independent vectors {v₁, …, vₖ} in Rⁿ into an orthogonal basis {u₁, …, uₖ} and then an orthonormal basis {e₁, …, eₖ}. Each new vector uₖ is obtained by subtracting from vₖ its projections onto all previously computed basis vectors. This calculator supports k = 2, 3, or 4 vectors in R² through R⁴ and also computes the QR decomposition: A = Q·R, where Q has orthonormal columns and R is upper triangular.
Formula
u₁ = v₁ | uₖ = vₖ − Σᵢ₌₁ᵏ⁻¹ (vₖ·uᵢ / ‖uᵢ‖²)·uᵢ | eₖ = uₖ / ‖uₖ‖
How to Use
- 1
Click a preset (e.g. "{(1,1),(1,−1)} in R²") to auto-fill, or set the dimension and number of vectors using the toggle buttons.
- 2
Enter each vector's components in the row grid — one vector per row, one component per cell.
- 3
Click "Compute" to run the Gram-Schmidt process.
- 4
Read the orthogonal vectors {u₁, u₂, …} and their norms in the results panel.
- 5
Examine the orthonormal vectors {e₁, e₂, …} — each has unit length (‖eᵢ‖ = 1).
- 6
Verify orthogonality from the dot product matrix: diagonal entries should be 1, off-diagonal entries should be 0.
- 7
Inspect the QR decomposition: columns of Q are the eᵢ vectors; R is upper triangular with rᵢⱼ = vⱼ·eᵢ.
Select the number of vectors (2–4) and their dimension (R² to R⁴), enter the vector components in the grid, and click Compute.
Example Calculation
Vectors in R³: v₁ = (1,0,0), v₂ = (1,1,0), v₃ = (1,1,1). u₁ = v₁ = (1,0,0). u₂ = v₂ − (v₂·u₁/‖u₁‖²)u₁ = (1,1,0) − 1·(1,0,0) = (0,1,0). u₃ = v₃ − (v₃·u₁)u₁ − (v₃·u₂)u₂ = (1,1,1) − (1,0,0) − (0,1,0) = (0,0,1). All norms = 1, so e₁=(1,0,0), e₂=(0,1,0), e₃=(0,0,1) — the standard basis. Q = I₃, R = [[1,1,1],[0,1,1],[0,0,1]].
Understanding Gram-Schmidt | Orthogonalization, Orthonormal Basis & QR Decomposition
Gram-Schmidt in R² and R³ — Worked Examples
| Input Vectors | u₁ (orthogonal) | u₂ (orthogonal) | ‖u₁‖ | ‖u₂‖ | e₁ | e₂ |
|---|---|---|---|---|---|---|
| (1,0),(1,1) | (1,0) | (0,1) | 1 | 1 | (1,0) | (0,1) |
| (1,1),(1,−1) | (1,1) | (1,−1) | √2 | √2 | (1/√2,1/√2) | (1/√2,−1/√2) |
| (2,0),(1,1) | (2,0) | (0,1) | 2 | 1 | (1,0) | (0,1) |
| (3,4),(1,0) | (3,4) | (16/25,−12/25) | 5 | 4/5 | (3/5,4/5) | (4/5,−3/5) |
| (1,1,0),(1,0,1) | (1,1,0) | (1/2,−1/2,1) | √2 | √(3/2) | e₁=v₁/√2 | e₂=u₂/‖u₂‖ |
QR Decomposition Properties Reference
| Property | Q matrix | R matrix | Use case |
|---|---|---|---|
| Orthogonality | Qᵀ·Q = I (orthonormal cols) | Upper triangular, positive diagonal | Solving Ax = b stably |
| Determinant | det(Q) = ±1 | det(R) = Π rᵢᵢ | det(A) = det(Q)·det(R) |
| Least squares | x_LS = R⁻¹·Qᵀ·b | Back-substitution on R | Normal equations without forming AᵀA |
| Eigenvalues | QR iteration: A ← RQ | Converges to Schur form | Numerical eigenvalue computation |
| Inverse | Q⁻¹ = Qᵀ | R⁻¹ is upper triangular | A⁻¹ = R⁻¹·Qᵀ |
Gram-Schmidt vs. Other Orthogonalization Methods
- ›Classical Gram-Schmidt (CGS): Subtracts all projections onto previous vectors in one pass. Fast but numerically unstable for nearly dependent inputs — round-off errors can accumulate.
- ›Modified Gram-Schmidt (MGS): Reorders the subtractions to subtract each projection immediately after computing it. Produces the same result mathematically but is far more numerically stable.
- ›Householder reflections: An alternative that produces the same QR decomposition using reflections rather than projections. More numerically stable than MGS but harder to interpret geometrically.
- ›Givens rotations: Build QR using a series of 2D rotations, useful for sparse matrices where most operations can be skipped.
- ›This calculator implements Classical Gram-Schmidt, which is clear for educational purposes. For high-precision applications, Modified Gram-Schmidt or Householder reflections are preferred.
Frequently Asked Questions
What is the difference between orthogonal and orthonormal?
Orthogonal vectors are pairwise perpendicular: their dot products are zero (uᵢ·uⱼ = 0 for i ≠ j). Orthonormal vectors are orthogonal AND each has unit length (‖eᵢ‖ = 1). The Gram-Schmidt process first produces orthogonal vectors {uᵢ}, then normalizes them to get orthonormal vectors {eᵢ = uᵢ/‖uᵢ‖}.
What does "projection onto u" mean?
The projection of vector v onto vector u is proj_u(v) = (v·u / u·u)·u. It is the component of v in the direction of u. Subtracting this from v removes that directional component, leaving a vector perpendicular to u. The Gram-Schmidt process applies this subtraction iteratively to eliminate all components in the directions of previously found basis vectors.
What happens if the input vectors are linearly dependent?
If a vector vₖ is in the span of the previous vectors, the Gram-Schmidt subtraction yields the zero vector (‖uₖ‖ ≈ 0). This calculator detects this when ‖uₖ‖ < 10⁻¹⁰ and flags the corresponding vector as linearly dependent. The QR decomposition is not well-defined in this case.
What is the QR decomposition used for?
QR decomposition A = Q·R is fundamental in linear algebra: it solves least-squares problems (Ax = b → Rx = Qᵀb), computes eigenvalues via the QR algorithm, performs singular value decomposition, and provides numerically stable solutions to linear systems. It is preferred over LU decomposition when the matrix is nearly singular.
Does the order of input vectors affect the result?
Yes. Gram-Schmidt is an ordered process: u₁ = v₁ exactly (no projection), and each subsequent uₖ is built relative to all previous ones. A different ordering of the same vectors produces a different orthonormal basis — though both span the same subspace. The QR decomposition depends on the order of columns of A.
You Might Also Like
Explore 360+ Free Calculators
From math and science to finance and everyday life — all free, no account needed.