Orthogonality and the Gram-Schmidt Process

Orthogonality is the geometric backbone of every inner-product space. Once an inner product ⟨⋅,⋅⟩\langle\cdot,\cdot\rangle is fixed, two vectors are declared perpendicular the instant ⟨u,v⟩=0\langle u,v\rangle=0 — no picture of arrows required, just a number that vanishes. That single relation makes an orthonormal basis such a luxury: components become inner products, ci=⟨ei,v⟩c_i=\langle e_i,v\rangle; the norm becomes a sum of squares, Parseval's identity; expansions demand no matrix inversion. The Pythagorean theorem, Fourier series, the completeness relations of quantum mechanics, and least-squares fitting are all this idea in different clothes. The Gram-Schmidt process answers the constructive question that orthonormal bases raise: given an arbitrary linearly independent set, how do we actually build one spanning the same space? The recipe is disarmingly simple: take the vectors one at a time, at each stage subtract off the part already spanned by everything built so far (an orthogonal projection), then normalize what survives; linear independence guarantees that survivor is never zero, so the machine never stalls. What comes out is nested to match the inputs: the first kk outputs span exactly what the first kk inputs did — the algebraic content of the QRQR factorization. Run on the monomials 1,x,x2,…1,x,x^2,\dots, the same procedure manufactures the Legendre and Hermite polynomials that pervade mathematical physics.

Key takeaways
  • Two vectors are orthogonal when their inner product vanishes; an orthonormal set is mutually orthogonal with unit-length vectors, ⟨ei,ej⟩=δij\langle e_i,e_j\rangle=\delta_{ij}.
  • Orthonormal bases trivialize everything: components are inner products ci=⟨ei,v⟩c_i=\langle e_i,v\rangle, and the norm obeys Parseval, ∥v∥2=∑i∣ci∣2\lVert v\rVert^2=\sum_i|c_i|^2.
  • Gram-Schmidt turns any independent set into an orthonormal one spanning the same nested subspaces — subtract each vector's projection onto all earlier outputs, then normalize.
  • The remainder is orthogonal to the earlier vectors by construction and nonzero by linear independence, so the process is exact and never divides by zero.
  • As matrices the procedure is the factorization A=QRA=QR with RR upper triangular; the diagonal Rkk=∥uk∥R_{kk}=\lVert u_k\rVert and ∏kRkk2=det⁡G\prod_k R_{kk}^2=\det G, the squared volume.
  • Run on functions with different weights it generates the classical orthogonal polynomials — Legendre, Hermite, Laguerre — the working bases of quantum mechanics.
  • Key idea: at each step, subtract from the next vector its orthogonal projection onto everything constructed so far, then normalize the leftover — orthogonal to all earlier vectors by construction, nonzero by linear independence.
The core insight

At each step of Gram-Schmidt, subtract from the next vector its orthogonal projection onto everything already constructed, then normalize the leftover. That leftover is orthogonal to all earlier vectors by construction, and nonzero by linear independence — so the process is both exact and guaranteed to run to completion.

Where this lives today

Gram-Schmidt is quietly everywhere a computer solves a linear problem. Its matrix form, QRQR, is the workhorse of numerical linear algebra: LAPACK factors matrices this way (via Householder reflectors) to solve least-squares problems min⁡∥Ax−b∥\min\lVert Ax-b\rVert through Rx=Q†bRx=Q^{\dagger}b, sidestepping the ill-conditioned normal equations; iterated, the same factorization becomes the QRQR algorithm for eigenvalues. In large-scale computing the modified recursion is the beating heart of Krylov-subspace methods — Arnoldi and Lanczos, behind GMRES and conjugate gradients, orthogonalize each new basis vector against its predecessors exactly as Gram-Schmidt prescribes, and "communication-avoiding" and block variants keep that stable on exascale machines. In quantum chemistry the related Löwdin orthogonalization turns overlapping atomic orbitals into an orthonormal basis; in machine learning QRQR underlies regression and orthogonal weight initialization, and the Gram matrix reappears as the kernel of support-vector machines and Gaussian processes; even lattice cryptography's LLL reduction opens with a Gram-Schmidt step. A hand computation from 1883 now runs billions of times a second.

The physical picture

Picture building an orthogonal frame from a bundle of slanted measuring rods. Keep the first rod as your first axis — its direction is fine, only its length needs fixing. The second rod leans partly along the first, so shave off the component along axis one, and what remains sticks out perpendicular to it. For the third, shave off the two components already covered, and so on. Normalize each survivor and you have an orthonormal frame spanning the same directions as the original bundle. The "shaving off" is orthogonal projection, and the first figure freezes the decisive step: the projection of v2v_2 onto v1v_1, and the perpendicular remainder left behind.

