Tutorials › Linear Algebra › A Gram-Schmidt Workshop with Exact and Polynomial Examples

Orthogonal Sets and Gram-Schmidt · Tutorial 655 of 1000

A Gram-Schmidt Workshop with Exact and Polynomial Examples

Apply Gram–Schmidt step by step to coordinate and polynomial examples, checking the outputs and the span they preserve.

Intermediate 11 min read

What You'll Learn

  • Apply the real Gram–Schmidt recursion while keeping track of nonzero residuals.
  • Compute exact residuals and normalize them in a coordinate example.
  • Use an integral inner product to orthonormalize polynomials.
  • Verify orthogonality and unit norms directly.
  • Explain why the original list and the nonzero Gram–Schmidt outputs have the same span.
  • Recognize and correctly handle a zero residual.

Gram–Schmidt as a Complete Calculation

The Gram–Schmidt process takes an ordered list of vectors and produces an orthogonal list, or an orthonormal list if each nonzero output is normalized. The calculations have two things to keep track of: the projection coefficients at each step, and whether a residual is zero. These examples work through both details for vectors in \(\mathbb{R}^4\) and for polynomials. In each case, direct checks will confirm orthonormality and show that the process preserves the span.

All spaces and inner products in this tutorial are real. In \(\mathbb{R}^n\), use the dot product \(\langle\mathbf{u},\mathbf{v}\rangle=\mathbf{u}^{\top}\mathbf{v}\) and norm \(\|\mathbf{u}\|=\sqrt{\langle\mathbf{u},\mathbf{u}\rangle}\). For a nonzero vector \(\mathbf{q}\) of norm \(1\), the projection of \(\mathbf{v}\) onto \(\mathbf{q}\) is \(\langle\mathbf{v},\mathbf{q}\rangle\mathbf{q}\). Subtracting this projection removes the component in the \(\mathbf{q}\) direction.

Definition: Given an ordered list \(\mathbf{v}_1,\dots,\mathbf{v}_p\) in a real inner product space, construct residuals in order. At step \(k\), let \(J_{k-1}\) be the indices of the nonzero residuals among the first \(k-1\) inputs, and let \(\mathbf{q}_j=\mathbf{u}_j/\|\mathbf{u}_j\|\) for those indices. Set \(\mathbf{u}_k=\mathbf{v}_k-\sum_{j\in J_{k-1}}\langle\mathbf{v}_k,\mathbf{q}_j\rangle\mathbf{q}_j\). If \(\mathbf{u}_k\ne\mathbf{0}\), output the unit vector \(\mathbf{q}_k=\mathbf{u}_k/\|\mathbf{u}_k\|\) and add \(k\) to the index set. If \(\mathbf{u}_k=\mathbf{0}\), omit it and continue without defining \(\mathbf{q}_k\).

The index set in this definition is important: projections are taken only onto outputs that were actually produced. A zero residual has no normalized vector, so it cannot supply a direction for a later projection. When every residual is nonzero, the formula reduces to the familiar recursion that projects away from all earlier outputs.

Why the Process Produces Orthogonal Outputs and Preserves Span

Theorem: For any finite ordered list in a real inner product space, the nonzero outputs of the Gram–Schmidt process are orthonormal. After each step \(k\), the span of the first \(k\) inputs equals the span of the nonzero outputs produced through that step.

Proof. We proceed in order through the inputs. Before the first step there are no outputs, so the previous outputs are an orthonormal list and their span equals the span of the empty list, namely \(\{\mathbf{0}\}\). Suppose the outputs through step \(k-1\) are orthonormal and span the first \(k-1\) inputs. For each earlier output \(\mathbf{q}_i\), the residual at step \(k\) satisfies \[ \langle\mathbf{u}_k,\mathbf{q}_i\rangle =\langle\mathbf{v}_k,\mathbf{q}_i\rangle- \sum_{j\in J_{k-1}}\langle\mathbf{v}_k,\mathbf{q}_j\rangle\langle\mathbf{q}_j,\mathbf{q}_i\rangle =0, \] because orthonormality gives \(\langle\mathbf{q}_j,\mathbf{q}_i\rangle=1\) when \(j=i\) and \(0\) otherwise. If \(\mathbf{u}_k\ne\mathbf{0}\), then \(\mathbf{q}_k=\mathbf{u}_k/\|\mathbf{u}_k\|\) has norm \(1\) and is orthogonal to every earlier output. If \(\mathbf{u}_k=\mathbf{0}\), no output is added, so the earlier outputs remain orthonormal.

