Gram-Schmidt Orthogonalization Calculator
Apply the Gram-Schmidt process to transform a linearly independent set of vectors into an orthogonal set spanning the same subspace. The process uses projections to remove components along previously constructed vectors and can also be used to obtain an orthonormal basis through normalization.
A
Learn About Gram-Schmidt Orthogonalization
In inner product spaces, orthogonal and orthonormal bases are mathematically ideal because coordinates can be calculated via simple dot products without matrix inversion, and numerical algorithms avoid error amplification.
The Gram-Schmidt process is an algorithm that takes a linearly independent set of vectors $\{\mathbf{v}_1, \mathbf{v}_2, \dots, \mathbf{v}_k\} \subset \mathbb{R}^m$ and generates:
- An orthogonal basis $\{\mathbf{u}_1, \mathbf{u}_2, \dots, \mathbf{u}_k\}$ satisfying $\mathbf{u}_i \cdot \mathbf{u}_j = 0$ for all $i \ne j$.
- An orthonormal basis $\{\mathbf{e}_1, \mathbf{e}_2, \dots, \mathbf{e}_k\}$ of unit vectors satisfying $\|\mathbf{e}_i\| = 1$ and $\mathbf{e}_i \cdot \mathbf{e}_j = \delta_{ij}$.
Both sets span the exact same subspace as the original vectors:
Mathematical Formulation and Projection Subtraction
The algorithm proceeds sequentially, setting the first vector directly and subtracting perpendicular vector projections from subsequent vectors:
- First Vector:
- Orthogonal Projection Operator:
The projection of vector $\mathbf{v}$ onto an orthogonal vector $\mathbf{u}$ is:
- Subsequent Vectors ($k \ge 2$):
- Normalization to Orthonormal Basis:
Linearly Dependent Input Behavior
The Gram-Schmidt algorithm requires the input vectors to be linearly independent. If a vector $\mathbf{v}_k$ is linearly dependent on preceding vectors, its projection onto their span completely cancels it out, producing the zero vector ($\mathbf{u}_k = \mathbf{0}$). Because the zero vector has magnitude zero ($\|\mathbf{u}_k\| = 0$), normalization ($\frac{\mathbf{u}_k}{\|\mathbf{u}_k\|}$) is undefined.
Worked Numerical Example
Orthogonalize the following vectors in $\mathbb{R}^3$:
- Step 1: First Orthogonal Vector:
- Step 2: Projection and Subtraction:
- Verify Orthogonality:
- Normalize to Orthonormal Basis:
What is the difference between an orthogonal basis and an orthonormal basis?
An orthogonal basis consists of vectors that are mutually perpendicular ($\mathbf{u}_i \cdot \mathbf{u}_j = 0$ for $i \ne j$), but may have arbitrary non-zero lengths. An orthonormal basis is an orthogonal basis where every vector has been normalized to unit length ($\|\mathbf{e}_i\| = 1$).
How does the Gram-Schmidt process relate to QR decomposition?
The Gram-Schmidt process directly computes the QR decomposition $\mathbf{A} = \mathbf{Q}\mathbf{R}$. The columns of matrix $\mathbf{Q}$ are the orthonormal vectors $\mathbf{e}_1, \dots, \mathbf{e}_k$, and $\mathbf{R}$ is the upper-triangular matrix containing the projection lengths and normalization factors ($r_{jj} = \|\mathbf{u}_j\|$ and $r_{ij} = \mathbf{v}_j \cdot \mathbf{e}_i$ for $i < j$).
Why does Classical Gram-Schmidt suffer from numerical instability?
In floating-point arithmetic, roundoff errors cause the computed vectors $\mathbf{u}_k$ to gradually lose orthogonality when vectors are subtracted in sequence. Numerical software often implements Modified Gram-Schmidt (MGS) or Householder reflections, where vectors are projected against newly updated orthogonal directions rather than original vectors, dramatically improving numerical stability.
Does changing the order of input vectors change the resulting basis?
Yes. The first vector $\mathbf{u}_1$ always points in the exact direction of $\mathbf{v}_1$. Reordering the input vectors changes which direction is preserved first, producing a different set of orthogonal basis vectors, although both sets span the exact same total subspace.
- Jørgen Gram and Erhard Schmidt: Danish mathematician Jørgen Pedersen Gram introduced the method in 1883 in the context of least-squares approximations, and German mathematician Erhard Schmidt formalized it for general function spaces and integral equations in 1907. It was also noted earlier by Laplace in 1820.
- Orthogonal Polynomials: When applied to the polynomial vector space $\mathcal{P}[-1, 1]$ equipped with the function inner product $\langle f, g \rangle = \int_{-1}^1 f(x)g(x)\,dx$, the Gram-Schmidt process applied to the monomial basis $\{1, x, x^2, x^3, \dots\}$ generates the classical Legendre polynomials.