Figure
Gram-Schmidt in the plane: subtract from v₂ its projection onto v₁ — coefficient ⟨v₁,v₂⟩/⟨v₁,v₁⟩ = 5/10 = ½ — leaving the remainder u₂ = v₂ − ½v₁ perpendicular to v₁, which you then normalize to the orthonormal pair e₁, e₂
Shave off the shadow of v₂ on v₁; the remainder u₂ is perpendicular to v₁ v₁ = (3, 1) v₂ = (1, 2) proj = ½ v₁ u₂ = v₂ − ½ v₁ coefficient ⟨v₁,v₂⟩ / ⟨v₁,v₁⟩ = 5 / 10 = ½ remainder u₂ = (−½, ³⁄₂), and v₁ · u₂ = 0 normalize: e₁ = v₁/√10, e₂ = u₂/√(5/2)

Why does the machine never fail? If a survivor were zero, that input would lie in the span of the earlier ones — precisely what linear independence forbids. So every remainder is nonzero and normalizable. The same picture holds for functions, where "angle" is an integral inner product ⟨f,g⟩=∫fg dx\langle f,g\rangle=\int f g\,\mathrm{d}x instead of a dot product. Feed Gram-Schmidt the monomials 1,x,x2,…1,x,x^2,\dots and it peels the lower-degree content off each power; what falls out, after the traditional rescaling, are the Legendre polynomials — the second figure shows the first three, mutually orthogonal on [−1,1][-1,1].

Figure
Gram-Schmidt on the monomials 1, x, x² over the interval from −1 to 1 yields the Legendre polynomials P₀ = 1, P₁ = x, P₂ = ½(3x² − 1), mutually orthogonal because the integral of Pᵢ Pⱼ over −1 to 1 vanishes whenever i ≠ j
The payoff: Gram-Schmidt on 1, x, x² makes the Legendre polynomials x −1 +1 0 +1 −1 P₀ = 1 P₁ = x P₂ = ½(3x² − 1) orthogonal on −1 ≤ x ≤ 1: ∫ Pᵢ Pⱼ dx = 0 for i ≠ j

The core equations

Everything begins with one scalar equation. Fix an inner product; orthogonality is nothing more than its vanishing — a condition needing no coordinates, identical for arrows, matrices, and functions.

⟨u,v⟩=0  ⟺  u⊥v(1)\langle u,v\rangle=0 \iff u\perp v \qquad (1)

where: ⟨u,v⟩\langle u,v\rangle — the inner product of uu and vv; ⊥\perp — the orthogonality relation. Reading: perpendicularity is a number that vanishes, not a picture — which lets the theory transplant from Rn\mathbb{R}^n to function spaces. An orthonormal set upgrades orthogonality with unit length, packaging both into one statement via the Kronecker delta — which makes it ideal to compute in.

⟨ei,ej⟩=δij(2)\langle e_i,e_j\rangle=\delta_{ij} \qquad (2)

where: eie_i — the ii-th basis vector; δij\delta_{ij} — the Kronecker delta, 11 when i=ji=j else 00. Reading: off-diagonal zeros are mutual orthogonality; the diagonal ones are unit normalization. The engine of Gram-Schmidt is the orthogonal projection — the piece of vv pointing along uu. The coefficient below makes the leftover v−projuvv-\mathrm{proj}_u v perpendicular to uu, as the first derivation proves.

projuv=⟨u,v⟩⟨u,u⟩ u(3)\mathrm{proj}_{u}v=\frac{\langle u,v\rangle}{\langle u,u\rangle}\,u \qquad (3)

where: projuv\mathrm{proj}_u v — the component of vv along uu; ⟨u,u⟩=∥u∥2\langle u,u\rangle=\lVert u\rVert^2 — the squared norm of uu. Reading: divide the overlap by the self-overlap for a ratio, then re-attach the direction uu. The recursion is the algorithm itself: process the inputs in order, and for each new one strip away its projections onto the remainders already built, then normalize what is left.

uk=vk−∑i=1k−1⟨ui,vk⟩⟨ui,ui⟩ ui,ek=uk∥uk∥(4)u_k=v_k-\sum_{i=1}^{k-1}\frac{\langle u_i,v_k\rangle}{\langle u_i,u_i\rangle}\,u_i,\qquad e_k=\frac{u_k}{\lVert u_k\rVert} \qquad (4)

where: vkv_k — the kk-th input; uku_k — the orthogonal remainder; eke_k — the kk-th orthonormal output. Reading: the sum removes everything already spanned; dividing by ∥uk∥\lVert u_k\rVert rescales the survivor to unit length. Once an orthonormal basis is in hand, every vector expands with no work: its components are its inner products with the basis vectors, no linear system to solve.

v=∑i⟨ei,v⟩ ei(5)v=\sum_{i}\langle e_i,v\rangle\,e_i \qquad (5)

