Tutorials › Linear Algebra › A Two-Vector Gram-Schmidt Calculation in R3

Orthogonal Sets and Gram-Schmidt · Tutorial 640 of 1000

A Two-Vector Gram-Schmidt Calculation in R3

Learn how to turn two independent vectors in \(\mathbb{R}^3\) into an orthonormal pair by computing and checking each Gram-Schmidt step.

Intermediate 9 min read

What You'll Learn

  • Compute the projection coefficient using the inner product and squared norm.
  • Subtract the first vector’s component from the second vector.
  • Normalize each vector to produce an orthonormal pair.
  • Verify orthogonality and unit lengths by direct calculation.
  • Identify why independence ensures the second residual is nonzero.
  • Avoid common errors in the projection and normalization steps.

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.

Definition (Two-vector Gram-Schmidt calculation): For independent \(\mathbf{u},\mathbf{v}\in\mathbb{R}^3\), define \(\mathbf{q}_1=\mathbf{u}/\|\mathbf{u}\|\), then subtract from \(\mathbf{v}\) its projection onto \(\mathbf{u}\): \(\mathbf{w}_2=\mathbf{v}-\frac{\mathbf{u}\cdot\mathbf{v}}{\mathbf{u}\cdot\mathbf{u}}\mathbf{u}\). Finally set \(\mathbf{q}_2=\mathbf{w}_2/\|\mathbf{w}_2\|\). The output is the ordered pair \((\mathbf{q}_1,\mathbf{q}_2)\).

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

Theorem: Let \(\mathbf{u},\mathbf{v}\in\mathbb{R}^3\) be linearly independent. The two-vector Gram-Schmidt calculation is defined and produces an orthonormal pair \((\mathbf{q}_1,\mathbf{q}_2)\).

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}\),

$$ \mathbf{u}\cdot\mathbf{w}_2 =\mathbf{u}\cdot(\mathbf{v}-c\mathbf{u}) =\mathbf{u}\cdot\mathbf{v}-c(\mathbf{u}\cdot\mathbf{u}) =0. $$

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\|\),

$$ \mathbf{q}_1\cdot\mathbf{q}_2 =\frac{\mathbf{u}\cdot\mathbf{w}_2}{\|\mathbf{u}\|\|\mathbf{w}_2\|} =0. $$

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.

Proposition: Under the same independence assumption, \(\operatorname{span}\{\mathbf{u},\mathbf{v}\}=\operatorname{span}\{\mathbf{q}_1,\mathbf{q}_2\}\).

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:

$$ \mathbf{u}\cdot\mathbf{u}=1^2+1^2+0^2=2, \qquad \|\mathbf{u}\|=\sqrt{2}, \qquad \mathbf{q}_1=\frac{1}{\sqrt{2}} \begin{bmatrix}1\\1\\0\end{bmatrix}. $$

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

$$ \mathbf{w}_2 =\begin{bmatrix}1\\0\\1\end{bmatrix} -\frac12\begin{bmatrix}1\\1\\0\end{bmatrix} =\begin{bmatrix}\frac12\\-\frac12\\1\end{bmatrix}. $$

Its squared norm is \(\frac14+\frac14+1=\frac32\), so \(\|\mathbf{w}_2\|=\frac{\sqrt{6}}{2}\). Normalizing yields

$$ \mathbf{q}_2 =\frac{1}{\sqrt{6}} \begin{bmatrix}1\\-1\\2\end{bmatrix}. $$

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

$$ \mathbf{w}_2 =\begin{bmatrix}2\\1\\0\end{bmatrix} -\frac49\begin{bmatrix}1\\2\\2\end{bmatrix} =\begin{bmatrix}\frac{14}{9}\\\frac19\\-\frac89\end{bmatrix} =\frac19\begin{bmatrix}14\\1\\-8\end{bmatrix}. $$

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

$$ \mathbf{q}_2 =\frac{1}{3\sqrt{29}} \begin{bmatrix}14\\1\\-8\end{bmatrix}. $$

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

$$ \mathbf{q}_2=\frac{1}{\sqrt{5}}\begin{bmatrix}1\\2\\0\end{bmatrix}. $$

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.

1
Normalize the first input.
Calculate \(\mathbf{u}\cdot\mathbf{u}\), take its positive square root, and set \(\mathbf{q}_1=\mathbf{u}/\|\mathbf{u}\|\).
2
Find the projection coefficient.
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.
3
Subtract and normalize the residual.
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.
4
Verify the output.
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.

  1. Apply Gram-Schmidt to \((1,0,1)^{\top}\) and \((1,1,0)^{\top}\). What are the projection coefficient and the residual?
  2. Explain why the residual cannot be zero when the two input vectors are linearly independent.
  3. 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\).
  4. 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.
  5. In one sentence, explain why normalization of a nonzero residual does not change its perpendicular direction.

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon