Skip to content
Math

Gram-Schmidt Orthogonalization Calculator

Enter two to four vectors (each with two to four coordinates), choose how many vectors and dimensions to use, and this calculator applies the Gram-Schmidt process to produce both the orthogonal set and the fully normalized orthonormal basis. Every projection and subtraction step is shown so you can follow the working and check your own calculations. Linear dependence is flagged automatically.

Your details

How many input vectors to orthogonalize.
Number of coordinates in each vector.
First coordinate of vector 1.
e₁ (first orthonormal vector)
(0.2673, 0.8018, -0.5345)

First basis vector normalized to unit length.

e₂ (second orthonormal vector)(0.4438, 0.39, 0.8068)
e₃ (third orthonormal vector)(-0.8554, 0.4528, 0.2516)
e₄ (fourth orthonormal vector)-
u₁ (first orthogonal vector)(1, 3, -2)
u₂ (second orthogonal vector)(2.3571, 2.0714, 4.2857)
u₃ (third orthogonal vector)(-2.9266, 1.5494, 0.8608)
u₄ (fourth orthogonal vector)-
||u₁||3.7417
||u₂||5.3117
||u₃||3.4215
Dependence note-
||u₁||3.7417
||u₂||5.3117
||u₃||3.4215

Orthonormal basis computed for 3 vectors in 3D space.

  • Each output vector e_k has length exactly 1 and is perpendicular to every other output vector.
  • The set of e_k vectors spans the same subspace as your original input vectors.
  • You can verify orthonormality by checking that e_i · e_j = 0 for i ≠ j, and ||e_k|| = 1 for all k.
  • With 3 vectors in 3D, the result spans all of R3 if the vectors are independent.

Next stepThese orthonormal vectors can be used as columns of an orthogonal matrix Q in QR decomposition, or as a stable numerical basis for projections.

Formula

uk=vkj=1k1vkujujujuj,ek=ukuku_k = v_k - \sum_{j=1}^{k-1} \frac{v_k \cdot u_j}{u_j \cdot u_j}\, u_j, \qquad e_k = \frac{u_k}{\|u_k\|}

Worked example

Take v1 = (1, 3, -2) and v2 = (4, 7, 1). Step 1: u1 = v1 = (1, 3, -2), ||u1|| = sqrt(14) ~ 3.7417, so e1 ~ (0.2673, 0.8018, -0.5345). Step 2: proj(v2 onto u1) = (v2 dot u1 / u1 dot u1) * u1 = (4+21-2)/14 * (1,3,-2) = (23/14)(1,3,-2) ~ (1.643, 4.929, -3.286). u2 = v2 - proj = (2.357, 2.071, 4.286), ||u2|| ~ 5.16, e2 ~ (0.457, 0.401, 0.830).

What is the Gram-Schmidt process?

The Gram-Schmidt process is an algorithm for converting a set of linearly independent vectors into an orthogonal (or orthonormal) set that spans the same subspace. Given vectors v1, v2, ..., vk, the algorithm produces vectors u1, u2, ..., uk where every pair is perpendicular (their dot product is zero). Dividing each u_i by its own length then gives an orthonormal set e1, ..., ek, where every vector also has unit length. The result is the most numerically stable local coordinate frame for a subspace, used throughout numerical linear algebra and computer graphics.

How to use this calculator

Select the number of vectors and the number of coordinates per vector from the dropdowns. Enter the coordinates for each vector in the fields that appear. The calculator immediately applies Gram-Schmidt and shows you both the intermediate orthogonal vectors u_k and the final orthonormal vectors e_k, together with the length of each u_k. The step-by-step panel shows every projection subtraction and normalization in detail. If any input vector is linearly dependent on the ones before it, the calculator flags it: that vector produces a zero u_k and is excluded from the orthonormal set.

Orthogonal vs orthonormal: what is the difference?

An orthogonal set of vectors satisfies u_i dot u_j = 0 for all i not equal to j: every pair is perpendicular, but the vectors can have any length. An orthonormal set adds the requirement that each vector has length 1 (||e_k|| = 1). Gram-Schmidt naturally produces the orthogonal set first (the u_k vectors), then a single division by each vector length yields the orthonormal set (the e_k vectors). Most applications in machine learning, statistics, and signal processing require the orthonormal set, while QR decomposition works directly with either form.

