The Two-Vector Calculation
Given two independent vectors in \(\mathbb{R}^3\), Gram-Schmidt replaces them with an orthonormal pair that spans the same plane. The first output points in the direction of the first input. The second is obtained by removing from the second input exactly the component pointing along the first, then normalizing what remains. Each step has a concrete check: the final vectors must have length \(1\), and their dot product must be \(0\).
Throughout, vectors are columns in \(\mathbb{R}^3\), and we use the standard dot product \(\mathbf{x}\cdot\mathbf{y}=\mathbf{x}^{\top}\mathbf{y}\). The norm is \(\|\mathbf{x}\|=\sqrt{\mathbf{x}\cdot\mathbf{x}}\). A pair is orthonormal if both vectors have norm \(1\) and their dot product is \(0\). We assume the input vectors \(\mathbf{u}\) and \(\mathbf{v}\) are linearly independent, so in particular neither is zero.
The denominator \(\mathbf{u}\cdot\mathbf{u}\) is the square of the length of \(\mathbf{u}\), not its length. It is positive because \(\mathbf{u}\ne\mathbf{0}\). The scalar \((\mathbf{u}\cdot\mathbf{v})/(\mathbf{u}\cdot\mathbf{u})\) is chosen so that after subtracting that multiple of \(\mathbf{u}\), the remainder has dot product zero with \(\mathbf{u}\). Dividing by a norm changes length but not direction, so the normalization step preserves that perpendicularity.
Why the Steps Produce an Orthonormal Pair
Proof. Since independence implies \(\mathbf{u}\ne\mathbf{0}\), we have \(\mathbf{u}\cdot\mathbf{u}>0\), so \(\mathbf{q}_1\) is defined. Write \(c=(\mathbf{u}\cdot\mathbf{v})/(\mathbf{u}\cdot\mathbf{u})\). From the definition of \(\mathbf{w}_2\) and the linearity of the dot product over \(\mathbb{R}\),
If \(\mathbf{w}_2=\mathbf{0}\), then \(\mathbf{v}=c\mathbf{u}\), contradicting the assumed independence. Thus \(\mathbf{w}_2\ne\mathbf{0}\), and \(\mathbf{q}_2\) is defined. The normalizations give \(\|\mathbf{q}_1\|=\|\mathbf{u}\|/\|\mathbf{u}\|=1\) and \(\|\mathbf{q}_2\|=\|\mathbf{w}_2\|/\|\mathbf{w}_2\|=1\). Finally, since \(\mathbf{q}_1=\mathbf{u}/\|\mathbf{u}\|\) and \(\mathbf{q}_2=\mathbf{w}_2/\|\mathbf{w}_2\|\),
Both vectors have unit length and are orthogonal, so the output is an orthonormal pair. \(\square\)
The calculation also keeps the same span, meaning the set of all linear combinations of the two vectors. This is useful because the orthonormal pair is easier to work with, while still describing the same plane through the origin.
Proof. The definition gives \(\mathbf{q}_1=\mathbf{u}/\|\mathbf{u}\|\), so \(\mathbf{q}_1\) is a scalar multiple of \(\mathbf{u}\). Also, \(\mathbf{w}_2=\mathbf{v}-c\mathbf{u}\), so \(\mathbf{w}_2\) is a linear combination of \(\mathbf{u}\) and \(\mathbf{v}\); because \(\mathbf{q}_2=\mathbf{w}_2/\|\mathbf{w}_2\|\), both \(\mathbf{q}_1,\mathbf{q}_2\) belong to \(\operatorname{span}\{\mathbf{u},\mathbf{v}\}\). This proves \(\operatorname{span}\{\mathbf{q}_1,\mathbf{q}_2\}\subseteq\operatorname{span}\{\mathbf{u},\mathbf{v}\}\). For the reverse inclusion, \(\mathbf{u}=\|\mathbf{u}\|\mathbf{q}_1\), and rearranging \(\mathbf{w}_2=\mathbf{v}-c\mathbf{u}\) gives \(\mathbf{v}=\mathbf{w}_2+c\mathbf{u}=\|\mathbf{w}_2\|\mathbf{q}_2+c\|\mathbf{u}\|\mathbf{q}_1\). Hence both \(\mathbf{u}\) and \(\mathbf{v}\) belong to \(\operatorname{span}\{\mathbf{q}_1,\mathbf{q}_2\}\). This proves the reverse inclusion and therefore equality. \(\square\)
Worked Calculations in \(\mathbb{R}^3\)
Worked Example: A Half-Integer Projection
Apply Gram-Schmidt to \(\mathbf{u}=(1,1,0)^{\top}\) and \(\mathbf{v}=(1,0,1)^{\top}\). First check independence: if \(\mathbf{v}=c\mathbf{u}\), then the third coordinate of \(\mathbf{v}\) would be \(0\), but it is \(1\). Thus the vectors are independent.
Compute the first norm and normalize:
The inner product of the inputs is \(\mathbf{u}\cdot\mathbf{v}=1\cdot1+1\cdot0+0\cdot1=1\). Therefore the projection coefficient is \(1/2\), and subtracting the corresponding multiple of \(\mathbf{u}\) gives
Its squared norm is \(\frac14+\frac14+1=\frac32\), so \(\|\mathbf{w}_2\|=\frac{\sqrt{6}}{2}\). Normalizing yields
Check: The squared length of \(\mathbf{q}_2\) is \((1+1+4)/6=1\), and \(\mathbf{q}_1\cdot\mathbf{q}_2=(1-1+0)/\sqrt{12}=0\). Also \(\|\mathbf{q}_1\|^2=(1+1)/2=1\). The pair is orthonormal.
Worked Example: A Nontrivial Integer Residual
Use \(\mathbf{u}=(1,2,2)^{\top}\) and \(\mathbf{v}=(2,1,0)^{\top}\). These vectors are independent: if \(\mathbf{v}=c\mathbf{u}\), the third coordinate would give \(0=2c\), hence \(c=0\), which would force \(\mathbf{v}=\mathbf{0}\), a contradiction.
First, \(\mathbf{u}\cdot\mathbf{u}=1+4+4=9\), so \(\|\mathbf{u}\|=3\) and \(\mathbf{q}_1=(1,2,2)^{\top}/3\). Next, \(\mathbf{u}\cdot\mathbf{v}=1\cdot2+2\cdot1+2\cdot0=4\), giving projection coefficient \(4/9\). The residual is
The integer vector in the final expression has squared norm \(14^2+1^2+(-8)^2=196+1+64=261=9\cdot29\). Hence \(\|\mathbf{w}_2\|=\sqrt{261}/9=\sqrt{29}/3\), and
Check: The squared norm of \(\mathbf{q}_2\) is \(261/(9\cdot29)=1\). The first vector also has squared norm \(9/9=1\), and their dot product is \((14+2-16)/(9\sqrt{29})=0\). Thus the result is orthonormal. The subtraction is also recoverable: \(\mathbf{v}=\mathbf{w}_2+\frac49\mathbf{u}\), confirming that the component removed was exactly restored.
Worked Example: Inputs That Are Already Orthogonal
Take \(\mathbf{u}=(2,-1,2)^{\top}\) and \(\mathbf{v}=(1,2,0)^{\top}\). Their dot product is \(2-2+0=0\), so the projection coefficient is zero. They are independent because neither is a scalar multiple of the other; for example, their third coordinates are \(2\) and \(0\), but the second coordinate of \(\mathbf{v}\) is nonzero.
For the first vector, \(\mathbf{u}\cdot\mathbf{u}=4+1+4=9\), so \(\mathbf{q}_1=(2,-1,2)^{\top}/3\). For the second, \(\mathbf{v}\cdot\mathbf{v}=1+4+0=5\), so \(\|\mathbf{v}\|=\sqrt{5}\). Since the projection coefficient vanishes, \(\mathbf{w}_2=\mathbf{v}-0\mathbf{u}=\mathbf{v}\), and therefore
Check: \(\|\mathbf{q}_1\|^2=(4+1+4)/9=1\), \(\|\mathbf{q}_2\|^2=(1+4)/5=1\), and \(\mathbf{q}_1\cdot\mathbf{q}_2=(2-2+0)/(3\sqrt{5})=0\). This case shows that Gram-Schmidt does not alter the second input when it is already perpendicular to the first.
A Reliable Order of Operations
For a new pair, keep the stages distinct. Compute inner products and squared norms before taking square roots; then subtract the projection; only after that compute the residual’s norm. This prevents mixing the coefficient used for projection with the factor used for normalization.
Calculate \(\mathbf{u}\cdot\mathbf{u}\), take its positive square root, and set \(\mathbf{q}_1=\mathbf{u}/\|\mathbf{u}\|\).
Calculate \(\mathbf{u}\cdot\mathbf{v}\) and divide by \(\mathbf{u}\cdot\mathbf{u}\). The denominator is the squared norm of the direction being projected onto.
Form \(\mathbf{w}_2=\mathbf{v}-\frac{\mathbf{u}\cdot\mathbf{v}}{\mathbf{u}\cdot\mathbf{u}}\mathbf{u}\), compute \(\|\mathbf{w}_2\|\), and divide \(\mathbf{w}_2\) by that norm.
Check separately that \(\mathbf{q}_1\cdot\mathbf{q}_1=1\), \(\mathbf{q}_2\cdot\mathbf{q}_2=1\), and \(\mathbf{q}_1\cdot\mathbf{q}_2=0\).
The independence assumption is essential: if \(\mathbf{u}\ne\mathbf{0}\) and the inputs are dependent, then \(\mathbf{v}=c\mathbf{u}\) for some scalar \(c\), so the residual is zero and cannot be normalized. If \(\mathbf{u}=\mathbf{0}\), the projection formula is already undefined. In the independent case treated here, the theorem proves that the residual is nonzero. A useful direct check during a calculation is \(\mathbf{u}\cdot\mathbf{w}_2=0\) before normalization. If it fails, the projection coefficient or subtraction has an error.
Common Pitfall: Omitting the Squared Norm
A frequent incorrect projection formula is \((\mathbf{u}\cdot\mathbf{v})\mathbf{u}\), with the denominator \(\mathbf{u}\cdot\mathbf{u}\) omitted. For \(\mathbf{u}=(1,1,0)^{\top}\) and \(\mathbf{v}=(1,0,1)^{\top}\), this would subtract \(\mathbf{u}\) and produce the wrong residual \((0,-1,1)^{\top}\). Its dot product with \(\mathbf{u}\) is \(0-1+0=-1\), so it is not perpendicular to \(\mathbf{u}\). The correct coefficient is \((\mathbf{u}\cdot\mathbf{v})/(\mathbf{u}\cdot\mathbf{u})=1/2\), producing \((1/2,-1/2,1)^{\top}\), whose dot product with \(\mathbf{u}\) is \(1/2-1/2+0=0\).
Another check worth making is that normalization uses the norm, not the squared norm: divide \(\mathbf{w}_2\) by \(\sqrt{\mathbf{w}_2\cdot\mathbf{w}_2}\). Dividing by \(\mathbf{w}_2\cdot\mathbf{w}_2\) generally does not produce a unit vector. A final verification of both lengths and the dot product catches this error even when the subtraction was correct.
Check Your Understanding
For each calculation, keep the projection, residual, and normalization steps separate; verify the final pair by direct inner products.
- Apply Gram-Schmidt to \((1,0,1)^{\top}\) and \((1,1,0)^{\top}\). What are the projection coefficient and the residual?
- Explain why the residual cannot be zero when the two input vectors are linearly independent.
- For \(\mathbf{u}=(1,2,0)^{\top}\) and \(\mathbf{v}=(2,0,1)^{\top}\), calculate \(\mathbf{q}_1\), \(\mathbf{w}_2\), and \(\mathbf{q}_2\).
- For \(\mathbf{u}=(1,1,0)^{\top}\), \(\mathbf{v}=(1,0,1)^{\top}\), show that subtracting \((\mathbf{u}\cdot\mathbf{v})\mathbf{u}\) fails the orthogonality check.
- In one sentence, explain why normalization of a nonzero residual does not change its perpendicular direction.