For the span statement, each earlier \(\mathbf{q}_j\) belongs to the span of the first \(k-1\) inputs by the induction hypothesis. Thus \(\mathbf{u}_k\), which is \(\mathbf{v}_k\) minus a combination of earlier outputs, belongs to the span of the first \(k\) inputs. Any new \(\mathbf{q}_k\) is a scalar multiple of \(\mathbf{u}_k\), so all outputs through step \(k\) belong to that input span. Conversely, rearranging the residual formula gives \(\mathbf{v}_k=\mathbf{u}_k+\sum_{j\in J_{k-1}}\langle\mathbf{v}_k,\mathbf{q}_j\rangle\mathbf{q}_j\). If the residual is zero, this expression still holds, with \(\mathbf{u}_k=\mathbf{0}\); if it is nonzero, it is a scalar multiple of the new output. In either case \(\mathbf{v}_k\) lies in the span of the outputs through step \(k\), and the earlier inputs already lie there by induction. The two spans are equal. \(\square\)

One useful consequence is that an independent input list has no zero residuals. Indeed, if \(\mathbf{u}_k=\mathbf{0}\), the residual formula expresses \(\mathbf{v}_k\) as a combination of earlier outputs. Those outputs lie in the span of earlier inputs, so \(\mathbf{v}_k\) is a combination of earlier inputs. That contradicts independence. This consequence does not say that every list produces a new output; a dependent list can produce a zero residual and then continue.

Worked Example in \(\mathbb{R}^4\)

Worked Example: Three Exact-Coordinate Vectors

Apply Gram–Schmidt to \(\mathbf{v}_1=\begin{bmatrix}1\\1\\0\\0\end{bmatrix}\), \(\mathbf{v}_2=\begin{bmatrix}1\\0\\1\\0\end{bmatrix}\), and \(\mathbf{v}_3=\begin{bmatrix}1\\1\\1\\1\end{bmatrix}\). Then check the outputs and compare their span with the span of the inputs.

The first residual is \(\mathbf{u}_1=\mathbf{v}_1\), with \(\|\mathbf{u}_1\|=\sqrt{1+1}=\sqrt{2}\). Therefore

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

For the second input, the projection coefficient is \(\langle\mathbf{v}_2,\mathbf{q}_1\rangle=(1+0)/\sqrt{2}=1/\sqrt{2}\). Consequently,

$$ \mathbf{u}_2 =\begin{bmatrix}1\\0\\1\\0\end{bmatrix} -\frac{1}{\sqrt{2}}\frac{1}{\sqrt{2}}\begin{bmatrix}1\\1\\0\\0\end{bmatrix} =\begin{bmatrix}\frac12\\-\frac12\\1\\0\end{bmatrix}. $$

Its squared norm is \(\frac14+\frac14+1=\frac32\), so \(\|\mathbf{u}_2\|=\sqrt{6}/2\). Normalizing gives \(\mathbf{q}_2=\frac{1}{\sqrt{6}}\begin{bmatrix}1\\-1\\2\\0\end{bmatrix}\). For the third input, the two projection coefficients are \(\langle\mathbf{v}_3,\mathbf{q}_1\rangle=2/\sqrt{2}=\sqrt{2}\) and \(\langle\mathbf{v}_3,\mathbf{q}_2\rangle=(1-1+2)/\sqrt{6}=2/\sqrt{6}\). Thus

$$ \begin{aligned} \mathbf{u}_3 &=\begin{bmatrix}1\\1\\1\\1\end{bmatrix} -\sqrt{2}\frac{1}{\sqrt{2}}\begin{bmatrix}1\\1\\0\\0\end{bmatrix} -\frac{2}{\sqrt{6}}\frac{1}{\sqrt{6}}\begin{bmatrix}1\\-1\\2\\0\end{bmatrix}\\ &=\begin{bmatrix}1\\1\\1\\1\end{bmatrix} -\begin{bmatrix}1\\1\\0\\0\end{bmatrix} -\begin{bmatrix}\frac13\\-\frac13\\\frac23\\0\end{bmatrix} =\begin{bmatrix}-\frac13\\\frac13\\\frac13\\1\end{bmatrix}. \end{aligned} $$