where: ⟨ei,v⟩\langle e_i,v\rangle — the ii-th component, the generalized Fourier coefficient of vv. Reading: how much of eie_i is in vv is one inner product — no other component enters. Because the basis is orthonormal, the squared length of vv is the sum of squared components — the Pythagorean theorem in nn dimensions, in physics the statement that total probability or energy is a sum over modes.

∥v∥2=∑i∣⟨ei,v⟩∣2(6)\lVert v\rVert^2=\sum_i |\langle e_i,v\rangle|^2 \qquad (6)

where: ∥v∥\lVert v\rVert — the norm of vv; ∣⋅∣|\cdot| — modulus, since complex coefficients contribute ∣ci∣2|c_i|^2. Reading: dropping one component costs exactly its squared coefficient — the error bound behind every truncation. Collected into matrices, Gram-Schmidt is a factorization: stack inputs as columns of AA and outputs as columns of QQ, and the coefficients and remainder-lengths assemble into an upper-triangular RR.

A=QR,Q†Q=I,R upper triangular, Rkk>0(7)A=QR,\qquad Q^{\dagger}Q=I,\qquad R\ \text{upper triangular},\ R_{kk}>0 \qquad (7)

where: AA — columns are the vkv_k; QQ — columns are the orthonormal eke_k; RR — upper-triangular matrix of overlaps and norms. Reading: "upper triangular" is the algebraic echo of "each output uses only earlier inputs" — the nested-span property. Finally, the diagonal of RR carries a volume: the product of the remainder-lengths is the square root of the Gram determinant, the determinant of the pairwise-inner-product matrix — the nn-dimensional volume of the parallelepiped the inputs span.

det⁡G=det⁡(⟨vi,vj⟩)=∏k=1n∥uk∥2(8)\det G=\det\big(\langle v_i,v_j\rangle\big)=\prod_{k=1}^{n}\lVert u_k\rVert^2 \qquad (8)

where: GG — the Gram matrix, Gij=⟨vi,vj⟩G_{ij}=\langle v_i,v_j\rangle; ∥uk∥\lVert u_k\rVert — the kk-th remainder-length. Reading: det⁡G>0\det G>0 exactly when the vectors are independent — a coordinate-free independence test and volume formula at once.

Derivation AThe projection coefficient that makes the residual orthogonal

The goal is to pin down, from first principles, the one number in equation (3): to show that the coefficient ⟨u,v⟩/⟨u,u⟩\langle u,v\rangle/\langle u,u\rangle is the unique scalar leaving a residual perpendicular to uu, and simultaneously the scalar making αu\alpha u the closest point to vv on the line through uu. We derive it two independent ways — minimizing a distance, and demanding orthogonality — so "the projection is the nearest point" and "the residual is orthogonal" are revealed as one fact.

Step 1. Fix u≠0u\neq0 and ask which multiple αu\alpha u sits closest to vv: minimize the squared distance f(α)=⟨v−αu, v−αu⟩=∥v∥2−2α ⟨u,v⟩+α2∥u∥2f(\alpha)=\langle v-\alpha u,\,v-\alpha u\rangle=\lVert v\rVert^2-2\alpha\,\langle u,v\rangle+\alpha^2\lVert u\rVert^2 (real case; the complex case replaces ⟨u,v⟩\langle u,v\rangle by its real part, same stationary point). Why: "closest point on the line" is the honest meaning of projection, and a squared distance is a quadratic we can minimize exactly.

Step 2. Differentiate and set to zero: f′(α)=−2⟨u,v⟩+2α⟨u,u⟩=0f'(\alpha)=-2\langle u,v\rangle+2\alpha\langle u,u\rangle=0, so α=⟨u,v⟩/⟨u,u⟩\alpha=\langle u,v\rangle/\langle u,u\rangle; and f′′=2∥u∥2>0f''=2\lVert u\rVert^2>0 confirms a global minimum. Why: the positive second derivative certifies a nearest point, not a saddle — the projection genuinely minimizes the residual length.

Step 3. Derive the same α\alpha from orthogonality: demand the residual r=v−αur=v-\alpha u be perpendicular to uu, i.e. ⟨u,r⟩=⟨u,v⟩−α⟨u,u⟩=0\langle u,r\rangle=\langle u,v\rangle-\alpha\langle u,u\rangle=0, giving α=⟨u,v⟩/⟨u,u⟩\alpha=\langle u,v\rangle/\langle u,u\rangle again. Why: the identical coefficient from a different requirement proves "nearest point" and "orthogonal residual" are one condition — the geometric heart of the method.

Step 4. Read off projuv=⟨u,v⟩⟨u,u⟩u\mathrm{proj}_u v=\dfrac{\langle u,v\rangle}{\langle u,u\rangle}u with residual v−projuvv-\mathrm{proj}_u v now certified orthogonal to uu; for a unit vector this collapses to projev=⟨e,v⟩ e\mathrm{proj}_e v=\langle e,v\rangle\,e, the form used inside the recursion. Why: this is exactly the piece Gram-Schmidt subtracts at every step, so one step is proven correct before we chain them.

