Gram-Schmidt Orthogonalization: A Step-by-Step Guide
In the world of linear algebra, vectors and vector spaces are fundamental building blocks. To describe any vector in a space, we use a 'basis'—a set of vectors that can be combined to create any other vector in that space. While any basis will do, some are far more useful than others. The 'gold standard' is an orthonormal basis, where every vector is at a right angle (orthogonal) to every other, and each vector has a length of one (normalized). But what if you're given a basis that's skewed and messy? This is where the Gram-Schmidt procedure comes in. It's a powerful and systematic algorithm for turning any basis into a much cleaner and more useful orthogonal one.
What is the Gram-Schmidt Procedure?
The Gram-Schmidt orthogonalization procedure is an algorithm that takes a finite, linearly independent set of vectors and transforms it into an orthogonal set (or an orthonormal set) that spans the same subspace. In simpler terms, it's a method for 'straightening out' a basis so that all its vectors are mutually perpendicular.
An Analogy: The Shadow Removers
Imagine you have a set of sticks (your vectors) planted in the ground, leaning at various angles. You want to create a new set of sticks in the same general area, but with each one perpendicular to the others.
- Keep the first stick: You take your first stick just as it is. This is your reference point.
- Adjust the second stick: You look at the second stick. It casts a 'shadow' along the direction of the first stick. You essentially 'break off' this shadow component from the second stick. What's left is a new stick that is perfectly perpendicular to the first one.
- Adjust the third stick: Now, you take the third stick. It casts shadows onto both of the first two (now perpendicular) sticks. You break off both of these shadow components. What's left is perpendicular to both of the previous sticks.
The Gram-Schmidt process does exactly this, but with mathematical precision using vector projections.
Why is an Orthogonal Basis Required?
Working with an orthogonal basis simplifies calculations dramatically. It turns complex problems into much more manageable ones.
- Easy Projections and Coordinates: Finding the coordinates of a vector in a non-orthogonal basis requires solving a system of linear equations. In an orthogonal basis, it's just a series of simple dot products. This is computationally much faster and more efficient.
- Numerical Stability: In computer calculations, rounding errors can accumulate and lead to inaccurate results. Orthonormal matrices (formed from orthonormal basis vectors) have special properties that make them numerically stable, minimizing the propagation of errors.
- Fundamental to Other Algorithms: The Gram-Schmidt process is the cornerstone of many important methods in numerical linear algebra, such as the QR decomposition, which is used for solving linear systems and eigenvalue problems.
- Function Approximation: The concept extends beyond simple geometric vectors. In signal processing and physics, functions can be treated as vectors. Gram-Schmidt is used to create orthogonal sets of functions (like Legendre polynomials or Fourier series) for approximating more complex functions.
The Step-by-Step Procedure
Let's start with a basis of linearly independent vectors: $$ \{ v_1, v_2, \dots, v_k \} $$. Our goal is to produce an orthogonal basis $$ \{ u_1, u_2, \dots, u_k \} $$.
The key operation is the projection of one vector onto another. The projection of vector $$v$$ onto vector $$u$$ is given by:
$$ \text{proj}_{u}(v) = \frac{v \cdot u}{u \cdot u} u $$
This formula calculates the 'shadow' of $$v$$ that lies in the direction of $$u$$.
The Algorithm
- Step 1: The First Orthogonal Vector
The first vector of our new basis, $$u_1$$, is simply the first vector from our original basis.
$$ u_1 = v_1 $$ - Step 2: The Second Orthogonal Vector
To get $$u_2$$, we take $$v_2$$ and subtract its projection onto $$u_1$$.
$$ u_2 = v_2 - \text{proj}_{u_1}(v_2) = v_2 - \frac{v_2 \cdot u_1}{u_1 \cdot u_1} u_1 $$ - Step 3: The Third Orthogonal Vector
To get $$u_3$$, we take $$v_3$$ and subtract its projections onto all previously found orthogonal vectors, $$u_1$$ and $$u_2$$.
$$ u_3 = v_3 - \text{proj}_{u_1}(v_3) - \text{proj}_{u_2}(v_3) = v_3 - \frac{v_3 \cdot u_1}{u_1 \cdot u_1} u_1 - \frac{v_3 \cdot u_2}{u_2 \cdot u_2} u_2 $$ - Step k: The General Step
The pattern continues. For the k-th vector, we take $$v_k$$ and subtract its projections onto all preceding orthogonal vectors $$u_1, u_2, \dots, u_{k-1}$$.
$$ u_k = v_k - \sum_{j=1}^{k-1} \text{proj}_{u_j}(v_k) = v_k - \sum_{j=1}^{k-1} \frac{v_k \cdot u_j}{u_j \cdot u_j} u_j $$ - Optional Final Step: Normalization
The set $$ \{ u_1, u_2, \dots, u_k \} $$ is now an orthogonal basis. To make it an orthonormal basis, we divide each vector by its magnitude (norm), $$ \|u_i\| = \sqrt{u_i \cdot u_i} $$.
$$ e_i = \frac{u_i}{\|u_i\|} $$
The resulting set $$ \{ e_1, e_2, \dots, e_k \} $$ is orthonormal.
Worked Examples
Example 1: Vectors in R²
Let's find an orthogonal basis for the space spanned by $$ v_1 = (3, 1) $$ and $$ v_2 = (2, 2) $$.
Step 1: $$ u_1 = v_1 = (3, 1) $$
Step 2: Calculate $$ u_2 $$. We need the dot products: $$ v_2 \cdot u_1 = (2)(3) + (2)(1) = 8 $$ and $$ u_1 \cdot u_1 = (3)(3) + (1)(1) = 10 $$.
$$ u_2 = v_2 - \frac{v_2 \cdot u_1}{u_1 \cdot u_1} u_1 = (2, 2) - \frac{8}{10}(3, 1) = (2, 2) - (\frac{12}{5}, \frac{4}{5}) = (\frac{10}{5} - \frac{12}{5}, \frac{10}{5} - \frac{4}{5}) = (-\frac{2}{5}, \frac{6}{5}) $$
Our orthogonal basis is $$ \{ (3, 1), (-\frac{2}{5}, \frac{6}{5}) \} $$. We can check their dot product: $$ (3)(-\frac{2}{5}) + (1)(\frac{6}{5}) = -\frac{6}{5} + \frac{6}{5} = 0 $$. They are indeed orthogonal!
Example 2: Vectors in R³
Given $$ v_1 = (1, 1, 1) $$, $$ v_2 = (0, 1, 1) $$, and $$ v_3 = (0, 0, 1) $$.
Step 1: $$ u_1 = v_1 = (1, 1, 1) $$
Step 2: Find $$ u_2 $$. $$ v_2 \cdot u_1 = 2 $$ and $$ u_1 \cdot u_1 = 3 $$.
$$ u_2 = (0, 1, 1) - \frac{2}{3}(1, 1, 1) = (-\frac{2}{3}, \frac{1}{3}, \frac{1}{3}) $$
Step 3: Find $$ u_3 $$. We need more dot products: $$ v_3 \cdot u_1 = 1 $$ and $$ v_3 \cdot u_2 = (0)(-\frac{2}{3}) + (0)(\frac{1}{3}) + (1)(\frac{1}{3}) = \frac{1}{3} $$. Also, $$ u_2 \cdot u_2 = (-\frac{2}{3})^2 + (\frac{1}{3})^2 + (\frac{1}{3})^2 = \frac{4}{9} + \frac{1}{9} + \frac{1}{9} = \frac{6}{9} = \frac{2}{3} $$.
$$ u_3 = v_3 - \frac{v_3 \cdot u_1}{u_1 \cdot u_1} u_1 - \frac{v_3 \cdot u_2}{u_2 \cdot u_2} u_2 = (0, 0, 1) - \frac{1}{3}(1, 1, 1) - \frac{1/3}{2/3}(-\frac{2}{3}, \frac{1}{3}, \frac{1}{3}) $$
$$ u_3 = (0, 0, 1) - (\frac{1}{3}, \frac{1}{3}, \frac{1}{3}) - \frac{1}{2}(-\frac{2}{3}, \frac{1}{3}, \frac{1}{3}) = (0, 0, 1) - (\frac{1}{3}, \frac{1}{3}, \frac{1}{3}) - (-\frac{1}{3}, \frac{1}{6}, \frac{1}{6}) = (0, -\frac{1}{2}, \frac{1}{2}) $$
The orthogonal basis is $$ \{ (1, 1, 1), (-\frac{2}{3}, \frac{1}{3}, \frac{1}{3}), (0, -\frac{1}{2}, \frac{1}{2}) \} $$.
Example 3: A Second R³ Example
Let $$ v_1 = (1, 0, 1) $$, $$ v_2 = (1, 1, 0) $$, and $$ v_3 = (0, 1, 1) $$.
Step 1: $$ u_1 = (1, 0, 1) $$
Step 2: $$ u_2 = (1, 1, 0) - \frac{1}{2}(1, 0, 1) = (\frac{1}{2}, 1, -\frac{1}{2}) $$
Step 3: $$ u_3 = (0, 1, 1) - \frac{1}{2}(1, 0, 1) - \frac{1/2}{3/2}(\frac{1}{2}, 1, -\frac{1}{2}) = (0, 1, 1) - (\frac{1}{2}, 0, \frac{1}{2}) - (\frac{1}{6}, \frac{1}{3}, -\frac{1}{6}) = (-\frac{2}{3}, \frac{2}{3}, \frac{2}{3}) $$
The orthogonal basis is $$ \{ (1, 0, 1), (\frac{1}{2}, 1, -\frac{1}{2}), (-\frac{2}{3}, \frac{2}{3}, \frac{2}{3}) \} $$.
Example 4: Vectors in R⁴
Given $$ v_1 = (0, 1, 2, 1) $$ and $$ v_2 = (0, 1, 3, 2) $$.
Step 1: $$ u_1 = (0, 1, 2, 1) $$
Step 2: Find $$ u_2 $$. $$ v_2 \cdot u_1 = (0)(0) + (1)(1) + (3)(2) + (2)(1) = 9 $$. $$ u_1 \cdot u_1 = 0^2 + 1^2 + 2^2 + 1^2 = 6 $$.
$$ u_2 = (0, 1, 3, 2) - \frac{9}{6}(0, 1, 2, 1) = (0, 1, 3, 2) - (0, \frac{3}{2}, 3, \frac{3}{2}) = (0, -\frac{1}{2}, 0, \frac{1}{2}) $$
The orthogonal set is $$ \{ (0, 1, 2, 1), (0, -\frac{1}{2}, 0, \frac{1}{2}) \} $$.
Example 5: Function Spaces (Polynomials)
The Gram-Schmidt process isn't limited to vectors in Rⁿ. It can be applied to any inner product space, like spaces of functions. Let's find an orthogonal basis for polynomials up to degree 2 on the interval $$[-1, 1]$$. Our starting basis is $$ \{ v_1, v_2, v_3 \} = \{ 1, x, x^2 \} $$. The inner product (analogous to a dot product) is defined as $$ \langle f, g \rangle = \int_{-1}^{1} f(x)g(x) dx $$.
Step 1: $$ u_1(x) = v_1(x) = 1 $$
Step 2: Find $$ u_2(x) $$. We need $$ \langle v_2, u_1 \rangle = \int_{-1}^{1} x \cdot 1 dx = [\frac{x^2}{2}]_{-1}^{1} = 0 $$. Since the inner product is zero, the vectors are already orthogonal!
$$ u_2(x) = v_2(x) - 0 = x $$
Step 3: Find $$ u_3(x) $$. We need $$ \langle v_3, u_1 \rangle = \int_{-1}^{1} x^2 \cdot 1 dx = [\frac{x^3}{3}]_{-1}^{1} = \frac{2}{3} $$ and $$ \langle u_1, u_1 \rangle = \int_{-1}^{1} 1 \cdot 1 dx = [x]_{-1}^{1} = 2 $$. We also need $$ \langle v_3, u_2 \rangle = \int_{-1}^{1} x^2 \cdot x dx = \int_{-1}^{1} x^3 dx = 0 $$.
$$ u_3(x) = v_3 - \frac{\langle v_3, u_1 \rangle}{\langle u_1, u_1 \rangle} u_1 - \frac{\langle v_3, u_2 \rangle}{\langle u_2, u_2 \rangle} u_2 = x^2 - \frac{2/3}{2} (1) - 0 = x^2 - \frac{1}{3} $$
The orthogonal basis is $$ \{ 1, x, x^2 - \frac{1}{3} \} $$. These are the first three Legendre Polynomials (up to a scalar multiple), which are immensely important in physics and engineering.
Conclusion
The Gram-Schmidt orthogonalization procedure might seem intimidating at first, but it is a highly logical and systematic process. By iteratively removing the 'shadows' of vectors on the previously constructed orthogonal set, it transforms any set of linearly independent vectors into a far more useful orthogonal basis. This ability to 'straighten out' a vector space is a cornerstone of linear algebra, unlocking simpler calculations, more stable numerical methods, and deeper insights into the structure of spaces, whether they are made of geometric vectors or abstract functions.
Take a Quiz Based on This Article
Test your understanding with AI-generated questions tailored to this content