Tutorials › Linear Algebra › Gram-Schmidt in R4 with Rational Inputs

Orthogonal Sets and Gram-Schmidt · Tutorial 642 of 1000

Gram-Schmidt in R4 with Rational Inputs

Learn to apply Gram–Schmidt to rational vectors in \(\mathbb{R}^4\), track exact radicals through normalization, and verify each orthonormal output.

Intermediate 10 min read

What You'll Learn

  • Write the Gram–Schmidt residual using inner products with the previously normalized vectors.
  • Preserve exact fractions and radicals in four-dimensional calculations.
  • Normalize residuals by computing their norms from the coordinates.
  • Verify orthogonality and reconstruct the original vectors from the output.
  • Recognize when a zero residual means the calculation cannot add a new orthonormal vector.

From Rational Inputs to Orthonormal Vectors

Gram–Schmidt starts with a linearly independent list and replaces it with an orthonormal list that spans the same subspace. In \(\mathbb{R}^4\), each input and each residual has four coordinates, but the calculation follows the same principle at every step: remove the components in directions already constructed, then normalize what remains. Rational input coordinates do not guarantee rational normalized vectors. Norms can introduce square roots, so keeping exact fractions and radicals throughout is essential.

Throughout this tutorial the scalar field is \(\mathbb{R}\), and the inner product is the dot product \(\mathbf{x}\cdot\mathbf{y}=\mathbf{x}^{\top}\mathbf{y}\). The norm is \(\|\mathbf{x}\|=\sqrt{\mathbf{x}\cdot\mathbf{x}}\). Vectors in \(\mathbb{R}^4\) are columns. A list is orthogonal if distinct vectors have dot product zero; it is orthonormal if it is orthogonal and every vector has norm \(1\).

Definition: Given an independent ordered list \((\mathbf{x}_1,\dots,\mathbf{x}_p)\) in \(\mathbb{R}^4\), Gram–Schmidt constructs residuals \(\mathbf{u}_k\) and normalized vectors \(\mathbf{e}_k\) in order. Set \(\mathbf{u}_1=\mathbf{x}_1\) and \(\mathbf{e}_1=\mathbf{u}_1/\|\mathbf{u}_1\|\). For \(k\ge2\), set $$ \mathbf{u}_k=\mathbf{x}_k-\sum_{j=1}^{k-1}(\mathbf{x}_k\cdot\mathbf{e}_j)\mathbf{e}_j, \qquad \mathbf{e}_k=\frac{\mathbf{u}_k}{\|\mathbf{u}_k\|}. $$ The normalization step requires \(\mathbf{u}_k\ne\mathbf{0}\). For an independent input list, the residuals in this construction are nonzero.

Each coefficient \(\mathbf{x}_k\cdot\mathbf{e}_j\) measures the component of the current input in the direction of a previously constructed unit vector. The earlier material on coefficients along an orthonormal list gives this coefficient rule. The calculation below also shows directly why the chosen coefficients remove those components.

Proposition: Suppose \(\mathbf{e}_1,\dots,\mathbf{e}_{k-1}\) are orthonormal in \(\mathbb{R}^4\). The unique vector of the form \(\mathbf{x}-\sum_{i=1}^{k-1}a_i\mathbf{e}_i\) that is perpendicular to every \(\mathbf{e}_j\) is obtained by taking \(a_j=\mathbf{x}\cdot\mathbf{e}_j\) for every \(j\).

Proof. To make \(\mathbf{x}-\sum_{i=1}^{k-1}a_i\mathbf{e}_i\) perpendicular to \(\mathbf{e}_j\), its dot product with \(\mathbf{e}_j\) must be zero. Orthonormality gives $$ \left(\mathbf{x}-\sum_{i=1}^{k-1}a_i\mathbf{e}_i\right)\cdot\mathbf{e}_j =\mathbf{x}\cdot\mathbf{e}_j-\sum_{i=1}^{k-1}a_i(\mathbf{e}_i\cdot\mathbf{e}_j) =\mathbf{x}\cdot\mathbf{e}_j-a_j. $$ Thus perpendicularity requires \(a_j=\mathbf{x}\cdot\mathbf{e}_j\). This choice works for every \(j\), and each coefficient is forced by its equation, proving uniqueness. \(\square\)