Go deeper · Derivation B · 1 minWhy the Gram-Schmidt output is genuinely orthonormal and never stalls
Derivation BWhy the Gram-Schmidt output is genuinely orthonormal and never stalls

The goal is to prove the two properties the method rests on: that each remainder uku_k is orthogonal to every earlier output, so the finished set is truly orthonormal, and that uku_k is never zero, so equation (4) never divides by zero. We argue by induction on kk, with the hypothesis that {e1,…,ek−1}\{e_1,\dots,e_{k-1}\} is orthonormal and spans the same subspace as {v1,…,vk−1}\{v_1,\dots,v_{k-1}\}, then test the new remainder against each earlier eje_j; the nonzero property follows from linear independence by contradiction.

Step 1. Write the remainder using the normalized earlier vectors (legitimate since they span the same space): uk=vk−∑i=1k−1⟨ei,vk⟩ eiu_k=v_k-\sum_{i=1}^{k-1}\langle e_i,v_k\rangle\,e_i, where ⟨ei,ei⟩=1\langle e_i,e_i\rangle=1 makes each coefficient simply ⟨ei,vk⟩\langle e_i,v_k\rangle. Why: working in the orthonormal eie_i makes the next inner product collapse cleanly through the Kronecker delta.

Step 2. Take the inner product with a fixed eje_j, j<kj<k, using linearity: ⟨ej,uk⟩=⟨ej,vk⟩−∑i=1k−1⟨ei,vk⟩ ⟨ej,ei⟩\langle e_j,u_k\rangle=\langle e_j,v_k\rangle-\sum_{i=1}^{k-1}\langle e_i,v_k\rangle\,\langle e_j,e_i\rangle. Why: orthogonality to the earlier block need only be tested against each eje_j, and linearity pushes the product through the sum.

Step 3. Apply the induction hypothesis ⟨ej,ei⟩=δji\langle e_j,e_i\rangle=\delta_{ji}; every term dies except i=ji=j, leaving ⟨ej,uk⟩=⟨ej,vk⟩−⟨ej,vk⟩=0\langle e_j,u_k\rangle=\langle e_j,v_k\rangle-\langle e_j,v_k\rangle=0 for all j<kj<k. Why: the subtracted projection removes exactly the eje_j-overlap of vkv_k, so it cancels itself — the whole trick, made precise.

Step 4. Suppose uk=0u_k=0. Then vk=∑i<k⟨ei,vk⟩eiv_k=\sum_{i<k}\langle e_i,v_k\rangle e_i lies in span(v1,…,vk−1)\mathrm{span}(v_1,\dots,v_{k-1}), making {v1,…,vk}\{v_1,\dots,v_k\} dependent — a contradiction. Hence ∥uk∥>0\lVert u_k\rVert>0 and ek=uk/∥uk∥e_k=u_k/\lVert u_k\rVert is well defined, orthogonal to the earlier eje_j by Step 3, completing the induction. Why: this is where linear independence earns its keep — the one hypothesis that forbids a zero remainder and keeps the algorithm alive to the last vector.

Go deeper · Derivation C · 1 minGram-Schmidt is the QR factorization, and its diagonal is a volume
Derivation CGram-Schmidt is the QR factorization, and its diagonal is a volume

The goal is to show that Gram-Schmidt, in matrix form, is exactly the factorization A=QRA=QR, and to extract the geometric meaning of RR: its diagonal entries are the successive remainder-lengths, and their product is the volume of the parallelepiped the inputs span, equal to the square root of the Gram determinant. We invert the recursion to express each input in the orthonormal basis, read the coefficients into a triangular matrix, and multiply the diagonal to recover det⁡G\det G — tying the algorithm to both least-squares and the geometry of volumes.

Step 1. Invert the recursion. Solving equation (4) for vkv_k writes each input from the outputs with index ≤k\le k: vk=∥uk∥ ek+∑i=1k−1⟨ei,vk⟩ ei=∑i=1kRikeiv_k=\lVert u_k\rVert\,e_k+\sum_{i=1}^{k-1}\langle e_i,v_k\rangle\,e_i=\sum_{i=1}^{k}R_{ik}e_i, with Rik=⟨ei,vk⟩R_{ik}=\langle e_i,v_k\rangle for i<ki<k and Rkk=∥uk∥R_{kk}=\lVert u_k\rVert. Why: since vkv_k only calls on e1,…,eke_1,\dots,e_k, every coefficient with row above column is zero — RR is upper triangular, the fingerprint of nested spans.

