Euler Hall — free maths guides

Normalize the residual of a Gram-Schmidt step

Divide an orthogonal vector by its length to produce a unit vector. The idea in plain words, a worked example, and a check with the answers shown — part of the free Linear Algebra guides.

The definition and the check

For a nonzero vectorvv, the unit vector in its direction is q=v∥v∥,so∥q∥=∥v∥∥v∥=1.q=\frac{v}{\|v\|},\qquad\text{so}\qquad \|q\|=\frac{\|v\|}{\|v\|}=1.

The check is one line. Square each entry ofqq, add, and require11: ∥q∥2=q12+q22+⋯=1.\|q\|^2=q_1^2+q_2^2+\cdots=1. That single sum detects every normalising slip, and it costs two multiplications per entry.

What stays the same and what changes.qq points in exactly the same direction asvv — it is a positive multiple ofvv — and only its length changed, from∥v∥\|v\| to11. So orthogonality to other vectors is preserved: ifuTv=0u^Tv=0 thenuTq=uTv/∥v∥=0u^Tq=u^Tv/\|v\|=0.

Where it happens in Gram-Schmidt. Subtracting the projections builds the orthogonal vectorsA,B,CA,B,C; normalising happens afterwards, once per vector. Dividing at the start would put a square root inside every later dot product.

Why the length and not the squared length

The reason is dimensional, and it is worth stating because it generalises to every scaling question.

Scaling a vector multiplies its length by the absolute scale. Ifq=cvq=cv, then∥q∥=∣c∣ ∥v∥\|q\|=|c|\,\|v\|. To get∥q∥=1\|q\|=1 you need∣c∣=1/∥v∥|c|=1/\|v\|, i.e.c=±1/∥v∥c=\pm1/\|v\|. Dividing by∥v∥2\|v\|^2 givesc=1/∥v∥2c=1/\|v\|^2 and hence∥q∥=1/∥v∥\|q\|=1/\|v\|, which is11 only whenvv was already unit.

Squaring is not linear, so it does not behave like the thing it is applied to. Doublingvv doubles∥v∥\|v\| but quadruples∥v∥2\|v\|^2. Any formula that should be homogeneous of degree one in the vector has to use∥v∥\|v\|, not∥v∥2\|v\|^2.

The same fact again in dot-product language.vTvv^Tv is the squared length by definition, so anything that starts fromvTvv^Tv is already one level too high. That is why the projection coefficient isaTbaTa\frac{a^Tb}{a^Ta} — the denominator is the squared length because it is compensating a dot product, not because lengths are squared in general.

Why orthogonality survives normalisation. IfuTv=0u^Tv=0 andq=v/∥v∥q=v/\|v\|, thenuTq=1∥v∥uTv=0u^Tq=\frac{1}{\|v\|}u^Tv=0. Scaling one vector of a perpendicular pair keeps the pair perpendicular, which is why normalising after all the subtractions is safe.

Worked example: the three Gram-Schmidt vectors

From the textbook's triplea=(1,−1,0)a=(1,-1,0),b=(2,0,−2)b=(2,0,-2),c=(3,−3,3)c=(3,-3,3) the orthogonal vectors are A=[1−10],B=[11−2],C=[111].A=\begin{bmatrix}1\\-1\\0\end{bmatrix},\qquad B=\begin{bmatrix}1\\1\\-2\end{bmatrix},\qquad C=\begin{bmatrix}1\\1\\1\end{bmatrix}.

Lengths.∥A∥2=2\|A\|^2=2,∥B∥2=6\|B\|^2=6,∥C∥2=3\|C\|^2=3, so∥A∥=2\|A\|=\sqrt2,∥B∥=6\|B\|=\sqrt6,∥C∥=3\|C\|=\sqrt3.

Unit vectors. q1=12[1−10],q2=16[11−2],q3=13[111].\def\arraystretch{1.6}q_1=\frac{1}{\sqrt2}\begin{bmatrix}1\\-1\\0\end{bmatrix},\qquad q_2=\frac{1}{\sqrt6}\begin{bmatrix}1\\1\\-2\end{bmatrix},\qquad q_3=\frac{1}{\sqrt3}\begin{bmatrix}1\\1\\1\end{bmatrix}.

Verify all three.∥q1∥2=1+12=1\|q_1\|^2=\frac{1+1}{2}=1 ✓,∥q2∥2=1+1+46=1\|q_2\|^2=\frac{1+1+4}{6}=1 ✓,∥q3∥2=1+1+13=1\|q_3\|^2=\frac{1+1+1}{3}=1 ✓

Verify orthogonality survived.q1Tq2=112(1−1+0)=0q_1^Tq_2=\frac{1}{\sqrt{12}}(1-1+0)=0 ✓ — the scaling factors multiply, and the dot of the unscaled vectors was already zero.

TheRR diagonal. Those three lengths are exactly the diagonal ofRR inA=QRA=QR:2,6,3\sqrt2,\sqrt6,\sqrt3. The squared lengths2,6,32,6,3 are the diagonal ofRTR=ATAR^TR=A^TA, which is where they naturally come from and why the two are easy to confuse.

By the end you can
  • Divide an orthogonal vector by its length to produce a unit vector
  • Distinguish the length from the squared length and say which one the division uses
  • Verify ||q||^2 = 1 and explain the sign convention
Test yourself

(a) Normalisev=(3,4)v=(3,4). (b) What is∥v∥2\|v\|^2 forv=(1,2,2)v=(1,2,2), and what is the unit vector? (c) Two students writeq=15(3,4)q=\frac{1}{5}(3,4) andq=125(3,4)q=\frac{1}{25}(3,4). Which is unit, and what is the other's squared length?

Answers

(a)∥v∥=5\|v\|=5, soq=(35,45)q=\left(\frac35,\frac45\right), and9+1625=1\frac{9+16}{25}=1 ✓

(b)∥v∥2=9\|v\|^2=9 and∥v∥=3\|v\|=3, soq=13(1,2,2)q=\frac13(1,2,2).

(c)15(3,4)\frac15(3,4) is unit.125(3,4)\frac{1}{25}(3,4) has squared length25625=125\frac{25}{625}=\frac{1}{25} — it divided by∥v∥2\|v\|^2 instead of∥v∥\|v\|.

Work out where to start — free, no accountAnswer six real questions — free, no account