help-calc

08 Numbers and Units

Gram Schmidt Calculator: Steps & Examples

Card 08-0189 · Updated · Standard formula, shown below

The calculator on this page is switched off while it is checked. The formula is below, and the worked example shows how to do the sum by hand.

This Gram-Schmidt calculator takes a set of linearly independent vectors and produces an orthonormal basis for the same vector space. You enter the vectors as rows or columns, choose the inner product (standard dot product), and the calculator returns the orthogonal and orthonormal vectors step by step. It also shows the intermediate projections, so you can verify each stage of the process.

What Is the Gram-Schmidt Process?

The Gram-Schmidt process is an algorithm for converting a set of linearly independent vectors into a set of orthogonal (perpendicular) vectors that span the same subspace. If you then divide each orthogonal vector by its length, you get an orthonormal basis—vectors that are mutually perpendicular and each of unit length. This is fundamental in linear algebra because orthonormal bases make many computations (like projections, least-squares fitting, and QR decomposition) much simpler and numerically stable.

The process works iteratively: start with the first vector, then for each subsequent vector, subtract off its projection onto all previously processed vectors. The result is a new vector that is orthogonal to all earlier ones. After processing all vectors, you have an orthogonal set. Normalizing each gives the orthonormal basis.

How the Calculator Works

The calculator implements the classical Gram-Schmidt algorithm. You provide m vectors in n-dimensional space (with m ≤ n). It checks that the vectors are linearly independent (if not, it warns you). Then it computes:

  • Orthogonalization: For each vector vk, compute the projection onto each previous orthogonal vector ui and subtract: uk = vk − Σi=1..k-1 projui(vk).
  • Normalization: Divide each uk by its Euclidean norm (length) to get ek = uk / ||uk||.

The calculator shows each intermediate vector and the final orthonormal basis. It also computes the dot products between the resulting vectors to confirm orthogonality (they should be 0).

Formula and Step-by-Step Example

Given a set of vectors {v1, v2, …, vm} in Rn, the algorithm is:

  1. Step 1: Set u1 = v1.
  2. Step 2: For k = 2 to m: compute uk = vk − Σi=1..k-1 ( (vk·ui) / (ui·ui) ) ui.
  3. Normalize: ek = uk / ||uk|| for all k.

Worked example with the default vectors: v1 = (1,0,1), v2 = (0,1,1), v3 = (1,1,0).

  • u1 = (1,0,1). ||u1|| = √(1²+0²+1²) = √2 ≈ 1.4142, so e1 = (0.7071, 0, 0.7071).
  • Projection of v2 onto u1: (v2·u1) / (u1·u1) = (0+0+1)/2 = 0.5. So u2 = (0,1,1) − 0.5*(1,0,1) = (−0.5, 1, 0.5). ||u2|| = √(0.25+1+0.25) = √1.5 ≈ 1.2247, so e2 = (−0.4082, 0.8165, 0.4082).
  • Projection of v3 onto u1: (1+0+0)/2 = 0.5. Projection onto u2: (v3·u2) / (u2·u2) = (−0.5+1+0)/1.5 = 0.5/1.5 ≈ 0.3333. So u3 = (1,1,0) − 0.5*(1,0,1) − 0.3333*(−0.5,1,0.5) = (1−0.5+0.1667, 1−0−0.3333, 0−0.5−0.1667) = (0.6667, 0.6667, −0.6667). ||u3|| = √(0.4444+0.4444+0.4444) = √1.3332 ≈ 1.1547, so e3 = (0.5774, 0.5774, −0.5774).

The calculator output matches these values: e1 = (0.7071, 0, 0.7071), e2 = (−0.4082, 0.8165, 0.4082), e3 = (0.5774, 0.5774, −0.5774).

Why Use an Orthonormal Basis?

