Gram-Schmidt Orthogonalization Calculator
Orthogonalize two 2D vectors using the Gram-Schmidt process.
Find the orthogonal pair and the orthonormal basis, with verification of perpendicularity.
The Gram-Schmidt process converts any set of linearly independent vectors into a set of mutually perpendicular (orthogonal) vectors that span the same space. An orthonormal basis is one that is both orthogonal and made of unit-length vectors, and those are fundamental to linear algebra, numerical methods, and quantum mechanics.
The process for two vectors u1 and u2:
Step 1: v1 = u1 (keep the first vector)
Step 2: v2 = u2 - (u2 · v1 / |v1|²) v1
The second term is the projection of u2 onto v1. Subtracting it removes the component of u2 that lies along v1, leaving only the perpendicular component.
Verify orthogonality: v1 · v2 = 0 (the dot product should be zero, or near zero accounting for floating-point rounding).
Normalize to get the orthonormal basis:
e1 = v1 / |v1| e2 = v2 / |v2|
Why it matters. QR decomposition in numerical linear algebra uses Gram-Schmidt, or a numerically stable variant of it. Orthonormal bases simplify projections dramatically, because the projection of any vector onto an orthonormal basis vector is just their dot product, with no division by a squared length. In quantum mechanics, states are vectors in a Hilbert space and the basis states must be orthonormal.
Where it goes wrong. Classic Gram-Schmidt loses accuracy when the input vectors are nearly parallel, and the reason is visible in the formula. If u2 points almost the same way as u1, then subtracting the projection leaves a v2 that is tiny compared with either input, and it was produced by subtracting two nearly equal numbers. That is the classic recipe for catastrophic cancellation: most of the significant digits agree and cancel, leaving the result to be determined by the few that did not. For many vectors the errors compound, and serious software uses modified Gram-Schmidt or Householder reflections instead. The calculator prints what fraction of u2’s length survived, which is a direct readout of how much cancellation happened. Anything under a few percent means the answer’s last digits should not be trusted.
This page handles the two-vector case in two dimensions, which is where the geometry is easy to see. The process itself extends to any number of vectors in any number of dimensions: each new vector has its projection onto every previous result subtracted in turn.
How we build and check this calculator
This calculator runs entirely in your browser, so the numbers you enter stay on your device. The math behind it is written by hand and tested against worked examples and standard references before the page goes live.
SuperGlobalCalculator is independently built and maintained. See how we build and verify our calculators.