Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Gram-Schmidt Process


Symbolic visualization of Gram–Schmidt — keep, subtract projections, normalize — on two or three vectors.

Number of vectors?Gram–Schmidt turns any list of independent vectors into an orthogonal list with the same span, one vector at a time: keep the first, and from each later vector subtract its projections onto every vector already made orthogonal. What remains is perpendicular to all of them. Dividing each result by its length then gives an orthonormal set. The vectors must be independent; a dependent v_k is reduced to zero and cannot be normalized.
k3
Vector length
n33 vectors in ℝ3
V3×3
v1,1
v1,2
v1,3
v2,1
v2,2
v2,3
v3,1
v3,2
v3,3
U3×3
?
?
?
?
?
?
?
?
?
Step 1 / 11

Step explanations

1Gram–Schmidt on 3 vectors in ℝ3
The rows of V are the input vectors v1…v3. Gram–Schmidt replaces them, in order, by vectors u1…u3 that are mutually perpendicular and span the same space: keep the first, and from each later vector subtract its projections onto the ones already done. A final pass divides each uk by its length to make the set orthonormal.
Keep the first, subtract projections from the rest, then normalize. Learn more about the opening scene · what it is








Key Terms

Orthogonal set — vectors that are pairwise perpendicular: uiuj=0\mathbf{u}_i \cdot \mathbf{u}_j = 0 whenever iji \neq j.

Orthonormal set — an orthogonal set in which every vector has length 11.

Gram-Schmidt process — the procedure that turns any list of independent vectors v1,,vk\mathbf{v}_1, \ldots, \mathbf{v}_k into an orthogonal list u1,,uk\mathbf{u}_1, \ldots, \mathbf{u}_k with the same span, and then into an orthonormal list e1,,ek\mathbf{e}_1, \ldots, \mathbf{e}_k.

Projection coefficientck,j=vkujujujc_{k,j} = \dfrac{\mathbf{v}_k \cdot \mathbf{u}_j}{\mathbf{u}_j \cdot \mathbf{u}_j}, the multiple of uj\mathbf{u}_j that is subtracted from vk\mathbf{v}_k.

Orthogonalization — the first pass, uk=vkj<kck,juj\mathbf{u}_k = \mathbf{v}_k - \sum_{j < k} c_{k,j} \mathbf{u}_j.

Normalization — the second pass, ek=uk/uk\mathbf{e}_k = \mathbf{u}_k / \|\mathbf{u}_k\|.

Span preservation — at every stage span{u1,,uk}=span{v1,,vk}\operatorname{span}\{\mathbf{u}_1, \ldots, \mathbf{u}_k\} = \operatorname{span}\{\mathbf{v}_1, \ldots, \mathbf{v}_k\}.

QR decomposition — the matrix form of the process: with the vk\mathbf{v}_k as the columns of AA and the ek\mathbf{e}_k as the columns of QQ, A=QRA = QR with RR upper triangular.

Getting Started with the Visualizer

Set how many vectors and how long they are, then watch the process run.

• Use the Number of vectors stepper for 22 or 33 input vectors; they are the rows of the matrix VV
• Use the Vector length stepper for 22, 33 or 44 components
• Hover the ? icon for a reminder of what the process does and why the inputs must be independent
• Press play or step manually through the scene player; the speed selector and step log let you control pace and review
• Everything is symbolic: the coefficients are named ck,jc_{k,j} and the lengths uk\|\mathbf{u}_k\|, so each row of UU shows the structure of the formula rather than a numerical result

Choosing 33 vectors of length 22 is allowed and instructive: three vectors in the plane cannot be independent, and the caption points out that the third would reduce to zero.

The Phases

The visualizer runs the process in the order it is always written.

Keepu1=v1\mathbf{u}_1 = \mathbf{v}_1; the first vector sets the first direction and is not changed
Startuk\mathbf{u}_k begins as a copy of vk\mathbf{v}_k, not yet perpendicular to anything
Subtract — one scene for each earlier uj\mathbf{u}_j: the projection of vk\mathbf{v}_k onto uj\mathbf{u}_j is subtracted, and row kk of UU grows one term, ck,juj- c_{k,j} \mathbf{u}_j
Normalize — one scene per vector: ek=uk/uk\mathbf{e}_k = \mathbf{u}_k / \|\mathbf{u}_k\|, filling the rows of EE
Done — the rows of EE are orthonormal and span the same space as the rows of VV

