Skip to content

Gram-Schmidt Algorithm


Method

Input: linearly independent vectors a1,…,ak\boldsymbol{a}_1,\ldots,\boldsymbol{a}_k in a real inner product space VV (in Rn\mathbb{R}^n: the dot product).

Steps: for j=1,…,kj=1,\ldots,k,

vj=aj−∑i=1j−1aj⋅vivi⋅vi vi,qj=vj∥vj∥.\boldsymbol{v}_j=\boldsymbol{a}_j-\sum_{i=1}^{j-1}\frac{\boldsymbol{a}_j\cdot\boldsymbol{v}_i}{\boldsymbol{v}_i\cdot\boldsymbol{v}_i}\,\boldsymbol{v}_i,\qquad \boldsymbol{q}_j=\frac{\boldsymbol{v}_j}{\|\boldsymbol{v}_j\|}.

Output: orthogonal vectors v1,…,vk\boldsymbol{v}_1,\ldots,\boldsymbol{v}_k and orthonormal vectors q1,…,qk\boldsymbol{q}_1,\ldots,\boldsymbol{q}_k such that, for every jj,

span⁡{q1,…,qj}=span⁡{a1,…,aj}.\operatorname{span}\{\boldsymbol{q}_1,\ldots,\boldsymbol{q}_j\}=\operatorname{span}\{\boldsymbol{a}_1,\ldots,\boldsymbol{a}_j\}.

Interpretation

Each step removes from aj\boldsymbol{a}_j its orthogonal projection onto the span of the earlier vectors; what is left, vj\boldsymbol{v}_j, is the component of aj\boldsymbol{a}_j in the orthogonal complement of that span. Dividing by the norm ∥vj∥=vj⋅vj\|\boldsymbol{v}_j\|=\sqrt{\boldsymbol{v}_j\cdot\boldsymbol{v}_j} (the Euclidean norm in Rn\mathbb{R}^n) then gives a unit vector. Since the qi\boldsymbol{q}_i are already orthonormal, the update can equally be written vj=aj−∑i<j(aj⋅qi)qi\displaystyle \boldsymbol{v}_j=\boldsymbol{a}_j-\sum_{i<j}(\boldsymbol{a}_j\cdot\boldsymbol{q}_i)\boldsymbol{q}_i.

Step two of Gram-Schmidt in the plane of a1 and a2: a2 is dropped perpendicularly onto v1 = a1, the foot is half of v1, and v2 = a2 minus half of v1 is at right angles to v1.

The figure shows the second step of the example below, drawn in the plane spanned by a1=(1,1,0)⊤\boldsymbol{a}_1=(1,1,0)^{\top} and a2=(1,0,1)⊤\boldsymbol{a}_2=(1,0,1)^{\top} with true lengths. The projection of a2\boldsymbol{a}_2 onto v1=a1\boldsymbol{v}_1=\boldsymbol{a}_1 is 12v1\tfrac{1}{2}\boldsymbol{v}_1, since (a2⋅v1)/(v1⋅v1)=12(\boldsymbol{a}_2\cdot\boldsymbol{v}_1)/(\boldsymbol{v}_1\cdot\boldsymbol{v}_1)=\tfrac{1}{2}. Removing it leaves v2=a2−12v1=(12,−12,1)⊤\boldsymbol{v}_2=\boldsymbol{a}_2-\tfrac{1}{2}\boldsymbol{v}_1=(\tfrac{1}{2},-\tfrac{1}{2},1)^{\top}, the dashed perpendicular moved to the origin, which is orthogonal to v1\boldsymbol{v}_1.

Linear independence is what guarantees vj≠0\boldsymbol{v}_j\neq\boldsymbol{0}, so that the division is allowed. The output depends on the order of the input: reordering the aj\boldsymbol{a}_j generally gives a different orthonormal basis of the same space.

A frequent slip is to project onto the original ai\boldsymbol{a}_i instead of the new vi\boldsymbol{v}_i; the ai\boldsymbol{a}_i are not orthogonal, so their projections overlap and the result is wrong.