Why does the process fail for linearly dependent vectors?

If a vector v_k already lies in the span of v1 through v_{k-1}, then after subtracting the projections of v_k onto all previous orthogonal vectors, the remainder u_k is the zero vector. Dividing a zero vector by its length is undefined, so no new basis vector can be added. This is not an error in the algorithm: it reveals that the input vectors do not form a linearly independent set. The fix is to replace or drop the dependent vector. You can test for dependence first by checking that the determinant of the matrix formed by your vectors is non-zero.

Applications of Gram-Schmidt orthogonalization

QR decomposition factors a matrix A into an orthogonal matrix Q (whose columns are the e_k vectors) and an upper-triangular matrix R, which is fundamental to solving least-squares problems, eigenvalue algorithms, and numerical stability. In signal processing, Gram-Schmidt orthogonalizes a set of waveforms or filter coefficients so they do not interfere with each other. In machine learning, principal component analysis (PCA) produces orthogonal directions of variance, a closely related idea. In quantum mechanics, a set of state vectors is orthonormalized before computing expectation values.

Gram-Schmidt process summary

Step kOrthogonal vector u_kOrthonormal vector e_k
1u1 = v1e1 = u1 / ||u1||
2u2 = v2 - (v2·u1/u1·u1)u1e2 = u2 / ||u2||
3u3 = v3 - (v3·u1/u1·u1)u1 - (v3·u2/u2·u2)u2e3 = u3 / ||u3||
4u4 = v4 - sum of projections onto u1, u2, u3e4 = u4 / ||u4||

Step-by-step structure of the classical Gram-Schmidt orthogonalization algorithm for k vectors.

Frequently asked questions

What does the Gram-Schmidt calculator compute?

It applies the Gram-Schmidt orthogonalization process to your input vectors to produce two related sets: an orthogonal set (the u_k vectors, which are mutually perpendicular but not necessarily unit length) and an orthonormal set (the e_k vectors, which are mutually perpendicular and each have length 1). The full set of intermediate steps, norms, and projections is shown in the step-by-step panel.

How many vectors and dimensions does this calculator support?

The calculator supports 2 to 4 input vectors and 2 to 4 coordinates per vector. For typical 2D and 3D problems in introductory linear algebra courses, 2 or 3 vectors with 2 or 3 dimensions covers almost every standard example. The 4D case handles problems in R4 such as those arising in computer graphics transformations or four-variable regression.

What does "linearly dependent" mean in the context of this process?

A vector is linearly dependent on the vectors before it if it can be written as a combination of those earlier vectors. When you subtract the projections of v_k onto all the orthogonal vectors found so far, the remainder is zero: there is nothing new the vector adds to the subspace. The calculator detects this automatically and reports which input vectors are dependent.

How do I verify that the output is actually orthonormal?

Take any two different output vectors e_i and e_j and compute their dot product: multiply matching coordinates and sum them. If the result is zero (or very close to zero given floating-point rounding), they are orthogonal. Next, compute the dot product of each vector with itself (sum of squares of coordinates): if the result is 1.0, the vector has unit length. The step-by-step panel in this calculator performs these verification checks for you.

What is QR decomposition and how does Gram-Schmidt relate to it?

QR decomposition writes a matrix A as a product Q * R, where Q is an orthogonal matrix (its columns are the e_k vectors from Gram-Schmidt applied to the columns of A) and R is an upper-triangular matrix whose entries are the dot products and norms computed during the process. The classical Gram-Schmidt algorithm is one of the standard methods for computing QR decomposition, used in least-squares fitting, eigenvalue solvers, and numerical linear algebra software.

Is the Gram-Schmidt process unique?

The process is unique given a fixed ordering of the input vectors, because at each step the projection onto the previously found orthogonal vectors is fully determined. If you reorder the input vectors, you get a different orthonormal basis for the same subspace. All valid orthonormal bases for that subspace are related by an orthogonal transformation, however, so they all have the same span and the same geometric properties.

Sources

Written by Dr. Rajiv Menon, PhD Applied Mathematician · Bengaluru, India

Applied mathematician bridging algebraic theory and computational tools for students, engineers, and everyday problem-solvers.

Search 3,500+ calculators

Loading search…