Gram-Schmidt Calculator

Enter two or three vectors to compute an orthogonal basis (u1, u2, u3) and an orthonormal basis (e1, e2, e3) using the Gram-Schmidt process.

Quick Facts

Projection formula
proj_u(v) = (v·u / u·u) u
The component of v pointing in the direction of u.
Orthogonal basis
u_k = v_k − Σ proj_uj(v_k)
Subtract every earlier projection to remove shared direction.
Orthonormal basis
e_k = u_k / ‖u_k‖
Scale each orthogonal vector to unit length.

Your Results

Calculated
Orthogonal vector u1
-
u1 = v1
Orthogonal vector u2
-
u2 = v2 − proj_u1(v2)
Orthogonal vector u3
-
u3 = v3 − proj_u1(v3) − proj_u2(v3)
Orthonormal basis
-
e_k = u_k / ‖u_k‖

Ready

Enter linearly independent vectors, then press Calculate.

How the Gram-Schmidt Process Works

The Gram-Schmidt process takes a set of linearly independent vectors, v1, v2, v3, and builds a new set of mutually perpendicular (orthogonal) vectors, u1, u2, u3, that span the exact same subspace. Each step removes the part of a vector that already points in the direction of the vectors found so far, leaving only the genuinely new direction. Dividing each orthogonal vector by its own length then produces an orthonormal basis, e1, e2, e3, where every vector has length 1 as well as being mutually perpendicular.

Formula and method

The building block is the vector projection of v onto u: proj_u(v) = (v·u / u·u) u, which is the component of v that lies along u. Gram-Schmidt applies this repeatedly: u1 = v1 (the first vector is kept as-is); u2 = v2 − proj_u1(v2) (subtract the part of v2 already covered by u1); u3 = v3 − proj_u1(v3) − proj_u2(v3) (subtract the parts covered by both u1 and u2). Each u_k is guaranteed to be orthogonal to every u_j computed before it, because the projection removes exactly the component shared with that direction. Normalizing gives e_k = u_k / ‖u_k‖, where ‖u_k‖ = √(u_k·u_k) is the Euclidean norm.

Common sources of error

  • Dimension mismatch: every input vector must have the same number of components (all in R², all in R³, and so on) — mixing lengths makes the dot products undefined.
  • Linearly dependent inputs: if a vector lies in the span of the earlier ones, its projections cancel it out entirely, leaving a zero vector — Gram-Schmidt cannot orthogonalize a dependent set.
  • Rounding intermediate steps: truncating u1 or u2 before computing the next projection compounds error into u3 and the final orthonormal basis — carry full precision through each step.

Checking your result

Verify orthogonality by checking that the dot product of any two output vectors is zero (or extremely close to it, allowing for floating-point rounding): u1·u2 ≈ 0, u1·u3 ≈ 0, and u2·u3 ≈ 0. Verify the orthonormal vectors by confirming each has length 1: e_k·e_k ≈ 1. Also confirm the span is preserved — v1, v2, and v3 should each be expressible as a linear combination of u1, u2, and u3.

Applications

Gram-Schmidt orthogonalization underlies the QR decomposition used to solve least-squares problems and linear systems numerically. Orthonormal bases simplify projections in computer graphics (camera and lighting frames), signal processing (orthogonal basis functions), and quantum mechanics (orthonormal state vectors), because coordinates in an orthonormal basis can be computed with simple dot products instead of solving a linear system.

Frequently Asked Questions

What is the Gram-Schmidt process?
The Gram-Schmidt process converts a set of linearly independent vectors into an orthogonal (or orthonormal) set that spans the same subspace. Each new vector is formed by subtracting its projections onto all previously computed orthogonal vectors, so u_k = v_k − Σ proj_uj(v_k) for j from 1 to k−1.
What is the difference between the orthogonal basis and the orthonormal basis it produces?
The orthogonal basis vectors u1, u2, u3 are mutually perpendicular (each dot product is zero) but generally have different lengths. Dividing each u_k by its own norm, e_k = u_k / ‖u_k‖, produces the orthonormal basis, where every vector also has unit length.
What happens if the input vectors are linearly dependent?
If a vector lies in the span of the earlier vectors, subtracting its projections leaves a zero (or near-zero) vector, since there is no independent direction left to orthogonalize. Gram-Schmidt requires linearly independent input vectors; a zero result signals dependence.
Does the order of the input vectors matter?
Yes. Gram-Schmidt processes vectors in the order given, and each step depends on all previous ones, so entering v1, v2, v3 in a different order generally produces a different (though still valid) orthogonal basis for the same span.