Adjust the number of vectors and dimensions, then fill in the coordinates.
Gram-Schmidt Orthogonalization Calculator
Use this Gram-Schmidt Orthogonalization Calculator to enter values, adjust options, and review results in a compact responsive workspace.
Results are calculated automatically as you enter data.
2D projection view
The first two coordinates are plotted so dependence and projection direction are easy to see.
Step-by-step explanation
▼ See explanations and tips below ▼
Related Calculators
What Is Gram-Schmidt Orthogonalization?
Gram-Schmidt orthogonalization is a method for turning a set of vectors into a cleaner basis for the same span. The span is the collection of all vectors you can make from the original vectors by taking linear combinations.
The main idea is simple: process the vectors one at a time, remove the parts that point in directions you have already kept, and keep only the leftover part. That leftover part is called a residual. If the residual is not zero, it becomes a new basis vector. If the residual is zero, the original vector did not add a new direction.
The result is an orthogonal basis or, after scaling each basis vector to length 1, an orthonormal basis. Orthogonal basis vectors are easier to work with because they point in mutually perpendicular directions. Orthonormal basis vectors are even more convenient because they are perpendicular and have unit length.
Gram-Schmidt is widely used in linear algebra because it connects several important ideas at once: projections, dot products, norms, rank, linear independence, QR decomposition, and least-squares methods.
Why Gram-Schmidt Matters
A basis is useful because it gives a compact way to describe a subspace. An orthogonal or orthonormal basis is especially useful because each direction can be studied separately.
In a non-orthogonal basis, changing one coordinate can affect the meaning of another coordinate because the basis directions overlap. In an orthogonal basis, the directions do not overlap. This makes calculations involving projections, distances, coordinates, and approximation much easier.
Gram-Schmidt is useful when you need to:
- convert a spanning set into an orthogonal or orthonormal basis;
- identify how many independent directions a vector set contains;
- detect vectors that are linearly dependent on earlier vectors;
- understand how projection removes an already-covered direction;
- prepare for QR decomposition and least-squares calculations;
- check homework or numerical results in a linear algebra course.
Key Terms to Know
- Vector: An ordered list of coordinates, such as \((2,-1,4)\).
- Span: The set of all linear combinations that can be made from a group of vectors.
- Basis: A linearly independent set of vectors that spans a subspace.
- Linear independence: A vector set is linearly independent when no vector in the set can be built from the others.
- Linear dependence: A vector is dependent when it does not add a new direction to the span.
- Rank: The number of independent directions found in the vector set.
- Dot product: A way to measure how strongly two vectors point in the same direction.
- Euclidean norm: The usual length of a vector.
- Orthogonal vectors: Vectors whose dot product is zero.
- Orthonormal vectors: Orthogonal vectors that each have length 1.
- Projection: The part of one vector that lies in the direction of another vector.
- Residual: What remains after projections onto previous basis directions have been subtracted.
How Gram-Schmidt Works
For real vectors in Euclidean space, the dot product of two vectors is
The Euclidean norm is
Two nonzero vectors are orthogonal when their dot product is zero:
The projection of a vector \(v_i\) onto a nonzero vector \(u_j\) is
The fraction is the projection coefficient. It tells you how much of \(u_j\) is needed to match the part of \(v_i\) that points in the \(u_j\) direction.
The calculator evaluates these projections with modified Gram–Schmidt and then performs a second reorthogonalization pass. This is more reliable in floating-point arithmetic than subtracting all projections computed from the original vector at once.
Gram-Schmidt processes the input vectors in order. For each vector, it subtracts the projections onto the basis directions that have already been accepted:
Where:
- \(v_i\) is the current input vector.
- \(u_j\) is a previously accepted orthogonal basis vector.
- \(r_i\) is the residual after subtracting old directions.
- \(k\) is the number of accepted basis vectors so far.
If \(r_i\) is nonzero, it becomes the next orthogonal basis vector. If \(r_i\) is zero, the current vector is dependent on earlier accepted directions and is not added to the basis.
To produce an orthonormal basis, each accepted orthogonal vector is divided by its norm:
The orthogonal and orthonormal versions span the same subspace. The difference is that the orthonormal version rescales each nonzero basis vector to length 1.
Examples of Gram-Schmidt in Practice
Example 1: Building an orthogonal basis from two vectors
Suppose the input vectors are
Start with the first vector:
Now remove from \(v_2\) the part that points in the \(u_1\) direction:
The residual is
So an orthogonal basis is
Check the dot product:
The basis vectors are orthogonal.
To make the basis orthonormal, divide each vector by its length:
and
Example 2: Detecting a dependent vector
Now add a third vector:
From Example 1, the first two accepted orthogonal vectors are
Project \(v_3\) onto both accepted directions:
and
The residual is
A zero residual means \(v_3\) does not add a new direction. The three vectors still span a two-dimensional plane, so the rank is 2.
Example 3: Repeated directions
Consider
The first vector gives
The second vector lies on the same line. Its projection onto \(u_1\) is
The residual is
So \(v_2\) is dependent. The basis has one vector, and the rank is 1.
How to Interpret the Result
The result tells you how many independent directions were found and gives a basis for the same span as the useful input directions.
A rank of 1 means all nonzero accepted vectors point along one independent direction. A rank of 2 means the set contains two independent directions. In general, the rank is the number of nonzero residuals accepted during the process.
A dependent result means at least one input vector did not add a new direction. It may have been a multiple of an earlier vector, a combination of earlier vectors, or effectively zero after projections were removed.
An orthogonal basis means the output basis vectors are mutually perpendicular, but they do not necessarily have length 1.
An orthonormal basis means the output basis vectors are mutually perpendicular and each has length 1.
The normalized orthogonality error checks the largest absolute dot product between distinct unit basis directions. The span reconstruction residual checks whether each input vector can be reconstructed from the computed basis. Values close to \(0\) indicate that both properties hold up to rounding error.
The basis table gives the coordinates of the output basis vectors. These vectors span the same subspace as the independent part of the input set.
The step explanations show how each vector was handled. A step usually includes projection coefficients, projection vectors, the residual vector, the residual norm, and whether the residual was accepted as a new basis direction.
The graph is useful for intuition, especially in two dimensions. For vectors with more than two coordinates, the graph shows only the first two coordinates, so it should not be treated as a full picture of higher-dimensional geometry.
Common Mistakes and Misconceptions
Entering vectors as columns instead of rows. In this calculator, each row is one vector and each column is one coordinate. Reversing that layout changes the vector set.
Leaving a coordinate blank. A placeholder can look like a zero, but a blank cell is not the same as entering \(0\). Enter every coordinate explicitly.
Expecting orthogonal mode to normalize vectors. Orthogonal mode makes the basis vectors perpendicular. It does not force them to have length 1. Choose orthonormal mode when you want unit-length basis vectors.
Assuming every nearly dependent decision is exact. When a residual falls in the numerical uncertainty band, the calculator reports a rank interval instead of silently forcing a single rank. More input precision or an exact-arithmetic tool may be needed to resolve the rank.
Assuming the 2D graph shows every coordinate. A three-dimensional or higher-dimensional vector cannot be fully represented by a graph that uses only the first two coordinates.
Pasting fractions or variables. The calculator expects finite numeric coordinates. Use decimals such as \(0.5\) instead of a fraction string such as 1/2, and do not enter symbolic expressions.
Rounding too early by hand. Gram-Schmidt uses projections repeatedly, so early rounding can change later residuals. Keep extra digits until the final result when doing the calculation manually.
Expecting the same basis after reordering vectors. The span and rank may stay the same, but the specific orthogonal vectors can change when the input order changes.
When to Use Gram-Schmidt
Use Gram-Schmidt when you want to turn a vector set into a clearer basis for its span.
Common uses include:
- checking whether a group of vectors contains redundant directions;
- turning a basis into an orthogonal or orthonormal basis;
- finding the rank of a small vector set numerically;
- studying projections and residuals step by step;
- preparing for QR decomposition;
- simplifying least-squares and approximation problems;
- verifying classroom examples in linear algebra.
Gram-Schmidt is most helpful when the geometry of the vector set matters. It shows not only whether vectors are independent, but also how each new vector contributes a new perpendicular direction after earlier directions are removed.
Limitations and Things to Keep in Mind
Gram-Schmidt is a mathematical process, but calculator results are numerical approximations. That distinction matters.
This calculator uses floating-point arithmetic with scale-safe norms, modified Gram–Schmidt, and a second reorthogonalization pass. Dependence decisions use residual size relative to the original vector rather than a fixed absolute cutoff. Decimal inputs are limited to 15 significant digits so the interface does not imply precision that JavaScript numbers cannot preserve.
The calculator is designed for real-valued coordinate vectors. It does not support complex coordinates, symbolic variables, algebraic expressions, exact rational arithmetic, or fraction strings such as 1/2.
The interactive grid is limited to 20 vectors and 10 coordinates per vector. Imported data must also fit within those limits, and all imported vectors must have the same number of coordinates.
The output basis is for the span of the input vectors using the standard Euclidean dot product. If your application uses a different inner product or weighted geometry, the usual Gram-Schmidt formula must be changed.
Nearly dependent inputs can still be numerically ambiguous. In that case, the reported rank interval gives the directions that are definitely independent and the additional directions that are plausible at the available precision. For high-stakes engineering, scientific, or numerical linear algebra work, use validated software and precision appropriate for the problem.
How to Use This Calculator
- Enter each vector as one row in the coordinate grid.
- Enter one coordinate per column, using finite numbers such as \(2\), \(-3.5\), or \(0\).
- Use the vector and coordinate controls to match the size of your vector set, or import pasted vectors in the import area.
- If importing, separate vectors with newlines or semicolons, and separate coordinates with spaces or commas.
- Choose orthogonal output if you want perpendicular basis vectors without unit-length scaling.
- Choose orthonormal output if you want the accepted basis vectors scaled to length 1.
- Select the explanation level and turn projection arrows on or off as needed.
- Use the step slider to inspect a specific vector's projections and residual.
- Review the rank, dependence status, max dot product, basis table, and step cards.
- Download the graph as a PNG if a graph has been successfully rendered.
Frequently Asked Questions
What does Gram-Schmidt produce?
Gram-Schmidt produces an orthogonal basis for the span of the independent input directions. If orthonormal output is selected, the basis vectors are also scaled to length 1. Dependent vectors are skipped because they do not add new directions.
What is the difference between orthogonal and orthonormal?
Orthogonal vectors are perpendicular to each other, so their pairwise dot products are zero. Orthonormal vectors are orthogonal and also have norm 1. Every orthonormal set is orthogonal, but not every orthogonal set is orthonormal.
Why can a vector be marked dependent?
A vector is dependent when its residual becomes zero after subtracting projections onto earlier accepted basis vectors. This means the vector was already in the span of the previous accepted directions. Numerically, a very tiny residual may also be treated as zero.
Why is the max dot product not exactly zero?
In exact math, different vectors in an orthogonal basis have dot product \(0\). In a numerical calculator, floating-point rounding can leave very small nonzero values. A value close to \(0\) is usually the practical sign that the basis is orthogonal to numerical precision.
Does the order of input vectors matter?
Yes. Gram-Schmidt processes vectors in the order entered. Reordering the same vectors can produce a different orthogonal basis, although the span and rank of the independent directions may be the same.
Can I enter fractions, variables, or complex numbers?
No. Enter finite real numbers as coordinates. Use decimal equivalents for fractions, such as \(0.5\) instead of 1/2, and do not enter variables, expressions, NaN, or infinity.
Does the graph show higher-dimensional vectors accurately?
The graph uses only the first two coordinates of each vector. It can help you visualize projections in two dimensions, but it does not fully represent vectors with three or more coordinates.
Sources and References
Books
- Dan Margalit and Joseph Rabinoff. Interactive Linear Algebra. Georgia Institute of Technology, 2019. Sections 6.3 “Orthogonal Projection” and 6.4 “Orthogonal Sets.” Open textbook
- Robert A. Beezer. A First Course in Linear Algebra. Open textbook, PreTeXt beta edition. Section O “Orthogonality,” especially “Gram-Schmidt Procedure.” Open textbook section
Online and University Sources
- Thomas Trogdon. “The Modified Gram-Schmidt Procedure.” University of California, Irvine, Math 105A lecture notes. Accessed June 28, 2026. Lecture notes