Gram-Schmidt Calculator

Vectors

First unit vector e1(0.67, 0.67, 0.33)
Second unit vector e2(0.33, -0.67, 0.67)
Length of u13.00
Length of u21.00
How this was calculated
  1. Gram-Schmidt starts with u1 = a1 = (2.00, 2.00, 1.00), whose length is 3.00.
  2. Normalizing gives the first unit vector e1 = (0.67, 0.67, 0.33).
  3. Project a2 onto a1: the projection coefficient is 0.33, so u2 = a2 - 0.33 x a1 = (0.33, -0.67, 0.67), which is orthogonal to u1.
  4. Normalizing u2 (length 1.00) gives e2 = (0.33, -0.67, 0.67); together e1 and e2 form an orthonormal set.

The Gram-Schmidt Calculator applies the Gram-Schmidt process to your vectors and returns an orthonormal set. The process turns independent vectors into an orthonormal set by subtracting projections one vector at a time. As a quick illustration, take a1 = (2, 2, 1): its length is 3, so e1 = (0.67, 0.67, 0.33). The projection coefficient of a2 = (1, 0, 1) onto a1 is 0.33, so u2 = a2 - 0.33 x a1 = (0.33, -0.67, 0.67), which is orthogonal to a1. In the same example u2 comes out with length 1.00, so e2 = (0.33, -0.67, 0.67). A second example, a1 = (1, 1, 0) and a2 = (1, 0, 1), gives e1 = (0.71, 0.71, 0.00) and e2 = (0.41, -0.41, 0.82).

The Gram-Schmidt process is the accepted standard for this kind of calculation because it builds the orthonormal set one vector at a time, subtracting projections so each new vector is orthogonal to the ones before it. That step-by-step structure is what makes the method reliable and easy to check. This page shows the formula, the step-by-step workings, worked examples and sources, so you can follow each projection and normalization yourself rather than trusting a black-box answer. Whether you are checking homework, preparing for an exam or verifying a result by hand, the calculator and the explanations here give you the full picture behind every number.

Worked examples

Clean textbook pair

(2 · 2 · 1 · 1 · 0 · 1)

First unit vector e1(0.67, 0.67, 0.33)
Second unit vector e2(0.33, -0.67, 0.67)
Length of u13.00
Length of u21.00

Axis pair

(1 · 1 · 0 · 1 · 0 · 1)

First unit vector e1(0.71, 0.71, 0.00)
Second unit vector e2(0.41, -0.41, 0.82)
Length of u11.41
Length of u21.22

3-4-5 first vector

(3 · 0 · 4 · 2 · 2 · 0)

First unit vector e1(0.60, 0.00, 0.80)
Second unit vector e2(0.50, 0.78, -0.37)
Length of u15.00
Length of u22.56

Projection is the whole idea

Think of two arrows drawn from the same starting point. The first arrow, a1, sets a direction. The second arrow, a2, usually leans partly along that direction and partly away from it. Subtracting the projection removes exactly the along-a1 part, so whatever is left points at a right angle to a1. That leftover is the orthogonal remainder, and it is the single move a gram schmidt calculator repeats for every new vector you give it.

A concrete case makes this visible. Take a1 = (2, 2, 1). Its length is 3, so e1 = (0.67, 0.67, 0.33). Now bring in a2 = (1, 0, 1). The projection coefficient of a2 onto a1 is 0.33, meaning a2 carries a small amount of a1's direction. Multiply that coefficient by a1 and subtract: u2 = a2 - 0.33 x a1 = (0.33, -0.67, 0.67). Check it against a1 and the dot product vanishes — the remainder is orthogonal to a1. The subtraction did its job: the shared direction is gone, and only the perpendicular part survives.

The geometry explains why this works. The projection of a2 onto a1 is the shadow a2 casts on the line through a1 — the closest point on that line. The gap between a2 and its shadow is the shortest path from a2 to the line, and the shortest path always meets the line at a right angle. So the subtraction does not shrink a2 arbitrarily; it isolates the component that a1 cannot account for. Each later vector gets the same treatment, with projections subtracted against every direction already fixed, one at a time, until nothing remains that points along an earlier vector.

Length then finishes the job. In the same example u2 comes out with length 1.00, so e2 = (0.33, -0.67, 0.67) — already unit length, so no rescaling changes it. A second example shows the same pattern with different numbers: a1 = (1, 1, 0) and a2 = (1, 0, 1) give e1 = (0.71, 0.71, 0.00) and e2 = (0.41, -0.41, 0.82). In both cases the first vector is normalized, the second has its projection removed, and the remainder is normalized. The process turns independent vectors into an orthonormal set by subtracting projections one vector at a time, and every step is the same geometric act: remove the part that leans, keep the part that stands square.

Subtracting the projection removes exactly the part of a2 that points along a1, leaving a remainder orthogonal to a1.

The algorithm step by step

The Gram-Schmidt process turns independent vectors into an orthonormal set by subtracting projections one vector at a time. Each vector is handled in four moves: normalize the previous result, project the new vector onto it, subtract that projection, then normalize what is left. A gram schmidt calculator performs these same four moves in order, so following a worked example by hand shows exactly what the tool is doing at each stage.

Start with a1 = (2, 2, 1). Its length is 3.00, so dividing each component by 3.00 gives e1 = (0.67, 0.67, 0.33). Next take a2 = (1, 0, 1). The projection coefficient of a2 onto a1 is 0.33, so subtract 0.33 times a1 from a2: u2 = a2 - 0.33 x a1 = (0.33, -0.67, 0.67). This result is orthogonal to a1, which is the whole point of the subtraction step. In the same example u2 comes out with length 1.00, so normalizing it changes nothing: e2 = (0.33, -0.67, 0.67). The first vector had length 3.00 and the second intermediate vector had length 1.00, and both ended as unit vectors.

A second example shows the same sequence with different numbers. With a1 = (1, 1, 0) and a2 = (1, 0, 1), the first normalization gives e1 = (0.71, 0.71, 0.00), since the length of a1 is 1.41. Projecting a2 onto that direction, subtracting the projection, and normalizing the remainder produces e2 = (0.41, -0.41, 0.82). Again the intermediate length was 1.41 before normalization, and again the final vector is a unit vector at right angles to the first.

Notice the pattern across both examples. The normalize step divides by the length: 3.00 in the first case, 1.41 in the second, and 5.00 for a third first vector of the same kind. The project step multiplies the earlier unit vector by a coefficient, 0.33 in the first example. The subtract step removes that projection, leaving a vector orthogonal to everything already fixed. The final normalize step rescales the remainder to length 1.00. Repeating these four moves for each new vector builds the full orthonormal set one vector at a time.

  • Normalize: divide a1 = (2, 2, 1) by its length 3.00 to get e1 = (0.67, 0.67, 0.33).
  • Project: the projection coefficient of a2 = (1, 0, 1) onto a1 is 0.33.
  • Subtract: u2 = a2 - 0.33 x a1 = (0.33, -0.67, 0.67), which is orthogonal to a1.
  • Normalize again: u2 has length 1.00, so e2 = (0.33, -0.67, 0.67).
  • Second example: a1 = (1, 1, 0) and a2 = (1, 0, 1) give e1 = (0.71, 0.71, 0.00) and e2 = (0.41, -0.41, 0.82).
StepFirst exampleSecond example
Normalize first vectora1 = (2, 2, 1), length 3.00, e1 = (0.67, 0.67, 0.33)a1 = (1, 1, 0), length 1.41, e1 = (0.71, 0.71, 0.00)
Project and subtractcoefficient 0.33; u2 = (0.33, -0.67, 0.67), orthogonal to a1a2 = (1, 0, 1) projected, subtracted, and normalized
Normalize resultu2 length 1.00, e2 = (0.33, -0.67, 0.67)e2 = (0.41, -0.41, 0.82)
The subtraction step is what guarantees orthogonality: after u2 = a2 - 0.33 x a1, the new vector is orthogonal to a1, and normalizing it to length 1.00 only changes its scale, not its direction.

Why orthonormal sets are useful

An orthonormal set is a collection of unit-length vectors that are all perpendicular to each other. That combination sounds modest, but it makes almost every calculation easier. When a basis is orthonormal, the coordinates of any vector are just dot products: to find how much of a vector v lies along a basis vector e, you compute v · e, and you are done. No system of equations, no matrix inverse. The Gram-Schmidt process turns independent vectors into an orthonormal set by subtracting projections one vector at a time, which is exactly why a gram schmidt calculator is handy for checking your work on longer lists of vectors.

A worked example shows the payoff. Take a1 = (2, 2, 1); its length is 3, so e1 = (0.67, 0.67, 0.33). For a2 = (1, 0, 1), the projection coefficient onto a1 is 0.33, so u2 = a2 - 0.33 x a1 = (0.33, -0.67, 0.67), which is orthogonal to a1. In the same example u2 comes out with length 1.00, so e2 = (0.33, -0.67, 0.67). A second example is even tidier: a1 = (1, 1, 0) and a2 = (1, 0, 1) give e1 = (0.71, 0.71, 0.00) and e2 = (0.41, -0.41, 0.82). Notice that each e vector has length one and the dot product of e1 with e2 is zero, so the coordinates of any vector in that plane can be read off with two dot products.

The same construction underlies QR factorization, one of the standard matrix decompositions. If the columns of a matrix A are independent, Gram-Schmidt produces an orthonormal matrix Q whose columns are the e vectors, and an upper triangular matrix R that records the projection coefficients along the way. Writing A = QR is useful because solving systems with Q is cheap: Q has orthonormal columns, so Q transpose times Q is the identity. That structure also feeds least squares. When a linear system has no exact solution, the best fit is found by projecting the data onto the column space, and an orthonormal basis makes that projection a simple sum of dot-product terms.

