Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

How to Apply the Gram-Schmidt Process

Gram-Schmidt turns independent vectors into orthogonal ones with the same span. Keep the first vector; from each next one subtract its projections onto the orthogonal vectors already built.

Recognize the task

The problem asks for an orthogonal or orthonormal basis of a span, a column space or a subspace given by a basis, or for QQ in A=QRA = QR. Forms: orthogonalize (1,1,0),(2,0,1),(1,1,3)(1, 1, 0), (2, 0, 1), (1, 1, 3); find an orthonormal basis of Col⁡A\operatorname{Col} A; orthogonalize 1,x,x21, x, x^2 on [−1,1][-1, 1]. Test: the inputs must be independent; a zero vector during the process means they are not.
The process is set out in the Gram-Schmidt lesson, with the general Gram-Schmidt formula.

Steps

StepOn v1=(1,1,0)\mathbf{v}_1 = (1, 1, 0), v2=(2,0,1)\mathbf{v}_2 = (2, 0, 1), v3=(1,1,3)\mathbf{v}_3 = (1, 1, 3)
1Keep the first vector. Set u1=v1\mathbf{u}_1 = \mathbf{v}_1. Any order of the inputs works, but a different order gives a different basis.u1=(1,1,0)\mathbf{u}_1 = (1, 1, 0), u1⋅u1=2\mathbf{u}_1 \cdot \mathbf{u}_1 = 2
2Subtract the projection from the second vector. Remove from v2\mathbf{v}_2 its projection onto u1\mathbf{u}_1.v2⋅u12=1\frac{\mathbf{v}_2 \cdot \mathbf{u}_1}{2} = 1, u2=(2,0,1)−(1,1,0)=(1,−1,1)\mathbf{u}_2 = (2, 0, 1) - (1, 1, 0) = (1, -1, 1)
3Subtract both projections from the third vector. Project onto the new u1,u2\mathbf{u}_1, \mathbf{u}_2, never onto the original v1,v2\mathbf{v}_1, \mathbf{v}_2.v3⋅u12=1\frac{\mathbf{v}_3 \cdot \mathbf{u}_1}{2} = 1, v3⋅u23=1\frac{\mathbf{v}_3 \cdot \mathbf{u}_2}{3} = 1, u3=(1,1,3)−(1,1,0)−(1,−1,1)=(−1,1,2)\mathbf{u}_3 = (1, 1, 3) - (1, 1, 0) - (1, -1, 1) = (-1, 1, 2)
4Check orthogonality. Every pair of new vectors must have dot product zero; an arithmetic slip shows up here at once.u1⋅u2=u1⋅u3=u2⋅u3=0\mathbf{u}_1 \cdot \mathbf{u}_2 = \mathbf{u}_1 \cdot \mathbf{u}_3 = \mathbf{u}_2 \cdot \mathbf{u}_3 = 0 ✓
5Normalize for an orthonormal basis. Divide each ui\mathbf{u}_i by its length (normalization). Rescaling a ui\mathbf{u}_i early, for example to clear fractions, does not change the later vectors.12(1,1,0)\frac{1}{\sqrt{2}}(1, 1, 0), 13(1,−1,1)\frac{1}{\sqrt{3}}(1, -1, 1), 16(−1,1,2)\frac{1}{\sqrt{6}}(-1, 1, 2)

Worked examples

Example 1 · two vectors in the plane

2 vectors
v1=(1,1)\mathbf{v}_1 = (1, 1), v2=(3,1)\mathbf{v}_2 = (3, 1): v2⋅u1u1⋅u1=42=2\frac{\mathbf{v}_2 \cdot \mathbf{u}_1}{\mathbf{u}_1 \cdot \mathbf{u}_1} = \frac{4}{2} = 2
project onto u1=v1\mathbf{u}_1 = \mathbf{v}_1
u2=(3,1)−2(1,1)=(1,−1)\mathbf{u}_2 = (3, 1) - 2(1, 1) = (1, -1)
subtract the projection
{12(1,1),12(1,−1)}\{\frac{1}{\sqrt{2}}(1, 1), \frac{1}{\sqrt{2}}(1, -1)\}
normalize both