This calculation does not produce the particularly simple third output one might expect from these inputs; it is nonetheless valid. Its squared norm is \(\frac19+\frac19+\frac19+1=\frac43\), so \(\|\mathbf{u}_3\|=2/\sqrt{3}\) and \(\mathbf{q}_3=\frac{\sqrt{3}}{2}\begin{bmatrix}-\frac13\\\frac13\\\frac13\\1\end{bmatrix}\). Check orthogonality directly: \(\langle\mathbf{u}_3,\mathbf{q}_1\rangle=(-1/3+1/3)/\sqrt{2}=0\), and \(\langle\mathbf{u}_3,\mathbf{q}_2\rangle=(-1/3-1/3+2/3)/\sqrt{6}=0\). The norm calculations give \(\|\mathbf{q}_1\|=\|\mathbf{q}_2\|=\|\mathbf{q}_3\|=1\), so the outputs are orthonormal.

The span comparison can also be checked from the residual equations. We have \(\mathbf{v}_1=\mathbf{u}_1\), \(\mathbf{v}_2=\mathbf{u}_2+\frac12\mathbf{v}_1\), and \(\mathbf{v}_3=\mathbf{u}_3+\mathbf{v}_1+\frac13\begin{bmatrix}1\\-1\\2\\0\end{bmatrix} =\mathbf{u}_3+\mathbf{v}_1+\frac{2}{\sqrt{6}}\mathbf{q}_2\). Each input is in the span of the residuals, and each residual is a combination of the inputs and earlier outputs. Equivalently, the theorem shows that the inputs and outputs have the same span.

A Zero Residual Does Not Stop the Process

Worked Example: Skip a Redundant Input

Apply the process to \(\mathbf{v}_1=\begin{bmatrix}1\\0\\0\end{bmatrix}\), \(\mathbf{v}_2=\begin{bmatrix}2\\0\\0\end{bmatrix}\), and \(\mathbf{v}_3=\begin{bmatrix}0\\1\\0\end{bmatrix}\) in \(\mathbb{R}^3\).

The first output is \(\mathbf{q}_1=\begin{bmatrix}1\\0\\0\end{bmatrix}\). At step 2, the coefficient is \(\langle\mathbf{v}_2,\mathbf{q}_1\rangle=2\), so \(\mathbf{u}_2=\begin{bmatrix}2\\0\\0\end{bmatrix}-2\begin{bmatrix}1\\0\\0\end{bmatrix}=\mathbf{0}\). There is no \(\mathbf{q}_2\). The active output set still contains only \(\mathbf{q}_1\). At step 3, use that output: \(\langle\mathbf{v}_3,\mathbf{q}_1\rangle=0\), hence \(\mathbf{u}_3=\begin{bmatrix}0\\1\\0\end{bmatrix}\) and \(\mathbf{q}_3=\begin{bmatrix}0\\1\\0\end{bmatrix}\).

The outputs are orthonormal: each has squared norm \(1\), and their dot product is \(0\). The span is preserved because \(\mathbf{v}_2=2\mathbf{q}_1\), \(\mathbf{v}_1=\mathbf{q}_1\), and \(\mathbf{v}_3=\mathbf{q}_3\); thus both lists span the same plane. The zero residual records that the second input added no new direction, while the third input still contributes one.

A Polynomial Example with an Integral Inner Product

For polynomials on \([-1,1]\), use the real inner product \(\langle f,g\rangle=\int_{-1}^{1}f(x)g(x)\,dx\) and norm \(\|f\|=\sqrt{\langle f,f\rangle}\). Consider the ordered list \(1,x,x^2\) in the space of real polynomials of degree at most \(2\). The projection formula is unchanged; only the inner products are now integrals.

Worked Example: Orthonormalizing \(1,x,x^2\)

The first residual is \(u_1=1\), and \(\|u_1\|^2=\int_{-1}^1 1\,dx=2\). Thus \(q_1=1/\sqrt{2}\). Since \(\langle x,q_1\rangle=\frac{1}{\sqrt{2}}\int_{-1}^{1}x\,dx=0\), the second residual is \(u_2=x\). Its squared norm is \(\int_{-1}^{1}x^2\,dx=2/3\), so \(q_2=\sqrt{3/2}\,x\).