Step 2. Stack the columns. With the vkv_k as columns of AA and the eie_i as columns of QQ, the relation vk=∑iRikeiv_k=\sum_i R_{ik}e_i is exactly the kk-th column of QRQR, so A=QRA=QR with Q†Q=IQ^{\dagger}Q=I, RR upper triangular, Rkk>0R_{kk}>0. Why: this is the columnwise definition of matrix multiplication read backwards — algorithm and factorization are the same equations.

Step 3. Multiply the diagonal for a volume. Since Q†Q=IQ^{\dagger}Q=I, det⁡G=det⁡(A†A)=det⁡(R†R)=∏k=1nRkk2=∏k=1n∥uk∥2\det G=\det(A^{\dagger}A)=\det(R^{\dagger}R)=\prod_{k=1}^{n}R_{kk}^2=\prod_{k=1}^{n}\lVert u_k\rVert^2. Why: the orthonormal QQ drops out of the determinant, so det⁡G\det G depends only on the remainder-lengths — the shrinking heights of the parallelepiped as each edge is measured against the flat of the earlier ones.

Step 4. Interpret. Rkk=∥uk∥R_{kk}=\lVert u_k\rVert is the distance from vkv_k to the span of its predecessors — the kk-th height — and ∏kRkk=det⁡G\prod_k R_{kk}=\sqrt{\det G} is the volume, base times height generalized; a vanishing height means a dependent vector and a collapsed solid. Why: this makes det⁡G\det G a coordinate-free independence test and a volume Gram-Schmidt computes for free. *As a numerical check on the R3\mathbb{R}^3 example below: ∏k∥uk∥2=2⋅32⋅43=4=det⁡G\prod_k\lVert u_k\rVert^2=2\cdot\tfrac32\cdot\tfrac43=4=\det G, confirming det⁡G=∏k∥uk∥2\det G=\prod_k\lVert u_k\rVert^2.*

Limiting cases

Orthogonality and Gram-Schmidt collapse to instructive special forms in several regimes, each a check on the machinery.

CaseResultMeaning
Already-orthonormal input⟨vi,vj⟩=δij ⇒ ei=vi, R=I\langle v_i,v_j\rangle=\delta_{ij}\ \Rightarrow\ e_i=v_i,\ R=IEvery projection coefficient vanishes and every norm is 11, so the process returns its input untouched — the identity factorization A=QA=Q.
Two vectors in the planee2=v2−⟨e1,v2⟩e1∥v2−⟨e1,v2⟩e1∥e_2=\dfrac{v_2-\langle e_1,v_2\rangle e_1}{\lVert v_2-\langle e_1,v_2\rangle e_1\rVert}The classic textbook step: subtract the shadow of v2v_2 on e1e_1 and normalize — the single move drawn in the first figure.
Nearly dependent input∥vk−∑i<k⟨ei,vk⟩ei∥→0\lVert v_k-\sum_{i<k}\langle e_i,v_k\rangle e_i\rVert\to 0The remainder is a tiny difference of large vectors; catastrophic cancellation destroys orthogonality in floating point — use modified Gram-Schmidt or Householder.
Complex inner-product spaceprojev=⟨e,v⟩ e,⟨e,v⟩=⟨v,e⟩‾\mathrm{proj}_e v=\langle e,v\rangle\,e,\quad \langle e,v\rangle=\overline{\langle v,e\rangle}The coefficient is still an inner product, but conjugation lives in a definite slot; swapping the order corrupts the result.
Function space, weight w(x)w(x)⟨f,g⟩=∫wfg dx\langle f,g\rangle=\int w f g\,\mathrm{d}x on monomials →\to classical polynomialsDifferent weights orthogonalize 1,x,x2,…1,x,x^2,\dots into Legendre (w=1w=1), Hermite (w=e−x2w=e^{-x^2}), Laguerre (w=e−xw=e^{-x}) — same algorithm, new inner product.

Worked examples

1 · A full QR factorization in ℝ³ (fully worked)

Orthonormalize v1=(1,1,0)v_1=(1,1,0), v2=(1,0,1)v_2=(1,0,1), v3=(0,1,1)v_3=(0,1,1) with the standard dot product, and read off the factorization A=QRA=QR and the volume they span.

Step 1. First vector — just normalize. u1=v1=(1,1,0)u_1=v_1=(1,1,0), so ∥u1∥2=2\lVert u_1\rVert^2=2 and ∥u1∥=2\lVert u_1\rVert=\sqrt2. Hence e1=12(1,1,0)\mathbf{e_1=\tfrac{1}{\sqrt2}(1,1,0)}. The diagonal entry R11=2≈1.41421R_{11}=\sqrt2\approx1.41421.