Example 2 · a dependent input

zero vector
v1=(1,2,0)\mathbf{v}_1 = (1, 2, 0), v2=(2,4,0)\mathbf{v}_2 = (2, 4, 0): v2⋅u1u1⋅u1=105=2\frac{\mathbf{v}_2 \cdot \mathbf{u}_1}{\mathbf{u}_1 \cdot \mathbf{u}_1} = \frac{10}{5} = 2
u2=(2,4,0)−2(1,2,0)=0\mathbf{u}_2 = (2, 4, 0) - 2(1, 2, 0) = \mathbf{0}
v2\mathbf{v}_2 was already in the span
drop v2\mathbf{v}_2; orthonormal basis {15(1,2,0)}\{\frac{1}{\sqrt{5}}(1, 2, 0)\}
a zero vector cannot be normalized

Example 3 · polynomials on an interval

integral inner product
⟨f,g⟩=∫−11f(x)g(x) dx\langle f, g \rangle = \int_{-1}^{1} f(x)g(x)\,dx; u1=1u_1 = 1; ⟨x,1⟩=0\langle x, 1 \rangle = 0, so u2=xu_2 = x
odd functions integrate to 00
⟨x2,1⟩⟨1,1⟩=2/32=13\frac{\langle x^2, 1 \rangle}{\langle 1, 1 \rangle} = \frac{2/3}{2} = \frac{1}{3}, ⟨x2,x⟩=0\langle x^2, x \rangle = 0
project x2x^2 onto 11 and xx
u3=x2−13u_3 = x^2 - \frac{1}{3}: orthogonal basis {1,x,x2−13}\{1, x, x^2 - \frac{1}{3}\}
Legendre polynomials, up to scale
The same numbers give A=QRA = QR, as the QR decomposition method shows. Run your own vectors through the vector calculator.

See it happen

Each step removes the shadow that vj\mathbf{v}_j casts on the vectors already built. What remains sticks straight out of their span, so it is perpendicular to all of them, and because the inputs are independent something always remains. Watch the shadows being removed in the Gram-Schmidt visualizer.

Common mistakes

Projecting onto the original vectors

✗ u3=v3−proj⁡v1v3−proj⁡v2v3\mathbf{u}_3 = \mathbf{v}_3 - \operatorname{proj}_{\mathbf{v}_1}\mathbf{v}_3 - \operatorname{proj}_{\mathbf{v}_2}\mathbf{v}_3
✓ u3=v3−proj⁡u1v3−proj⁡u2v3\mathbf{u}_3 = \mathbf{v}_3 - \operatorname{proj}_{\mathbf{u}_1}\mathbf{v}_3 - \operatorname{proj}_{\mathbf{u}_2}\mathbf{v}_3

Dropping the denominator

✗ u2=(2,0,1)−(v2⋅u1) u1=(0,−2,1)\mathbf{u}_2 = (2, 0, 1) - (\mathbf{v}_2 \cdot \mathbf{u}_1)\,\mathbf{u}_1 = (0, -2, 1)
✓ u2=(2,0,1)−22(1,1,0)=(1,−1,1)\mathbf{u}_2 = (2, 0, 1) - \frac{2}{2}(1, 1, 0) = (1, -1, 1)
You may skip the division only when u1\mathbf{u}_1 is a unit vector.

Normalizing the inputs instead of the outputs

✗ normalize v1,v2,v3\mathbf{v}_1, \mathbf{v}_2, \mathbf{v}_3 and call the result orthonormal
✓ orthogonalize first, then divide each ui\mathbf{u}_i by ∥ui∥\|\mathbf{u}_i\|