Gram Schmidt Calculator - Orthogonal and Orthonormal Basis

Use this Gram Schmidt calculator to orthogonalize 2D and 3D vectors and read off the orthonormal basis e1, e2, e3 with each intermediate norm.

Updated: June 16, 2026 • Free Tool

Gram Schmidt Calculator

Enter 2 or 3 vectors in 2D or 3D. One vector per line; components are comma- or space-separated. Up to 3 vectors, up to 3 components per vector.

Results

Orthogonal (u1, u2, u3)
0
Orthonormal (e1, e2, e3) 0
Norms of u1, u2, u3 0

What Is Gram Schmidt Calculator?

A Gram Schmidt calculator turns a list of 2 or 3 linearly independent vectors in 2D or 3D into an orthogonal set and then into an orthonormal basis for the same subspace. Use it to check the orthogonality of basis vectors in a class problem, to clean up a basis before a QR factorization, or to build a stable coordinate frame from measured directions.

  • Linear algebra homework: Walk through orthogonal and orthonormal basis steps for two or three input vectors in R^2 or R^3.
  • QR decomposition cross-check: Read the Q columns from e_i and the R diagonal from the Norms output to confirm a hand QR factorization.
  • Stable coordinate frames: Convert measured directions into a mutually perpendicular frame for graphics, robotics, or finite element work.
  • Linear dependence check: Submit a candidate basis; a linear-dependence error means the input does not span the claimed dimension.

Gram-Schmidt is a constructive proof that every finite-dimensional inner product space has an orthonormal basis. Given linearly independent vectors v_1, ..., v_n, the process produces u_1, ..., u_n that span the same subspace with every pair perpendicular, and then divides by length to give an orthonormal e_1, ..., e_n. The modified variant re-orthogonalizes each candidate vector against the most recent basis vector, which keeps the result stable for nearly parallel inputs.

When you also need the Euclidean length of each input or output vector alongside the basis, the Vector Magnitude Calculator covers the per-vector norm calculation that the Gram-Schmidt step implicitly reuses.

How Gram Schmidt Calculator Works

The calculator parses the textarea into input vectors, validates the count and dimension, runs modified Gram-Schmidt to produce the orthogonal u_i, and divides each u_i by its norm to produce the orthonormal e_i. The first orthogonal vector is the first input vector, and each later one is the next input vector minus its projection onto every earlier orthogonal vector.

u_1 = v_1; u_i = v_i - sum_{j<i} ((v_i . u_j) / (u_j . u_j)) * u_j; e_i = u_i / ||u_i||
  • v_i: input vector at position i in the user-supplied list, 2D or 3D
  • u_i: orthogonal vector at position i, output of the modified Gram-Schmidt recurrence
  • e_i: orthonormal vector at position i, equal to u_i divided by its Euclidean norm
  • r_ij: inner product (v_i . u_j) divided by (u_j . u_j); the diagonal r_ii equals ||u_i||, which appears in the Norms output

The recurrence comes from the projection formula proj_u(v) = ((v . u) / (u . u)) * u. Subtracting the projection leaves a vector perpendicular to u, so removing all earlier projections makes u_i perpendicular to the entire basis.

Three 3D vectors (1, 1, 0), (1, 0, 1), (0, 1, 1)

Paste the three vectors as separate lines: 1, 1, 0 | 1, 0, 1 | 0, 1, 1.

u_1 = (1, 1, 0). The projection of v_2 onto u_1 has coefficient 1/2, so u_2 = (1, 0, 1) - (1/2) * (1, 1, 0) = (0.5, -0.5, 1). The projection of v_3 onto u_1 has coefficient 1/2 and onto u_2 has coefficient 1/3, so u_3 = (0, 1, 1) - (0.5, 0.5, 0) - (1/3) * (0.5, -0.5, 1) = (-0.6667, 0.6667, 0.6667).

u_1 = (1, 1, 0); u_2 = (0.5, -0.5, 1); u_3 = (-0.6667, 0.6667, 0.6667). Divide by ||u_i|| to get e_1 = (0.7071, 0.7071, 0), e_2 = (0.4082, -0.4082, 0.8165), e_3 = (-0.5774, 0.5774, 0.5774).

All three u_i are mutually perpendicular, and each e_i has length 1. The Norms output reads 1.4142, 1.2247, 1.1547, the diagonal of the QR factorization R matrix.