Step 2. Second vector — subtract its projection on u1u_1. The overlap ⟨u1,v2⟩=1\langle u_1,v_2\rangle=1 over ⟨u1,u1⟩=2\langle u_1,u_1\rangle=2 gives coefficient 12\tfrac12, so u2=v2−12u1=(12,−12,1)u_2=v_2-\tfrac12 u_1=(\tfrac12,-\tfrac12,1) with ∥u2∥2=32\lVert u_2\rVert^2=\tfrac32. Normalizing, e2=16(1,−1,2)\mathbf{e_2=\tfrac{1}{\sqrt6}(1,-1,2)} (check 1+1+4=61+1+4=6). Then R12=⟨e1,v2⟩=12≈0.70711R_{12}=\langle e_1,v_2\rangle=\tfrac{1}{\sqrt2}\approx0.70711 and R22=3/2≈1.22474R_{22}=\sqrt{3/2}\approx1.22474.

Step 3. Third vector — subtract projections on both. The overlaps give coefficients ⟨u1,v3⟩/2=12\langle u_1,v_3\rangle/2=\tfrac12 and ⟨u2,v3⟩/⟨u2,u2⟩=(12)/(32)=13\langle u_2,v_3\rangle/\langle u_2,u_2\rangle=(\tfrac12)/(\tfrac32)=\tfrac13, so

u3=(0,1,1)−12(1,1,0)−13(12,−12,1)=(−23,23,23),u_3=(0,1,1)-\tfrac12(1,1,0)-\tfrac13(\tfrac12,-\tfrac12,1)=(-\tfrac23,\tfrac23,\tfrac23),

with ∥u3∥2=43\lVert u_3\rVert^2=\tfrac43. Normalizing, e3=13(−1,1,1)\mathbf{e_3=\tfrac{1}{\sqrt3}(-1,1,1)}, so R33=2/3≈1.15470R_{33}=2/\sqrt3\approx1.15470 and R23=⟨e2,v3⟩=16≈0.40825R_{23}=\langle e_2,v_3\rangle=\tfrac{1}{\sqrt6}\approx0.40825.

Step 4. Assemble and check. The factorization is

Q=(1216−1312−161302613),R=(2121203/2160023).Q=\begin{pmatrix}\tfrac{1}{\sqrt2}&\tfrac{1}{\sqrt6}&-\tfrac{1}{\sqrt3}\\[2pt]\tfrac{1}{\sqrt2}&-\tfrac{1}{\sqrt6}&\tfrac{1}{\sqrt3}\\[2pt]0&\tfrac{2}{\sqrt6}&\tfrac{1}{\sqrt3}\end{pmatrix},\qquad R=\begin{pmatrix}\sqrt2&\tfrac{1}{\sqrt2}&\tfrac{1}{\sqrt2}\\[2pt]0&\sqrt{3/2}&\tfrac{1}{\sqrt6}\\[2pt]0&0&\tfrac{2}{\sqrt3}\end{pmatrix}.

A dot-product check gives e1⋅e2=e1⋅e3=e2⋅e3=0e_1\cdot e_2=e_1\cdot e_3=e_2\cdot e_3=0, and the volume ∏kRkk=2⋅3/2⋅2/3=2\prod_k R_{kk}=\sqrt2\cdot\sqrt{3/2}\cdot 2/\sqrt3=\mathbf{2} matches det⁡G\sqrt{\det G} and ∣det⁡A∣=2|\det A|=2 exactly. The three edges span a solid of volume 2, and Gram-Schmidt handed us both the orthonormal frame and that volume in one pass.

2 · Legendre polynomials from Gram-Schmidt on monomials (fully worked)

Orthonormalize 1,x,x21,x,x^2 on L2[−1,1]L^2[-1,1] with ⟨f,g⟩=∫−11fg dx\langle f,g\rangle=\int_{-1}^{1}f g\,\mathrm{d}x, and recover the first Legendre polynomials.

Step 1. Zeroth function. Take u0=1u_0=1, so ⟨u0,u0⟩=∫−111 dx=2\langle u_0,u_0\rangle=\int_{-1}^{1}1\,\mathrm{d}x=2. Keeping the Legendre normalization Pn(1)=1P_n(1)=1 rather than unit norm, P0=1\mathbf{P_0=1}.

Step 2. First function. The overlap ⟨u0,x⟩=∫−11x dx=0\langle u_0,x\rangle=\int_{-1}^{1}x\,\mathrm{d}x=0 vanishes by odd symmetry, so nothing is subtracted: u1=xu_1=x and P1=x\mathbf{P_1=x}.

Step 3. Second function. Subtract projections onto both earlier remainders:

u2=x2−⟨u0,x2⟩⟨u0,u0⟩ u0−⟨u1,x2⟩⟨u1,u1⟩ u1.u_2=x^2-\frac{\langle u_0,x^2\rangle}{\langle u_0,u_0\rangle}\,u_0-\frac{\langle u_1,x^2\rangle}{\langle u_1,u_1\rangle}\,u_1.