The layout changes once, between the two passes: VUV \to U while the vectors are being made perpendicular, then UEU \to E while they are being scaled to length one.

The Opening Scene: The Input Set as Rows

The player opens with the input vectors stacked as the rows of VV and an empty matrix UU of the same shape beside it. At the default size there are three vectors of length three.

Nothing is computed yet. What the scene establishes is the plan: the rows of UU will be filled top to bottom, each one made perpendicular to the rows above it before the next is started.
V3×3v1,1v1,2v1,3v2,1v2,2v2,3v3,1v3,2v3,3U3×3?????????
Opening scene, frozen

Three input vectors stacked as the rows of V, an empty U beside them. The rows of U will be filled top to bottom, each made perpendicular to the ones above before the next begins.

Stacking the vectors as rows is a presentational choice; the process does not care whether the vectors are rows or columns. In the QR decomposition they are the columns of AA, and the rows of EE here are the columns of QQ there.

The one precondition is independence. The tool does not check it, because its inputs are symbolic, but the caption notes when the chosen sizes make independence impossible: three vectors in R2\mathbb{R}^2 cannot all survive the process.

Keeping the First Vector

The first step is the easiest: u1=v1\mathbf{u}_1 = \mathbf{v}_1, copied across unchanged.

The frozen picture below shows the copy: row 11 of VV highlighted as the source, row 11 of UU filled with the same components.
V3×3v1,1v1,2v1,3v2,1v2,2v2,3v3,1v3,2v3,3U3×3v1,1v1,2v1,3??????
First vector kept, frozen

u1 = v1, copied across unchanged. Nothing to be perpendicular to yet; this row fixes the first direction and every later vector is adjusted against it.

There is nothing for the first vector to be perpendicular to, so nothing is subtracted. Its only role is to fix the first direction of the orthogonal set, and that choice propagates: every later vector is adjusted relative to it.

This is where the order dependence enters. Start with a different v\mathbf{v} and the whole output changes, even though the span it describes does not.

Subtracting the Projections

Each later vector begins as a copy of itself and then loses, one at a time, its projections onto the vectors already made orthogonal. The coefficient of each projection is ck,j=(vkuj)/(ujuj)c_{k,j} = (\mathbf{v}_k \cdot \mathbf{u}_j) / (\mathbf{u}_j \cdot \mathbf{u}_j), and the row of UU grows a term with every subtraction.

The frozen picture below is the last subtraction at the default size: row 33 of UU reads v3,ic3,1u1,ic3,2u2,iv_{3,i} - c_{3,1} u_{1,i} - c_{3,2} u_{2,i}, perpendicular to both earlier rows.
V3×3v1,1v1,2v1,3v2,1v2,2v2,3v3,1v3,2v3,3U3×3v1,1v1,2v1,3v2,1c2,1u1,1v2,2c2,1u1,2v2,3c2,1u1,3v3,1c3,1u1,1c3,2u2,1v3,2c3,1u1,2c3,2u2,2v3,3c3,1u1,3c3,2u2,3
Last subtraction, frozen

Row 3 of U reading v3,i − c3,1u1,i − c3,2u2,i. The projections are onto u1 and u2, already orthogonal - never onto the original v2.

The projection is always onto the uj\mathbf{u}_j, never onto the original vj\mathbf{v}_j. That is the detail the picture is built to show: the row highlighted as the source of each subtraction is a row of UU, already orthogonal, not a row of VV.

Subtracting projections onto perpendicular directions is what makes the pieces independent of one another. Removing the u1\mathbf{u}_1 component of v3\mathbf{v}_3 does not disturb its u2\mathbf{u}_2 component, because u1u2\mathbf{u}_1 \perp \mathbf{u}_2; so the two subtractions can be done in either order and the result is the same vector, perpendicular to both.

Normalizing

The second pass divides every component of each uk\mathbf{u}_k by its length uk\|\mathbf{u}_k\|, filling the rows of EE.