This proposition justifies the subtraction at each stage: it removes precisely the components along the earlier unit vectors. If the resulting residual is nonzero, dividing by its norm makes it a unit vector without changing its direction. If it is zero, there is no direction left to normalize.

A Four-Vector Calculation in \(\mathbb{R}^4\)

Worked Example: Four Rational Inputs

Apply Gram–Schmidt to the following list, keeping all quantities exact: $$ \mathbf{x}_1=\begin{bmatrix}1\\1\\0\\0\end{bmatrix},\quad \mathbf{x}_2=\begin{bmatrix}2\\0\\2\\0\end{bmatrix},\quad \mathbf{x}_3=\begin{bmatrix}4\\-2\\3\\0\end{bmatrix},\quad \mathbf{x}_4=\begin{bmatrix}1\\1\\-3\\1\end{bmatrix}. $$

For the first vector, the residual is \(\mathbf{u}_1=\mathbf{x}_1\). Its squared norm is \(1^2+1^2=2\), so \(\|\mathbf{u}_1\|=\sqrt{2}\) and $$ \mathbf{e}_1=\frac{1}{\sqrt{2}}\begin{bmatrix}1\\1\\0\\0\end{bmatrix}. $$

For the second vector, its coefficient along \(\mathbf{e}_1\) is \(\mathbf{x}_2\cdot\mathbf{e}_1=2/\sqrt{2}=\sqrt{2}\). Therefore $$ \mathbf{u}_2=\mathbf{x}_2-\sqrt{2}\mathbf{e}_1 =\begin{bmatrix}2\\0\\2\\0\end{bmatrix} -\begin{bmatrix}1\\1\\0\\0\end{bmatrix} =\begin{bmatrix}1\\-1\\2\\0\end{bmatrix}. $$ Its squared norm is \(1+1+4=6\), hence $$ \mathbf{e}_2=\frac{1}{\sqrt{6}}\begin{bmatrix}1\\-1\\2\\0\end{bmatrix}. $$

For \(\mathbf{x}_3\), the two coefficients are $$ \mathbf{x}_3\cdot\mathbf{e}_1=\frac{4-2}{\sqrt{2}}=\sqrt{2}, \qquad \mathbf{x}_3\cdot\mathbf{e}_2=\frac{4+2+6}{\sqrt{6}}=2\sqrt{6}. $$ The corresponding components are \(\sqrt{2}\mathbf{e}_1=(1,1,0,0)^{\top}\) and \(2\sqrt{6}\mathbf{e}_2=(2,-2,4,0)^{\top}\). Subtracting both gives $$ \mathbf{u}_3= \begin{bmatrix}4\\-2\\3\\0\end{bmatrix} -\begin{bmatrix}1\\1\\0\\0\end{bmatrix} -\begin{bmatrix}2\\-2\\4\\0\end{bmatrix} =\begin{bmatrix}1\\-1\\-1\\0\end{bmatrix}. $$ Its squared norm is \(1+1+1=3\), so $$ \mathbf{e}_3=\frac{1}{\sqrt{3}}\begin{bmatrix}1\\-1\\-1\\0\end{bmatrix}. $$

For the last vector, calculate all three coefficients before subtracting: $$ \mathbf{x}_4\cdot\mathbf{e}_1=\frac{1+1}{\sqrt{2}}=\sqrt{2},\quad \mathbf{x}_4\cdot\mathbf{e}_2=\frac{1-1-6}{\sqrt{6}}=-\sqrt{6},\quad \mathbf{x}_4\cdot\mathbf{e}_3=\frac{1-1+3}{\sqrt{3}}=\sqrt{3}. $$ Their components are respectively \((1,1,0,0)^{\top}\), \((-1,1,-2,0)^{\top}\), and \((1,-1,-1,0)^{\top}\). Thus $$ \mathbf{u}_4= \begin{bmatrix}1\\1\\-3\\1\end{bmatrix} -\begin{bmatrix}1\\1\\0\\0\end{bmatrix} -\begin{bmatrix}-1\\1\\-2\\0\end{bmatrix} -\begin{bmatrix}1\\-1\\-1\\0\end{bmatrix} =\begin{bmatrix}0\\0\\0\\1\end{bmatrix}. $$ Its norm is \(1\), so \(\mathbf{e}_4=(0,0,0,1)^{\top}\).

Check. The residuals are mutually perpendicular: their pairwise dot products are \(\mathbf{u}_1\cdot\mathbf{u}_2=1-1=0\), \(\mathbf{u}_1\cdot\mathbf{u}_3=1-1=0\), \(\mathbf{u}_2\cdot\mathbf{u}_3=1+1-2=0\), and each of \(\mathbf{u}_1,\mathbf{u}_2,\mathbf{u}_3\) has fourth coordinate zero, so it is perpendicular to \(\mathbf{u}_4\). Dividing by nonzero norms preserves these zero dot products, and the displayed norms show that every \(\mathbf{e}_i\) has norm \(1\). Reconstruction also checks each subtraction: \(\mathbf{x}_1=\mathbf{u}_1\), \(\mathbf{x}_2=\mathbf{u}_1+\mathbf{u}_2\), \(\mathbf{x}_3=\mathbf{u}_1+2\mathbf{u}_2+\mathbf{u}_3\), and \(\mathbf{x}_4=\mathbf{u}_1-\mathbf{u}_2+\mathbf{u}_3+\mathbf{u}_4\).

The input list is independent. Indeed, the four residual directions are nonzero and mutually orthogonal, hence independent by the earlier result on orthogonal nonzero vectors. The displayed reconstruction relations express the inputs from the residuals by a triangular system with diagonal coefficients \(1\); successively comparing the \(\mathbf{u}_4,\mathbf{u}_3,\mathbf{u}_2,\mathbf{u}_1\) coefficients shows that a zero linear combination of the inputs must have all coefficients zero.

Two and Three Inputs: The Same Exact Steps

Worked Example: A Two-Vector List with Fractions

Apply Gram–Schmidt to \(\mathbf{x}_1=(1,1,1,1)^{\top}\) and \(\mathbf{x}_2=(1,0,0,0)^{\top}\). The first norm is \(\sqrt{4}=2\), so $$ \mathbf{e}_1=\frac12\begin{bmatrix}1\\1\\1\\1\end{bmatrix}. $$ The coefficient for the second input is \(\mathbf{x}_2\cdot\mathbf{e}_1=\tfrac12\). Hence $$ \mathbf{u}_2= \begin{bmatrix}1\\0\\0\\0\end{bmatrix} -\frac12\mathbf{e}_1 = \begin{bmatrix}1\\0\\0\\0\end{bmatrix} -\begin{bmatrix}1/4\\1/4\\1/4\\1/4\end{bmatrix} = \begin{bmatrix}3/4\\-1/4\\-1/4\\-1/4\end{bmatrix}. $$ The squared norm is \((9+1+1+1)/16=3/4\), so \(\|\mathbf{u}_2\|=\sqrt{3}/2\), and $$ \mathbf{e}_2=\frac{1}{2\sqrt{3}}\begin{bmatrix}3\\-1\\-1\\-1\end{bmatrix}. $$

Check. The dot product of the two unit vectors is \((3-1-1-1)/(4\sqrt{3})=0\), and \(\|\mathbf{e}_2\|^2=(9+1+1+1)/12=1\). Also \(\tfrac12\mathbf{e}_1+\tfrac{\sqrt{3}}2\mathbf{e}_2=(1,0,0,0)^{\top}=\mathbf{x}_2\), confirming the decomposition. The inputs are independent: in \(c_1\mathbf{x}_1+c_2\mathbf{x}_2=\mathbf{0}\), the second coordinate forces \(c_1=0\), and then the first forces \(c_2=0\).

Worked Example: Three Inputs with a Simple Final Residual

Take \(\mathbf{y}_1=(1,0,0,0)^{\top}\), \(\mathbf{y}_2=(1,1,0,0)^{\top}\), and \(\mathbf{y}_3=(1,1,1,1)^{\top}\). The first vector is already a unit vector, so \(\mathbf{e}_1=(1,0,0,0)^{\top}\). The second coefficient is \(\mathbf{y}_2\cdot\mathbf{e}_1=1\), giving $$ \mathbf{u}_2=\mathbf{y}_2-\mathbf{e}_1 =\begin{bmatrix}0\\1\\0\\0\end{bmatrix}, \qquad \mathbf{e}_2=\begin{bmatrix}0\\1\\0\\0\end{bmatrix}. $$ For \(\mathbf{y}_3\), the coefficients along \(\mathbf{e}_1,\mathbf{e}_2\) are both \(1\). Therefore $$ \mathbf{u}_3=\mathbf{y}_3-\mathbf{e}_1-\mathbf{e}_2 =\begin{bmatrix}0\\0\\1\\1\end{bmatrix}, \qquad \|\mathbf{u}_3\|=\sqrt{2}, \qquad \mathbf{e}_3=\frac{1}{\sqrt{2}}\begin{bmatrix}0\\0\\1\\1\end{bmatrix}. $$

Check. The first two vectors are coordinate directions, so each is perpendicular to \(\mathbf{u}_3\) and to the other. The norm of \(\mathbf{e}_3\) is \(\sqrt{(1+1)/2}=1\). Finally, \(\mathbf{y}_3=\mathbf{e}_1+\mathbf{e}_2+\sqrt{2}\mathbf{e}_3\), while \(\mathbf{y}_2=\mathbf{e}_1+\mathbf{e}_2\) and \(\mathbf{y}_1=\mathbf{e}_1\); these equations verify the construction.

Keeping the Arithmetic Reliable

For exact calculations, keep each residual as an unnormalized vector until its coordinates have been checked. Its norm is computed from the sum of the squares of those coordinates. Only then divide by that norm. This order makes it easier to distinguish a coefficient error in the subtraction from an arithmetic error in the square root.

Common mistake: confusing a squared norm with a norm. In the four-vector example, \(\mathbf{u}_3=(1,-1,-1,0)^{\top}\). A wrong normalization is \(\mathbf{u}_3/3\), because \(3\) is the sum of its squared coordinates. But \(\|\mathbf{u}_3\|=\sqrt{3}\), not \(3\), and the incorrect vector has squared norm \(3/9=1/3\), so it is not a unit vector. The correct normalization is \(\mathbf{u}_3/\sqrt{3}\), whose squared norm is \(3/3=1\).

There are two checks worth making after every step. First, test the new residual against each earlier unit vector by taking dot products; every result should be zero. Second, check that its normalized version has squared norm \(1\). At the end, reconstruct each original input from its residual components. A mistaken sign or omitted component will often be detected by one of these checks.

A zero residual has a precise meaning: the current input was entirely accounted for by the earlier directions, so it contributes no new orthogonal direction. The normalization formula then cannot be used because division by \(\|\mathbf{0}\|=0\) is undefined. For an independent input list this does not occur; for a list that is not independent, a zero residual signals that the list has supplied a redundant vector.

Check Your Understanding

For each calculation, keep fractions and radicals exact, then check orthogonality and norms.

  1. Starting with \(\mathbf{a}_1=(1,1,0,0)^{\top}\) and \(\mathbf{a}_2=(1,0,1,0)^{\top}\), find the second Gram–Schmidt residual and its normalized vector.
  2. For \(\mathbf{b}_1=(1,0,0,0)^{\top}\), \(\mathbf{b}_2=(1,1,1,0)^{\top}\), compute the projection coefficient and the second residual.
  3. Explain why \((1,0,0,0)^{\top},(0,1,0,0)^{\top},(1,1,0,0)^{\top}\) produce a zero residual at the third step.
  4. If a residual is \((2,-1,2,0)^{\top}\), compute its norm and its normalized vector.
  5. State two exact checks that can be used to catch errors in a Gram–Schmidt calculation.

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