The integrals are elementary: ⟨u0,x2⟩=∫−11x2 dx=23\langle u_0,x^2\rangle=\int_{-1}^{1}x^2\,\mathrm{d}x=\tfrac23 and ⟨u1,x2⟩=∫−11x3 dx=0\langle u_1,x^2\rangle=\int_{-1}^{1}x^3\,\mathrm{d}x=0 by symmetry, so only the u0u_0 term survives: u2=x2−2/32=x2−13u_2=x^2-\tfrac{2/3}{2}=x^2-\tfrac13.

Step 4. Apply the Legendre normalization. Rescale so the value at x=1x=1 is 11: since u2(1)=23u_2(1)=\tfrac23, multiply by 32\tfrac32, giving P2=32(x2−13)=12(3x2−1)P_2=\tfrac32\big(x^2-\tfrac13\big)=\mathbf{\tfrac12(3x^2-1)} — the standard P2P_2. A check confirms ∫−11P0P2 dx=12(2−2)=0\int_{-1}^{1}P_0 P_2\,\mathrm{d}x=\tfrac12(2-2)=0, orthogonal as promised. Gram-Schmidt on 1,x,x21,x,x^2 with the flat weight reproduces P0,P1,P2P_0,P_1,P_2 exactly; swapping the weight to e−x2e^{-x^2} would instead deliver the Hermite polynomials.

Physics of the portrait

Gram-Schmidt is named for two people who never collaborated, working a quarter-century apart on problems that turned out to be the same — a Danish actuary counting timber, and a German student of Hilbert taming integral equations.

Origins · 1 minthe Gram-Schmidt process and how this was discovered
TG
the Gram-Schmidt process
orthonormalization: J. P. Gram 1883, Erhard Schmidt 1907 · inner-product spaces and Hilbert-space theory

The process carries two names because it was found twice. Jørgen Pedersen Gram (1850–1916) was a Danish mathematician who spent most of his career in insurance, and it was an applied problem — approximating functions by least-squares series, once famously to model the yield of Danish forests — that led him in 1883 to the successive orthogonalization and to the determinant of pairwise inner products that now bears his name. Erhard Schmidt (1876–1959), a student of David Hilbert at Göttingen and later a founder of the Berlin school of functional analysis, wrote down the explicit recursion in 1907 inside his theory of linear integral equations, building orthonormal systems of functions in what would soon be called Hilbert space. Neither invented the idea from nothing — Laplace and Cauchy had orthogonalized functions decades earlier, and Schmidt credited Gram — but their names stuck as the algorithm entered the curriculum. The deeper lesson is that "orthogonalize, then normalize" is no trick of Euclidean geometry but a universal construction: it works in any inner-product space, finite or infinite dimensional, which is why the same three lines that straighten a bundle of arrows also manufacture the Legendre, Hermite, and Laguerre polynomials that quantum mechanics cannot do without.

History
1883
— Gram derives successive orthogonalization and the Gram determinant in a least-squares memoir
1907
— Schmidt states the explicit recursive orthonormalization in his theory of integral equations
1935
— the joint name Gram-Schmidt takes hold in the linear-algebra literature
1958
— Householder introduces reflector-based QR, a numerically stabler route to the same factorization
1967
— Björck's rounding-error analysis establishes modified Gram-Schmidt as the stable variant

Going further

Texts. Stone & Goldbart, Mathematics for Physics, §1.4–1.5 · Arfken, Weber & Harris, Mathematical Methods for Physicists, 7th ed., Ch. 5 · Hassani, Mathematical Physics, 2nd ed., Ch. 2–4 · Byron & Fuller, Mathematics of Classical and Quantum Physics, Ch. 3–4 · Riley, Hobson & Bence, Mathematical Methods for Physics and Engineering, 3rd ed., Ch. 8 · Trefethen & Bau, Numerical Linear Algebra, Lectures 7–8 (QR, Gram-Schmidt stability). Key anchor results: the projection coefficient α=⟨u,v⟩/⟨u,u⟩\alpha=\langle u,v\rangle/\langle u,u\rangle follows from both distance-minimization and the orthogonality condition; the R3\mathbb{R}^3 example gives e1=12(1,1,0)e_1=\tfrac{1}{\sqrt2}(1,1,0), e2=16(1,−1,2)e_2=\tfrac{1}{\sqrt6}(1,-1,2), e3=13(−1,1,1)e_3=\tfrac{1}{\sqrt3}(-1,1,1), diagonal R=2,3/2,2/3R=\sqrt2,\sqrt{3/2},2/\sqrt3, and volume ∏Rkk=∣det⁡A∣=2\prod R_{kk}=|\det A|=2; the Legendre integrals are ∫−11xn dx=2,0,23,0\int_{-1}^1 x^n\,\mathrm{d}x=2,0,\tfrac23,0 and P2=12(3x2−1)P_2=\tfrac12(3x^2-1); and det⁡G=∏k∥uk∥2\det G=\prod_k\lVert u_k\rVert^2. Historical dates for the naming and stability analysis are approximate.