The frozen picture below is the first normalization: row 11 of UU as the source, row 11 of EE reading u1,i/u1u_{1,i} / \|\mathbf{u}_1\|.
U3×3v1,1v1,2v1,3v2,1c2,1u1,1v2,2c2,1u1,2v2,3c2,1u1,3v3,1c3,1u1,1c3,2u2,1v3,2c3,1u1,2c3,2u2,2v3,3c3,1u1,3c3,2u2,3E3×3u1,1/u1u1,2/u1u1,3/u1??????
First normalization, frozen

Row 1 of U divided by its length into row 1 of E. Lengths change, directions do not, so the perpendicularity from the first pass survives.

Normalization is the magnitude tool's third phase applied kk times. It changes lengths and nothing else, so the perpendicularity established in the first pass survives it, and the result is an orthonormal set.

Doing the two passes separately is a teaching device. In practice each uk\mathbf{u}_k is often normalized as soon as it is finished, and the later coefficients become plain dot products vkej\mathbf{v}_k \cdot \mathbf{e}_j with no division. Either way the output is the same.

The Completed Orthonormal Set

The final scene shows every row of EE filled: an orthonormal set spanning exactly the space the rows of VV span.

The frozen picture below is the default run complete, three unit vectors, pairwise perpendicular.
U3×3v1,1v1,2v1,3v2,1c2,1u1,1v2,2c2,1u1,2v2,3c2,1u1,3v3,1c3,1u1,1c3,2u2,1v3,2c3,1u1,2c3,2u2,2v3,3c3,1u1,3c3,2u2,3E3×3u1,1/u1u1,2/u1u1,3/u1u2,1/u2u2,2/u2u2,3/u2u3,1/u3u3,2/u3u3,3/u3
Completed orthonormal set, frozen

All three rows of E filled: unit vectors, pairwise perpendicular, spanning the same space as the rows of V. As columns, this is the Q of A = QR.

Two things are true of the finished set beyond orthonormality. The first mm rows of EE span the same space as the first mm rows of VV, for every mm, because the process never looks ahead. And the numbers it discarded along the way, the coefficients ck,jc_{k,j} and the lengths uk\|\mathbf{u}_k\|, are not waste: rescaled by the lengths, they are the entries of the upper triangular RR in A=QRA = QR, with the rows of EE as the columns of QQ.

That is why the process is the foundation of so much numerical linear algebra. An orthonormal basis turns projections, coordinates and least squares into dot products, and Gram-Schmidt is the direct way to get one.

Reading the Scene Player

Each scene combines row highlights, an arrow, and a caption.

• In a keep or start scene, the source row of VV is primary and the destination row of UU is accent
• In a subtract scene, the row of VV being processed is primary, the row uj\mathbf{u}_j being projected onto is secondary, and the row being built is accent, with an arrow from uj\mathbf{u}_j into it; the caption states the coefficient formula and the full expression so far
• In a normalize scene, the row of UU is primary and the row of EE accent, with an arrow between them
• Cells of UU show the accumulated expression vk,ick,1u1,iv_{k,i} - c_{k,1} u_{1,i} - \cdots, and cells of EE show uk,i/uku_{k,i} / \|\mathbf{u}_k\|, at a font size that scales with the number of terms
• The step log on the right keeps a record of every completed step across both passes

Choosing the Size

Two and three vectors cover the whole pattern, and lengths from 22 to 44 show that the length is irrelevant to it.

• With 22 vectors there is one subtraction: u2=v2c2,1u1\mathbf{u}_2 = \mathbf{v}_2 - c_{2,1} \mathbf{u}_1, the projection tool's remainder
• With 33 vectors there are three subtractions, and the third vector shows the essential point: it is projected onto u1\mathbf{u}_1 and u2\mathbf{u}_2, the vectors already made orthogonal, never onto the original v2\mathbf{v}_2
• The vector length only changes how many components each row has; the number of scenes depends on the number of vectors alone
• Beyond three vectors the pattern simply continues, with k1k - 1 subtractions for the kk-th vector; the tool stops at three because the expressions in row 33 of UU are already three terms long

What the Gram-Schmidt Process Is

Given linearly independent vectors v1,,vk\mathbf{v}_1, \ldots, \mathbf{v}_k, the process produces orthogonal vectors

u1=v1,uk=vkj=1k1vkujujujuj\mathbf{u}_1 = \mathbf{v}_1, \qquad \mathbf{u}_k = \mathbf{v}_k - \sum_{j=1}^{k-1} \frac{\mathbf{v}_k \cdot \mathbf{u}_j}{\mathbf{u}_j \cdot \mathbf{u}_j}\,\mathbf{u}_j