For \(x^2\), the coefficient along \(q_1\) is \(\langle x^2,q_1\rangle=(1/\sqrt{2})(2/3)=\sqrt{2}/3\). The coefficient along \(q_2\) is \(\langle x^2,q_2\rangle=\sqrt{3/2}\int_{-1}^{1}x^3\,dx=0\). Therefore \(u_3=x^2-\frac13\). Its squared norm is

$$ \begin{aligned} \|u_3\|^2 &=\int_{-1}^{1}\left(x^2-\frac13\right)^2\,dx\\ &=\int_{-1}^{1}\left(x^4-\frac23x^2+\frac19\right)\,dx\\ &=\frac25-\frac23\cdot\frac23+\frac29 =\frac25-\frac49+\frac29 =\frac{8}{45}. \end{aligned} $$

Hence \(q_3=\sqrt{45/8}\left(x^2-\frac13\right)\). To verify orthogonality before normalization, \(\langle u_3,q_1\rangle=(1/\sqrt{2})(2/3-2/3)=0\), and \(\langle u_3,q_2\rangle=\sqrt{3/2}\int_{-1}^{1}(x^3-x/3)\,dx=0\), since both terms are odd. The norms are \(1\) by construction: \(\|q_1\|^2=2/2=1\), \(\|q_2\|^2=(3/2)(2/3)=1\), and \(\|q_3\|^2=(45/8)(8/45)=1\). Thus the three polynomials are orthonormal.

For the span comparison, \(1=\sqrt{2}q_1\) and \(x=\sqrt{2/3}q_2\). Also, \(x^2=u_3+\frac13=\sqrt{8/45}q_3+\frac{\sqrt{2}}{3}q_1\). So each input polynomial is a combination of the outputs. Conversely, each output was constructed from the inputs, so the two lists span the same polynomial space.

Common Mistake: Use the Unit Vector in the Projection

The projection onto a unit vector \(\mathbf{q}\) is \(\langle\mathbf{v},\mathbf{q}\rangle\mathbf{q}\), not \(\langle\mathbf{v},\mathbf{q}\rangle\mathbf{v}_1\) when \(\mathbf{v}_1\) is the unnormalized earlier vector. In the first coordinate example, \(\langle\mathbf{v}_2,\mathbf{q}_1\rangle=1/\sqrt{2}\). An incorrect calculation would subtract \((1/\sqrt{2})\mathbf{v}_1\) and claim the residual is orthogonal to \(\mathbf{v}_1\). Its dot product with \(\mathbf{v}_1\) is \((1-1/\sqrt{2})+(-1/\sqrt{2})=1-\sqrt{2}\ne0\), so the claim fails. The correct projection is \((1/\sqrt{2})\mathbf{q}_1=\frac12\mathbf{v}_1\), giving \(\mathbf{u}_2=\begin{bmatrix}1/2\\-1/2\\1\\0\end{bmatrix}\), whose dot product with \(\mathbf{v}_1\) is \(1/2-1/2=0\).

Also distinguish an orthogonal list from an orthonormal one. Orthogonality requires distinct vectors to have inner product zero; orthonormality additionally requires every vector to have norm \(1\). Gram–Schmidt residuals are orthogonal, but they must be divided by their norms to obtain unit outputs. If a residual is zero, normalization is impossible, and that residual is omitted rather than treated as a new direction.

Check Your Understanding

For each question, include a direct check of the relevant residual, inner product, or span relation.

  1. Apply Gram–Schmidt to \(\begin{bmatrix}1\\0\\1\end{bmatrix}\) and \(\begin{bmatrix}1\\1\\0\end{bmatrix}\) in \(\mathbb{R}^3\). Give the normalized outputs.
  2. For the list \(\begin{bmatrix}1\\0\end{bmatrix},\begin{bmatrix}3\\0\end{bmatrix},\begin{bmatrix}0\\2\end{bmatrix}\), identify the zero residual and continue the process.
  3. Under \(\langle f,g\rangle=\int_{-1}^{1}f(x)g(x)\,dx\), compute the residual for \(x^2\) after orthogonalizing \(1\) and \(x\).
  4. Explain why a zero residual means that the corresponding input lies in the span of the preceding inputs.
  5. State which calculations verify orthonormality and which verify equality of the spans.

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