Prerequisites. Inner-Product Spaces and Norms · Linear Independence, Basis, and Dimension · Vector Spaces and Subspaces. Leads to. Unitary and Orthogonal Operators · Diagonalization and the Spectral Decomposition · Adjoint Operators and Hermitian Operators · Change of Basis and Similarity Transformations.

Ask the tutor: Want me to run Gram-Schmidt on your own vectors, or show how the Hermite polynomials fall out when the weight turns Gaussian?

Does the order in which I feed the vectors to Gram-Schmidt matter?

Yes — the algorithm is order-dependent, and different orderings generally produce different orthonormal bases, though each still spans the same total space. The first input keeps its direction and only gets normalized; each later one is bent perpendicular to everything before it, so reordering yields a different QQ and RR. This matters in numerics: column-pivoted QRQR deliberately processes the largest remainder first, improving stability and revealing the numerical rank. So the span is order-independent, but the specific basis is not.

What is the difference between classical and modified Gram-Schmidt?

They compute the same QQ and RR in exact arithmetic but behave very differently in floating point. Classical Gram-Schmidt forms all projection coefficients from the original vkv_k and subtracts them in one batch. Modified Gram-Schmidt subtracts one projection, updates the working vector in place, then computes the next coefficient from that updated vector. Because each coefficient is taken against a partially-orthogonalized vector, rounding errors do not compound as they do in the batch, and the columns stay far closer to orthogonal — especially for nearly dependent inputs. For dense problems people often prefer Householder reflectors, which are more stable still, but modified Gram-Schmidt remains the natural choice inside iterative Krylov methods.

What happens if I accidentally feed in a linearly dependent set?

The process detects it by producing a zero remainder. At the step where vkv_k lies in the span of its predecessors, subtracting its projections removes everything, leaving uk=0u_k=0 and a zero norm — normalization would divide by zero. In exact arithmetic this is the clean signal "these vectors are dependent"; you skip that vector and the survivors still form an orthonormal basis of the subspace they span. In floating point the remainder is a tiny nonzero vector, which is dangerous: dividing by its minuscule norm amplifies rounding error. Rank-revealing QRQR handles this by flagging any remainder below a tolerance as a numerical dependency.

Why do the Legendre polynomials come out, and where do the weight functions come from?

Legendre polynomials are, by definition, the orthogonal polynomials for the flat weight w(x)=1w(x)=1 on [−1,1][-1,1] — and Gram-Schmidt on 1,x,x2,…1,x,x^2,\dots with that inner product produces exactly them, up to the rescaling Pn(1)=1P_n(1)=1. Change the weight and you change the family: w=e−x2w=e^{-x^2} gives Hermite polynomials, w=e−xw=e^{-x} on [0,∞)[0,\infty) gives Laguerre, and (1−x2)α(1-x^2)^\alpha weights give Gegenbauer and Jacobi. The weights are not arbitrary — each is the natural measure of a physical problem: Hermite's Gaussian weight is the ground-state density of the harmonic oscillator, Laguerre's is tied to the hydrogen radial equation. Gram-Schmidt is the common factory; the weight is the die that stamps out which family you get.

How exactly is Gram-Schmidt the same thing as the QR factorization?

Stack your inputs as the columns of AA. Gram-Schmidt produces orthonormal outputs, stacked as the columns of QQ; every coefficient and remainder-length you computed is an entry of an upper-triangular RR. The relation "each input is a combination of the outputs with equal-or-smaller index" is precisely A=QRA=QR: the diagonal Rkk=∥uk∥R_{kk}=\lVert u_k\rVert records each remainder-length, the off-diagonal Rik=⟨ei,vk⟩R_{ik}=\langle e_i,v_k\rangle the overlaps you subtracted. So the algorithm and the factorization are the same equations in two notations, which is why QRQR solvers and Gram-Schmidt are interchangeable.

Is Gram-Schmidt actually used to compute, or is it mainly a proof device?

Both, with a division of labour. As a proof device it is indispensable: it constructively shows every finite-dimensional inner-product space has an orthonormal basis, underpins the spectral theorem's orthonormal eigenbases for degenerate spectra, and builds the classical orthogonal polynomials. As a computational tool the classical form is avoided for dense problems — Householder QRQR is more stable — but the modified form runs at enormous scale inside iterative solvers (Arnoldi, Lanczos, GMRES), orthogonalizing each freshly generated Krylov vector against the previous ones on the fly. So the textbook recursion is at once the cleanest existence proof in linear algebra and, in its modified guise, a routine that runs constantly inside simulation codes.

Before this

Where this leads