According to Wolfram MathWorld, the Gram-Schmidt process orthogonalizes a set of vectors by repeatedly subtracting the projection of the next vector onto the orthogonal basis built so far.

The projection coefficient (v_i . u_j) / (u_j . u_j) in the Gram-Schmidt recurrence is built from inner products, and the Dot Product Calculator computes the same dot product v . u for any pair of vectors you want to check by hand.

Key Concepts Explained

Four ideas carry the entire algorithm. Understanding them removes the guesswork from both the calculation and the interpretation of the result.

Inner Product

The dot product v . u is the sum of the component-by-component products, and equals ||v|| * ||u|| * cos(theta). When v . u = 0 the vectors are perpendicular, and every step of Gram-Schmidt reads inner products off the input.

Projection Subtraction

The vector proj_u(v) = ((v . u) / (u . u)) * u is the part of v that points along u. Subtracting it from v leaves a vector perpendicular to u, and repeating for every earlier basis vector makes the new vector perpendicular to the whole basis.

Linear Independence

Gram-Schmidt only works when the input vectors span a subspace of dimension equal to the number of vectors. A vector is dependent on the previous ones exactly when its projection-subtracted form is the zero vector, which the calculator catches as an error.

Modified vs Classical

The classical recurrence subtracts all earlier projections in one shot; the modified recurrence subtracts them one at a time and reuses the just-updated vector. The two agree in exact arithmetic, but the modified form keeps roundoff from accumulating for nearly parallel inputs.

A quick way to remember the recurrence is to read it as 'start with v_i, then remove every earlier direction from it.' The output u_i has no component along any of the previous u_j.

Cross product is a different way to build a perpendicular vector in 3D, and the Cross Product Calculator is useful when you want to confirm that a Gram-Schmidt u_i matches the cross product of two others.

How to Use This Calculator

Paste the vectors, read off the orthogonal u_i, and then the orthonormal e_i. The same flow works for homework answers or QR extraction.

  1. 1 List the input vectors: Write each vector on its own line, separating components with commas or spaces. Two vectors for a 2D or 3D pair, three for a full 2D or 3D basis.
  2. 2 Match the dimension: Use 2 components per line for 2D, 3 for 3D. Mixed dimensions are rejected; for 2D vectors leave any third slot empty or set it to 0.
  3. 3 Read the orthogonal set: The first output lists u_1, u_2, u_3, the orthogonal but unnormalized basis. Each u_i is perpendicular to every earlier u_j and the set spans the same subspace as the input.
  4. 4 Read the orthonormal set: The second output lists e_1, e_2, e_3, the orthonormal basis. Every e_i has length 1, and the set is the Q matrix in a QR factorization.
  5. 5 Use the norms row as R: The third output gives ||u_1||, ||u_2||, ||u_3||. These are the diagonal entries of the R matrix, and the off-diagonal R entries are the projection coefficients (v_i . u_j) / (u_j . u_j) computed during the recurrence.

An engineer has three measured directions (1, 1, 0), (1, 0, 1), (0, 1, 1) for a coordinate frame and wants to confirm it is orthogonal. Pasting the three vectors returns u_1, u_2, u_3 that are mutually perpendicular, and the e_i row gives the unit-length frame for downstream use.

Once you have the Q columns and the upper-triangular R row, the next step in many linear-algebra workflows is to put them to work on a 2x2 or 3x3 system, and the System of Equations Calculator runs Cramer's rule and Gaussian elimination on coefficients of the same dimension to reach an equivalent triangular form.

Benefits of Using This Calculator

A purpose-built Gram Schmidt calculator saves you from re-doing the same projection steps by hand and keeps the bookkeeping visible at every iteration.

  • Visible intermediate steps: Both the orthogonal u_i and the orthonormal e_i are shown side by side, so you can read off the unnormalized basis for projection work and the unit basis for orthonormal frames from the same run.
  • Numerical stability: The modified recurrence reuses the just-updated vector for the next projection, which keeps roundoff in check when inputs are close to parallel.
  • QR decomposition shortcut: The Norms output is the diagonal of R, and the e_i row is the Q matrix. You can read off a full QR factorization without rewriting the algorithm.
  • Linear-dependence detection: The calculator checks every intermediate u_i for a near-zero norm. A linear-dependence error tells you the input vectors do not span the expected dimension.
  • Supports 2D and 3D inputs: Both 2D pairs and 3D triples use the same input format, so you can switch between class problems and real coordinate frames without re-formatting.