Numerical analysts usually prefer the modified Gram-Schmidt order of operations over the textbook version. In the classical order, you compute all projection coefficients against the original vectors and then subtract. In the modified order, you subtract each projection from the working vector as soon as it is computed, before moving to the next basis vector. The two orders are mathematically equivalent, but the modified version loses less precision when vectors are nearly dependent, because it works with the already-updated remainder rather than the original vector. The difference is small on paper and can matter a great deal in floating-point arithmetic.

So orthonormal sets earn their place three times over: they make coordinates trivial to compute, they give a clean QR factorization, and they make least-squares projections stable. Keeping the modified order in mind is the practical habit that separates a textbook answer from one you can trust on a computer.

Quick check: after Gram-Schmidt, every output vector should have length 1, and every pair should have a dot product of 0. If either test fails, a projection step went wrong.

When it breaks

The Gram-Schmidt process assumes something that is easy to take for granted: that each new vector points in a genuinely new direction. When that assumption nearly fails, the arithmetic does not announce the problem. It keeps going and hands you a unit vector that looks perfectly reasonable but is built almost entirely out of rounding error. This is the near-dependent case, and it is the main reason a gram schmidt calculator should warn you rather than quietly return a full orthonormal set.

Picture a2 sitting almost on top of a1, off by only a sliver. Subtracting the projection of a2 onto a1 leaves u2 as that sliver — a very short vector. Its length may be tiny, but its direction is what the next step needs, and that direction is dominated by noise. A one-digit change in the last decimal place of a2 can swing u2 through a wide arc. Normalizing it divides by a near-zero length, which scales the noise up to length 1 and dresses it as a legitimate basis vector. The numbers are finite and the output is well formed, so nothing looks wrong on the page.

Contrast that with a well-behaved case. Take a1 = (2, 2, 1), which has length 3, so e1 = (0.67, 0.67, 0.33). The projection coefficient of a2 = (1, 0, 1) onto a1 is 0.33, giving u2 = a2 - 0.33 x a1 = (0.33, -0.67, 0.67), orthogonal to a1. Here u2 has length 1.00, so e2 = (0.33, -0.67, 0.67). A second example, a1 = (1, 1, 0) and a2 = (1, 0, 1), gives e1 = (0.71, 0.71, 0.00) and e2 = (0.41, -0.41, 0.82). In both, u2 is long enough that its direction is carried by the input data, not by floating-point dust. That is the situation the process is designed for.

The practical rule is to check the length of u2 before dividing by it. If that length is not comfortably above the rounding scale of your inputs, the honest answer is that a2 is effectively parallel to a1 and the set should be treated as dependent. Stop there and report it. Continuing produces an orthonormal set that satisfies the arithmetic but not the geometry, and any later result built on it inherits the error.

A few habits keep this from biting you. Rescale inputs so their entries are of comparable size before starting. Compare the length of each u against the length of the original vector it came from, not against an absolute threshold. And when a length is small, say so explicitly instead of normalizing — a stopped computation with a clear message is more useful than a smooth-looking answer you cannot trust.

If u2 is tiny, its direction is noise. Stop and report near-dependence instead of normalizing rounding error into a unit vector.

FAQs

What does Gram-Schmidt do?

Gram-Schmidt converts a set of independent vectors into an orthonormal set that spans the same space. It works by repeatedly subtracting projections and then normalizing. Each new vector has its components along earlier vectors removed, so what remains is orthogonal to them, and normalizing makes each vector unit length.

What is the projection coefficient?

The projection coefficient measures the amount of a1 inside a2: (a2 . a1) / (a1 . a1). Subtracting that multiple of a1 from a2 leaves a vector orthogonal to a1. This single subtraction is the core step that removes overlap between vectors before you normalize.

Why normalize at the end of each step?

Orthogonal alone is not orthonormal. Dividing each vector by its length makes it a unit vector, which is what orthonormal requires. Normalizing at the end of each step also simplifies every later projection, because the projection coefficient then reduces to a simple dot product with a unit vector.

What if my vectors are linearly dependent?

The subtraction leaves a zero (or near-zero) vector, which cannot be normalized. That is the process telling you the set was dependent. In that case the vector adds no new direction, so you drop it, and the resulting orthonormal set spans the same space as the independent vectors you started with.

How is Gram-Schmidt related to QR factorization?

Collecting the e vectors as columns of Q and the projection coefficients into an upper-triangular R gives A = QR. That is the factorization behind least-squares solvers. Gram-Schmidt is essentially the step-by-step construction of Q, with R recording the coefficients used at each subtraction.

Does the order of vectors matter?

Yes. The first vector fixes e1's direction entirely, and different orders give different orthonormal bases for the same span. The span is unchanged, but the individual unit vectors depend on which vector you process first, so order affects the output even when the input set is identical.

Sources

Related calculators

Vector Projection Calculator
The shadow one vector casts on another: the vector projection and scalar projection of a onto b, with the dot product and magnitudes shown.
Unit Vector Calculator
Normalize any 3D vector to length 1: magnitude first, then each component divided by it — direction kept, size removed.
Vector Dot Product Calculator
The dot product of two 3D vectors, their magnitudes and the angle between them — and what the sign of the result tells you.