and then orthonormal vectors

ek=ukuk\mathbf{e}_k = \frac{\mathbf{u}_k}{\|\mathbf{u}_k\|}


Each uk\mathbf{u}_k is vk\mathbf{v}_k with its projections onto all the earlier uj\mathbf{u}_j removed, so it is perpendicular to every one of them; and since it differs from vk\mathbf{v}_k only by a combination of earlier vectors, the span is unchanged at every step. The result is an orthonormal basis of span{v1,,vk}\operatorname{span}\{\mathbf{v}_1, \ldots, \mathbf{v}_k\} with the extra property that the first mm output vectors span the same space as the first mm inputs, for every mm.

Why the subtraction works: dot uk\mathbf{u}_k with any earlier uj\mathbf{u}_j. The projections onto the other ui\mathbf{u}_i contribute nothing, since they are already perpendicular to uj\mathbf{u}_j, and the projection onto uj\mathbf{u}_j contributes exactly vkuj-\mathbf{v}_k \cdot \mathbf{u}_j, cancelling the vkuj\mathbf{v}_k \cdot \mathbf{u}_j from the first term.

Independence is required. If vk\mathbf{v}_k lies in the span of the earlier vectors, subtracting its projections leaves uk=0\mathbf{u}_k = \mathbf{0}, which cannot be normalized. For the full treatment, including the modified Gram-Schmidt variant and numerical behaviour, see the Gram-Schmidt theory page.

Key Properties

The output of the process has more structure than orthonormality alone.

Orthogonality: uiuj=0\mathbf{u}_i \cdot \mathbf{u}_j = 0 and eiej=0\mathbf{e}_i \cdot \mathbf{e}_j = 0 for iji \neq j
Unit length: ek=1\|\mathbf{e}_k\| = 1 for every kk
Nested spans: span{e1,,em}=span{v1,,vm}\operatorname{span}\{\mathbf{e}_1, \ldots, \mathbf{e}_m\} = \operatorname{span}\{\mathbf{v}_1, \ldots, \mathbf{v}_m\} for every mkm \leq k
Order matters: reordering the inputs gives a different orthonormal basis of the same space
Coefficients are inner products: with the orthonormal vectors, vk=jk(vkej)ej\mathbf{v}_k = \sum_{j \leq k} (\mathbf{v}_k \cdot \mathbf{e}_j)\,\mathbf{e}_j, which is the kk-th column of RR in A=QRA = QR
Independence test: a zero uk\mathbf{u}_k means vk\mathbf{v}_k was dependent on its predecessors
Coordinates for free: in an orthonormal basis the coordinates of any vector are its dot products with the basis vectors, no system to solve
Numerical caveat: in floating point, subtracting all projections from the original vk\mathbf{v}_k loses orthogonality gradually; the modified variant subtracts each projection from the running remainder instead and is more stable

Why It Matters

Orthonormal bases make almost every computation in linear algebra simpler, and Gram-Schmidt is how they are made.

QR decomposition: the process on the columns of AA gives A=QRA = QR, the workhorse of least squares and of eigenvalue algorithms
Least squares: solving AxbAx \approx b with an orthonormal basis of the column space reduces to dot products, avoiding the ill-conditioned normal equations
Orthogonal projection onto a subspace: with an orthonormal basis e1,,ek\mathbf{e}_1, \ldots, \mathbf{e}_k of the subspace, the projection of any w\mathbf{w} is (wej)ej\sum (\mathbf{w} \cdot \mathbf{e}_j)\,\mathbf{e}_j
Change of basis: an orthonormal basis matrix QQ has Q1=QTQ^{-1} = Q^T, so converting coordinates costs a transpose rather than an inversion
Function spaces: applied to 1,x,x2,1, x, x^2, \ldots with an integral inner product, the same process produces the Legendre polynomials and their relatives
Signal processing and statistics: orthogonalizing regressors or basis signals removes redundancy so that each contribution can be read off independently

Worked Example

Take three vectors in R3\mathbb{R}^3:

