Gram-Schmidt Calculator

Orthogonalize a set of vectors using the Gram-Schmidt process with detailed projection calculations.

Enter Vectors

Result

Orthogonal Vectors
--

Step-by-Step Solution

u_k = v_k - sum(proj(u_j, v_k))

Understanding the Gram-Schmidt Process

The Gram-Schmidt process is a method for orthogonalizing a set of vectors in an inner product space, most commonly the Euclidean space Rn. Given a set of linearly independent vectors, the process produces an orthogonal (or orthonormal) set of vectors that spans the same subspace as the original set.

This is one of the most important algorithms in linear algebra and has applications in numerical analysis, computer graphics, signal processing, and quantum mechanics.

The Algorithm

Step 1: First Vector

The first orthogonal vector is simply the first input vector.

u_1 = v_1

Step 2: Projection

Compute the projection of each subsequent vector onto all previously computed orthogonal vectors.

proj(u, v) = (v . u / u . u) * u

Step 3: Subtract Projections

Subtract all projections from the current vector to obtain the next orthogonal vector.

u_k = v_k - sum of proj(u_j, v_k)

Step 4: Normalize (Optional)

For an orthonormal set, divide each vector by its magnitude.

e_k = u_k / ||u_k||

Key Concepts

Orthogonal vs Orthonormal

Orthogonal vectors are mutually perpendicular (their dot product is zero). Orthonormal vectors are orthogonal AND have unit length (magnitude = 1). The Gram-Schmidt process first produces orthogonal vectors, which can then be normalized to become orthonormal.

Linear Independence Requirement

The input vectors must be linearly independent for the algorithm to work. If any vector in the set can be written as a linear combination of the others, the process will produce a zero vector, indicating linear dependence.

Applications

  • QR decomposition of matrices, used extensively in numerical linear algebra
  • Finding orthonormal bases for subspaces in functional analysis
  • Signal processing for constructing orthogonal signal sets
  • Computer graphics for camera orientation and coordinate frame construction
  • Least squares fitting and regression analysis
  • Quantum mechanics for constructing orthonormal state bases

Numerical Stability

The classical Gram-Schmidt process can suffer from numerical instability due to floating-point arithmetic. The modified Gram-Schmidt algorithm addresses this by recomputing projections using the partially orthogonalized vectors, yielding better numerical results in practice.

Worked Example

Consider orthogonalizing v_1 = (1, 1, 0) and v_2 = (1, 0, 1):

  1. Set u_1 = v_1 = (1, 1, 0)
  2. Compute proj(u_1, v_2) = (v_2 . u_1 / u_1 . u_1) * u_1 = (1/2)(1, 1, 0) = (0.5, 0.5, 0)
  3. u_2 = v_2 - proj(u_1, v_2) = (1, 0, 1) - (0.5, 0.5, 0) = (0.5, -0.5, 1)
  4. Verify: u_1 . u_2 = 0.5 - 0.5 + 0 = 0 (orthogonal)