Orthonormal bases are the “nice” bases in linear algebra. They preserve lengths and angles, making coordinate transformations and projections straightforward. For example, in QR decomposition, a matrix is factored into an orthogonal matrix Q and an upper triangular matrix R—this is used in many numerical algorithms, including solving least-squares problems. In signal processing, orthonormal bases (like Fourier or wavelet bases) allow efficient decomposition of signals. In machine learning, Gram-Schmidt can be used to create orthogonal features to reduce redundancy.

Common Mistakes and How to Avoid Them

  • Using non-independent vectors: The process fails (produces a zero vector) if the input set is linearly dependent. The calculator checks this and warns you.
  • Mixing up row and column vectors: The algorithm works the same for both, but be consistent. The calculator treats each input as a vector.
  • Rounding too early: If you round intermediate projections, errors accumulate. Use full precision during computation and round only the final output.
  • Forgetting to normalize: The orthogonal vectors are not unit length; you must divide by the norm to get the orthonormal basis.

Numerical Stability and Alternatives

The classical Gram-Schmidt algorithm is mathematically elegant but can be numerically unstable for large sets of vectors—round-off errors can cause loss of orthogonality. The modified Gram-Schmidt process is more stable because it subtracts projections one at a time, re-orthogonalizing each new vector against the updated previous ones. In practice, for large matrices, most software uses Householder reflections or Givens rotations to compute QR decompositions because they are even more stable. However, for small to medium-sized problems (like those you’d solve by hand or with this calculator), classical Gram-Schmidt is perfectly fine.

How to Use This Calculator Effectively

Enter your vectors as comma-separated numbers (e.g., “1, 2, 3”). The number of dimensions (n) must match the length of each vector. The number of vectors (m) must be ≤ n. The calculator will:

  • Verify that all vectors have the same length and that m ≤ n.
  • Check linear independence (by computing the rank).
  • Compute the orthogonal vectors uk and the orthonormal vectors ek.
  • Display the dot products between the orthonormal vectors to confirm orthogonality.

If you need to compute the QR decomposition of a matrix, you can use the orthonormal vectors as Q and then compute R = QTA manually or with another tool.

Frequently Asked Questions

What does Gram-Schmidt do in simple terms?

It takes a set of independent vectors and “straightens” them so they are all perpendicular (orthogonal) and of length 1 (normalized). Imagine taking three non-perpendicular sticks and rotating them to be at right angles without changing the space they span.

Can I use Gram-Schmidt on any set of vectors?

No, the vectors must be linearly independent. If they are dependent, the process will produce a zero vector at some step, and you cannot get an orthonormal basis. The calculator checks this and warns you.

What is the difference between orthogonal and orthonormal?

Orthogonal means the vectors are perpendicular (dot product = 0). Orthonormal means they are orthogonal AND each has length 1. Gram-Schmidt first produces orthogonal vectors, then normalizes them to get orthonormal.

Why is Gram-Schmidt important in real life?

It is used in many numerical algorithms, such as QR decomposition, which is essential for solving linear systems, least-squares problems, and eigenvalue computations. It also appears in signal processing and machine learning for feature orthogonalization.

Does the order of the vectors matter?

Yes, the order affects the resulting orthonormal basis, but not the subspace they span. Different orders give different bases, all valid. The calculator processes them in the order you enter.

What if my vectors have more than 6 dimensions?

This calculator supports up to 6 dimensions for simplicity. For higher dimensions, you can use a computer algebra system like MATLAB, NumPy, or Wolfram Alpha, which implement the same algorithm.

Related

Formula used
in dim | Number of dimensions (n) | - | 3 | 2 | 6
in count | Number of vectors (m) | - | 3 | 1 | 6
in v1 | Vector 1 (comma-separated) | - | 1, 0, 1 | - | -
in v2 | Vector 2 (comma-separated) | - | 0, 1, 1 | - | -
in v3 | Vector 3 (comma-separated) | - | 1, 1, 0 | - | -
out ortho | Orthogonal vectors | - | "see steps" | 0 | 0
out norm | Orthonormal vectors | - | "see steps" | 0 | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More on this shelf

The whole Numbers and Units shelf →