v1=(110),v2=(101),v3=(011)\mathbf{v}_1 = \begin{pmatrix} 1 \\ 1 \\ 0 \end{pmatrix}, \quad \mathbf{v}_2 = \begin{pmatrix} 1 \\ 0 \\ 1 \end{pmatrix}, \quad \mathbf{v}_3 = \begin{pmatrix} 0 \\ 1 \\ 1 \end{pmatrix}


Keep: u1=v1=(1,1,0)\mathbf{u}_1 = \mathbf{v}_1 = (1, 1, 0).

Second vector: c2,1=v2u1u1u1=12c_{2,1} = \dfrac{\mathbf{v}_2 \cdot \mathbf{u}_1}{\mathbf{u}_1 \cdot \mathbf{u}_1} = \dfrac{1}{2}, so

u2=v212u1=(12,12,1)\mathbf{u}_2 = \mathbf{v}_2 - \tfrac{1}{2}\mathbf{u}_1 = \left(\tfrac{1}{2}, -\tfrac{1}{2}, 1\right)


Check: u2u1=1212+0=0\mathbf{u}_2 \cdot \mathbf{u}_1 = \tfrac{1}{2} - \tfrac{1}{2} + 0 = 0.

Third vector: c3,1=12c_{3,1} = \dfrac{1}{2} and c3,2=v3u2u2u2=12+114+14+1=1/23/2=13c_{3,2} = \dfrac{\mathbf{v}_3 \cdot \mathbf{u}_2}{\mathbf{u}_2 \cdot \mathbf{u}_2} = \dfrac{-\frac{1}{2} + 1}{\frac{1}{4} + \frac{1}{4} + 1} = \dfrac{1/2}{3/2} = \dfrac{1}{3}, so

u3=v312u113u2=(23,23,23)\mathbf{u}_3 = \mathbf{v}_3 - \tfrac{1}{2}\mathbf{u}_1 - \tfrac{1}{3}\mathbf{u}_2 = \left(-\tfrac{2}{3}, \tfrac{2}{3}, \tfrac{2}{3}\right)


Check: u3u1=23+23=0\mathbf{u}_3 \cdot \mathbf{u}_1 = -\tfrac{2}{3} + \tfrac{2}{3} = 0 and u3u2=1313+23=0\mathbf{u}_3 \cdot \mathbf{u}_2 = -\tfrac{1}{3} - \tfrac{1}{3} + \tfrac{2}{3} = 0.

Normalize: u1=2\|\mathbf{u}_1\| = \sqrt{2}, u2=3/2\|\mathbf{u}_2\| = \sqrt{3/2}, u3=4/3\|\mathbf{u}_3\| = \sqrt{4/3}, giving

e1=12(1,1,0),e2=16(1,1,2),e3=13(1,1,1)\mathbf{e}_1 = \tfrac{1}{\sqrt{2}}(1, 1, 0), \quad \mathbf{e}_2 = \tfrac{1}{\sqrt{6}}(1, -1, 2), \quad \mathbf{e}_3 = \tfrac{1}{\sqrt{3}}(-1, 1, 1)


Set the visualizer to 33 vectors of length 33 and step through to see the same six steps assembled symbolically, with c2,1c_{2,1}, c3,1c_{3,1} and c3,2c_{3,2} standing for the three fractions above.

Common Mistakes

A few mistakes recur.

Projecting onto the original vectorsv3\mathbf{v}_3 must be projected onto u1\mathbf{u}_1 and u2\mathbf{u}_2, the vectors already made orthogonal, not onto v1\mathbf{v}_1 and v2\mathbf{v}_2; using the originals does not produce a perpendicular remainder
Normalizing too early — dividing uj\mathbf{u}_j by its length before using it in later projections is fine if the coefficient formula is adjusted to vkej\mathbf{v}_k \cdot \mathbf{e}_j, but mixing the two conventions gives wrong coefficients
Dividing by uj\|\mathbf{u}_j\| instead of ujuj\mathbf{u}_j \cdot \mathbf{u}_j — the projection coefficient needs the squared length, exactly as in the projection formula
Forgetting that order matters — running the process on the same vectors in a different order gives a different orthonormal basis
Feeding in dependent vectors — a dependent vk\mathbf{v}_k reduces to uk=0\mathbf{u}_k = \mathbf{0}; the fix is to drop it and continue, not to divide by zero
Skipping the check — every uk\mathbf{u}_k should be dotted against the earlier ones; a non-zero result means an arithmetic slip somewhere above it