The same output doubles as a teaching aid and a workaday engineering tool: students see the projection arithmetic, practitioners see the QR-style R row and the Q columns at the same time.

With the orthonormal e_i basis in hand, point distances in the new frame collapse to a square root of summed squared components, and the 3D Distance Calculator runs that same Euclidean formula in the original coordinates whenever you want a direct sanity check against the projected distance.

Factors That Affect Your Results

A few decisions about inputs and tolerances change what the calculator returns. Knowing them helps you interpret borderline cases.

Linear independence of the input

Gram-Schmidt requires the input vectors to span a subspace of dimension equal to their count. Two parallel vectors or three coplanar vectors in 3D trigger a linear-dependence error.

Vector ordering

The orthogonal set depends on the order of the input vectors. Reordering the input changes the intermediate u_i values, although the final span of the orthogonal set is the same.

Numerical conditioning

When input vectors are nearly parallel, the projection coefficient (v_i . u_j) / (u_j . u_j) becomes large and amplifies roundoff in the input. The modified recurrence mitigates this but does not eliminate it.

Component format

Components may be integers or decimals, separated by commas or spaces. The internal computation uses double precision, so the displayed four-decimal values are rounded for readability, not for accuracy.

  • This calculator accepts 2 or 3 input vectors in 2D or 3D. For 4D or higher-dimensional inputs, the same recurrence still works but is not exposed by the page.
  • The result is rounded for display to four decimals. The internal arithmetic keeps full precision, but a hand calculation that rounds each intermediate value will not match the page output to more than a few digits.
  • The Norms output is the diagonal of R, but the off-diagonal projection coefficients are not displayed. Recover them from the recurrence if a full R is needed.

The recurrence and the output are equivalent to the QR factorization of the input matrix: e_i is the Q matrix and the Norms output is the diagonal of R, which is what makes Gram-Schmidt a workhorse algorithm in numerical linear algebra.

According to Wikipedia, dividing each orthogonal vector by its length gives an orthonormal set of vectors that span the same subspace as the original input vectors.

According to Khan Academy, the Gram-Schmidt process is the standard way to turn a list of linearly independent vectors into an orthonormal basis for the same subspace.

The QR factorization that this calculator implicitly computes is also the standard way to solve the least-squares problem in a linear regression fit, and the Linear Regression Calculator shows the same orthonormal-basis idea at work in that workflow.

Gram Schmidt calculator showing orthogonal u and orthonormal e basis vectors for 2D and 3D input sets with intermediate norms
Gram Schmidt calculator showing orthogonal u and orthonormal e basis vectors for 2D and 3D input sets with intermediate norms

Frequently Asked Questions

Q: What does the Gram Schmidt calculator do?

A: It accepts 2 or 3 input vectors in 2D or 3D and returns the orthogonal u_i and orthonormal e_i basis for the same subspace, using modified Gram-Schmidt. The Norms output is the diagonal of the R matrix.

Q: How do you orthogonalize two vectors with Gram-Schmidt?

A: Keep the first vector as u_1 = v_1. For the second, compute r = (v_2 . u_1) / (u_1 . u_1) and set u_2 = v_2 - r * u_1. The two u_i are perpendicular; dividing each by its length gives the orthonormal e_i.

Q: What is the difference between orthogonal and orthonormal vectors?

A: Orthogonal vectors are mutually perpendicular with dot product zero, but their lengths are not fixed. Orthonormal vectors are orthogonal and each has length exactly 1, obtained by dividing each orthogonal vector by its norm.

Q: What happens if the input vectors are linearly dependent?

A: The modified Gram-Schmidt recurrence returns a near-zero u_i, which the calculator catches as a linear-dependence error. The basis is not returned because the input does not span the expected dimension.

Q: Why use modified Gram-Schmidt instead of classical Gram-Schmidt?

A: The classical form subtracts all earlier projections in one shot using the original v_i, while the modified form re-orthogonalizes against the most recent basis vector, keeping roundoff from compounding for nearly parallel inputs.

Q: Is the Gram-Schmidt result the same as QR decomposition?

A: Yes. The orthonormal e_i are the Q matrix of the QR factorization, and the diagonal of R is the list of ||u_i|| in the Norms output. The off-diagonal R entries are the projection coefficients (v_i . u_j) / (u_j . u_j).