Key Results

  • vj=0\boldsymbol{v}_j=\boldsymbol{0} occurs exactly when aj∈span⁡{a1,…,aj−1}\boldsymbol{a}_j\in\operatorname{span}\{\boldsymbol{a}_1,\ldots,\boldsymbol{a}_{j-1}\}; run on any list, the algorithm detects dependence, and discarding such aj\boldsymbol{a}_j yields an orthonormal basis of the span of the list.
  • Every finite-dimensional inner product space has an orthonormal basis, and every orthonormal list extends to one.
  • In floating-point arithmetic the classical version loses orthogonality; the modified version, which subtracts projections one at a time from the updated vector, is the numerically preferred form.

Beyond the course

Many textbooks collect the Gram-Schmidt output in a factorization A=QRA=QR of a matrix with independent columns, with QQ having orthonormal columns and RR upper triangular. This QR decomposition is not part of Math V.


Examples

Three vectors in R3\mathbb{R}^3. Take a1=(1,1,0)⊤\boldsymbol{a}_1=(1,1,0)^{\top}, a2=(1,0,1)⊤\boldsymbol{a}_2=(1,0,1)^{\top}, a3=(0,1,1)⊤\boldsymbol{a}_3=(0,1,1)^{\top}.

  • v1=(1,1,0)⊤\boldsymbol{v}_1=(1,1,0)^{\top}, ∥v1∥2=2\|\boldsymbol{v}_1\|^2=2.
  • a2⋅v1=1\boldsymbol{a}_2\cdot\boldsymbol{v}_1=1, so v2=(1,0,1)⊤−12(1,1,0)⊤=(12,−12,1)⊤\boldsymbol{v}_2=(1,0,1)^{\top}-\tfrac{1}{2}(1,1,0)^{\top}=(\tfrac{1}{2},-\tfrac{1}{2},1)^{\top}, ∥v2∥2=32\|\boldsymbol{v}_2\|^2=\tfrac{3}{2}.
  • a3⋅v1=1\boldsymbol{a}_3\cdot\boldsymbol{v}_1=1 and a3⋅v2=12\boldsymbol{a}_3\cdot\boldsymbol{v}_2=\tfrac{1}{2}, so v3=(0,1,1)⊤−12(1,1,0)⊤−13(12,−12,1)⊤=(−23,23,23)⊤\boldsymbol{v}_3=(0,1,1)^{\top}-\tfrac{1}{2}(1,1,0)^{\top}-\tfrac{1}{3}(\tfrac{1}{2},-\tfrac{1}{2},1)^{\top}=(-\tfrac{2}{3},\tfrac{2}{3},\tfrac{2}{3})^{\top}.

Check: v3⋅v1=0\boldsymbol{v}_3\cdot\boldsymbol{v}_1=0 and v3⋅v2=−13−13+23=0\boldsymbol{v}_3\cdot\boldsymbol{v}_2=-\tfrac{1}{3}-\tfrac{1}{3}+\tfrac{2}{3}=0. Normalizing,

q1=12(1,1,0)⊤,q2=16(1,−1,2)⊤,q3=13(−1,1,1)⊤.\boldsymbol{q}_1=\tfrac{1}{\sqrt{2}}(1,1,0)^{\top},\qquad \boldsymbol{q}_2=\tfrac{1}{\sqrt{6}}(1,-1,2)^{\top},\qquad \boldsymbol{q}_3=\tfrac{1}{\sqrt{3}}(-1,1,1)^{\top}.

Detecting dependence. For a1=(1,2)⊤\boldsymbol{a}_1=(1,2)^{\top}, a2=(2,4)⊤\boldsymbol{a}_2=(2,4)^{\top}: v2=(2,4)⊤−105(1,2)⊤=0\boldsymbol{v}_2=(2,4)^{\top}-\tfrac{10}{5}(1,2)^{\top}=\boldsymbol{0}, so a2\boldsymbol{a}_2 is a multiple of a1\boldsymbol{a}_1.


Prerequisites



Sources

Aliases: Gram-Schmidt process, Gram-Schmidt orthogonalization, Gram-Schmidt orthonormalization, Gram-Schmidt orthogonalisation, Gram-Schmidt procedure, Gram-Schmidt method Keywords: orthonormal basis, QR decomposition, q_j = v_j / ||v_j||, subtract projections, A = QR Symbols: element of, real numbers, square root, sum

Last updated: 22 October 2026 19:04