Linear-Algebra-Done-Right Β· Unit 20 Β· Video 3 Β· Interactive Practice

QR Factorization: Gram–Schmidt Recorded as A = QR

IKey Formulas

FormulaNameWhen it holds
Qβˆ—Q=QQβˆ—=IQ^*Q = QQ^* = IUnitary matrixQQ is nn-by-nn with orthonormal columns (equivalently, orthonormal rows)
Rj,k=⟨vk,ej⟩R_{j,k} = \langle v_k, e_j\rangleEntries of RRv1,…,vnv_1, \dots, v_n are the linearly independent columns of AA; e1,…,ene_1, \dots, e_n is their Gram–Schmidt output and the columns of QQ
Rk,k=βˆ₯fkβˆ₯>0R_{k,k} = \|f_k\| > 0, where fk=vkβˆ’βˆ‘j<k⟨vk,ej⟩ejf_k = v_k - \sum_{j<k} \langle v_k, e_j\rangle e_jPositive diagonalSame hypotheses; fkβ‰ 0f_k \neq 0 because vkβˆ‰span⁑(v1,…,vkβˆ’1)v_k \notin \operatorname{span}(v_1, \dots, v_{k-1})
Ax=bβ€…β€ŠβŸΊβ€…β€ŠRx=Qβˆ—bAx = b \iff Rx = Q^*bSolving with QRA=QRA = QR with QQ unitary and RR upper triangular with positive diagonal

Key Insight: Gram–Schmidt and A=QRA = QR are one computation: QQ stores the vectors eke_k, RR stores the coefficients, and requiring Rk,k>0R_{k,k} > 0 makes the pair unique.

IIGram–Schmidt Fills In RR

Gram–Schmidt turns the columns v1,v2v_1, v_2 of AA into e1,e2e_1, e_2; the coefficients it computes are the entries of RR.

IIIWhy the Diagonal Must Be Positive

Every unitary Q^\widehat{Q} gives A=Q^R^A = \widehat{Q}\widehat{R} with R^=Q^βˆ—A\widehat{R} = \widehat{Q}^*A; only one makes R^\widehat{R} upper triangular with positive diagonal.

πŸ’‘ Over C\mathbf{C} the freedom is larger, qk=ΞΆkekq_k = \zeta_k e_k with ∣΢k∣=1|\zeta_k| = 1, and R^k,k>0\widehat{R}_{k,k} > 0 still forces every ΞΆk=1\zeta_k = 1.

IVSolving Ax=bAx = b by Back Substitution

For the video's matrix A=QRA = QR, the system Ax=bAx = b becomes the triangular system Rx=Qβˆ—bRx = Q^*b, solved from the last row up.

VQuiz Questions

Problem 1 Β· The Factor RR of a 2Γ—22 \times 2 Matrix

Given: A=(3142)A = \begin{pmatrix} 3 & 1 \\ 4 & 2 \end{pmatrix} β€” find the upper triangular factor RR in its QR factorization.

βœ… Correct! R1,1=βˆ₯v1βˆ₯=5R_{1,1} = \|v_1\| = 5, R1,2=⟨v2,e1⟩=115R_{1,2} = \langle v_2, e_1\rangle = \tfrac{11}{5} and R2,2=βˆ₯f2βˆ₯=25R_{2,2} = \|f_2\| = \tfrac{2}{5}.
❌ Rows and columns swapped. Rj,k=⟨vk,ej⟩R_{j,k} = \langle v_k, e_j\rangle is zero when j>kj > k, so the nonzero off-diagonal entry ⟨v2,e1⟩\langle v_2, e_1\rangle sits in row 1, column 2: RR is upper triangular.
❌ Not normalized. 11=⟨v2,v1⟩11 = \langle v_2, v_1\rangle, but R1,2=⟨v2,e1⟩R_{1,2} = \langle v_2, e_1\rangle with the unit vector e1=v1/βˆ₯v1βˆ₯=15(3,4)e_1 = v_1/\|v_1\| = \tfrac{1}{5}(3, 4), so R1,2=115R_{1,2} = \tfrac{11}{5}.
❌ Wrong sign on the diagonal. Taking e2=(45,βˆ’35)e_2 = (\tfrac{4}{5}, -\tfrac{3}{5}) still gives a unitary QQ, but then R2,2=βˆ’25<0R_{2,2} = -\tfrac{2}{5} < 0. Gram–Schmidt's e2=f2/βˆ₯f2βˆ₯e_2 = f_2/\|f_2\| makes R2,2=βˆ₯f2βˆ₯>0R_{2,2} = \|f_2\| > 0.
Show solution

The columns are v1=(3,4)v_1 = (3, 4) and v2=(1,2)v_2 = (1, 2). Since βˆ₯v1βˆ₯=5\|v_1\| = 5, e1=15(3,4)e_1 = \tfrac{1}{5}(3, 4) and R1,1=⟨v1,e1⟩=5R_{1,1} = \langle v_1, e_1\rangle = 5.

R1,2=⟨v2,e1⟩=15(3+8)=115R_{1,2} = \langle v_2, e_1\rangle = \tfrac{1}{5}(3 + 8) = \tfrac{11}{5} f2=v2βˆ’115e1=(1,2)βˆ’(3325,4425)=(βˆ’825,625),βˆ₯f2βˆ₯=1025=25f_2 = v_2 - \tfrac{11}{5}e_1 = (1, 2) - \big(\tfrac{33}{25}, \tfrac{44}{25}\big) = \big(-\tfrac{8}{25}, \tfrac{6}{25}\big), \qquad \|f_2\| = \tfrac{10}{25} = \tfrac{2}{5}

So e2=f2/βˆ₯f2βˆ₯=(βˆ’45,35)e_2 = f_2/\|f_2\| = (-\tfrac{4}{5}, \tfrac{3}{5}), R2,1=0R_{2,1} = 0 and R2,2=25R_{2,2} = \tfrac{2}{5}:

Q=(35βˆ’454535),R=(5115025).Q = \begin{pmatrix} \tfrac{3}{5} & -\tfrac{4}{5} \\ \tfrac{4}{5} & \tfrac{3}{5} \end{pmatrix}, \qquad R = \begin{pmatrix} 5 & \tfrac{11}{5} \\ 0 & \tfrac{2}{5} \end{pmatrix}.

Check: column 2 of QRQR is 115e1+25e2=(3325βˆ’825,4425+625)=(1,2)=v2\tfrac{11}{5}e_1 + \tfrac{2}{5}e_2 = \big(\tfrac{33}{25} - \tfrac{8}{25}, \tfrac{44}{25} + \tfrac{6}{25}\big) = (1, 2) = v_2.

Problem 2 Β· Already Triangular Is Not Enough

Given: A=(210βˆ’5)A = \begin{pmatrix} 2 & 1 \\ 0 & -5 \end{pmatrix}, which is already upper triangular β€” find the QQ and RR of its QR factorization.

βœ… Correct! QQ is unitary, RR is upper triangular with diagonal 2,5>02, 5 > 0, and QR=AQR = A; by uniqueness this is the only such pair.
❌ The diagonal is not positive. IA=AIA = A is a factorization, but R2,2=βˆ’5<0R_{2,2} = -5 < 0, so it is not the QR factorization the theorem describes.
❌ QRβ‰ AQR \neq A. This product is (2βˆ’10βˆ’5)\begin{pmatrix} 2 & -1 \\ 0 & -5 \end{pmatrix}. Negating column 2 of QQ must be matched by negating only row 2 of RR; R1,2=⟨v2,e1⟩=1R_{1,2} = \langle v_2, e_1\rangle = 1 is unchanged.
❌ Wrong sign in the first entry. (βˆ’I)(βˆ’A)=A(-I)(-A) = A, but now R1,1=βˆ’2<0R_{1,1} = -2 < 0, while R2,2=5R_{2,2} = 5 is fine. Only the second column of QQ needs negating.
Show solution

Run Gram–Schmidt on v1=(2,0)v_1 = (2, 0), v2=(1,βˆ’5)v_2 = (1, -5). First e1=(1,0)e_1 = (1, 0) and R1,1=2R_{1,1} = 2. Then R1,2=⟨v2,e1⟩=1R_{1,2} = \langle v_2, e_1\rangle = 1 and

f2=v2βˆ’1β‹…e1=(0,βˆ’5),βˆ₯f2βˆ₯=5,e2=(0,βˆ’1).f_2 = v_2 - 1 \cdot e_1 = (0, -5), \qquad \|f_2\| = 5, \qquad e_2 = (0, -1). Q=(100βˆ’1),R=(2105),QR=(210βˆ’5)=A.Q = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}, \qquad R = \begin{pmatrix} 2 & 1 \\ 0 & 5 \end{pmatrix}, \qquad QR = \begin{pmatrix} 2 & 1 \\ 0 & -5 \end{pmatrix} = A.

Taking Q=IQ = I, R=AR = A is the factorization (QD)(DR)(QD)(DR) with D=diag⁑(1,βˆ’1)D = \operatorname{diag}(1, -1): still a unitary times an upper triangular matrix, but with a negative diagonal entry.

Problem 3 Β· A 3Γ—33 \times 3 Factorization

Given: A=(13523βˆ’520βˆ’2)A = \begin{pmatrix} 1 & 3 & 5 \\ 2 & 3 & -5 \\ 2 & 0 & -2 \end{pmatrix} with columns v1,v2,v3v_1, v_2, v_3, and e1=13(1,2,2)e_1 = \tfrac{1}{3}(1, 2, 2) β€” find e2e_2 and the third column of RR.

What is e2e_2?

What is the third column (R1,3,R2,3,R3,3)(R_{1,3}, R_{2,3}, R_{3,3}) of RR?

βœ… Correct! e2=13(2,1,βˆ’2)e_2 = \tfrac{1}{3}(2, 1, -2) and column 3 of RR is (⟨v3,e1⟩,⟨v3,e2⟩,βˆ₯f3βˆ₯)=(βˆ’3,3,6)(\langle v_3, e_1\rangle, \langle v_3, e_2\rangle, \|f_3\|) = (-3, 3, 6).
❌ That is f2f_2. f2=v2βˆ’3e1=(2,1,βˆ’2)f_2 = v_2 - 3e_1 = (2, 1, -2) has norm 33; divide by it to get the unit vector e2e_2.
❌ The projection was not removed. This is v2/βˆ₯v2βˆ₯v_2/\|v_2\|, which is not orthogonal to e1e_1: ⟨v2,e1⟩=3β‰ 0\langle v_2, e_1\rangle = 3 \neq 0. Subtract 3e13e_1 from v2v_2 first.
❌ Wrong sign. βˆ’e2-e_2 is also a unit vector orthogonal to e1e_1, but then R2,2=⟨v2,βˆ’e2⟩=βˆ’3<0R_{2,2} = \langle v_2, -e_2\rangle = -3 < 0. Gram–Schmidt's e2=f2/βˆ₯f2βˆ₯e_2 = f_2/\|f_2\| points along f2=(2,1,βˆ’2)f_2 = (2, 1, -2).
❌ Used f2f_2 instead of e2e_2. ⟨v3,f2⟩=9\langle v_3, f_2\rangle = 9, but R2,3=⟨v3,e2⟩=9/βˆ₯f2βˆ₯=3R_{2,3} = \langle v_3, e_2\rangle = 9/\|f_2\| = 3.
❌ R3,3R_{3,3} is βˆ₯f3βˆ₯\|f_3\|, not βˆ₯v3βˆ₯\|v_3\|. βˆ₯v3βˆ₯=54=36\|v_3\| = \sqrt{54} = 3\sqrt{6}; after removing the components along e1,e2e_1, e_2, f3=(4,βˆ’4,2)f_3 = (4, -4, 2) has norm 66.
❌ That is the third row. Row 3 of RR is (0,0,6)(0, 0, 6); the third column holds the coefficients of v3v_3 along e1,e2,e3e_1, e_2, e_3.
Show solution

The columns are v1=(1,2,2)v_1 = (1, 2, 2), v2=(3,3,0)v_2 = (3, 3, 0), v3=(5,βˆ’5,βˆ’2)v_3 = (5, -5, -2), and βˆ₯v1βˆ₯=3\|v_1\| = 3 gives e1=13(1,2,2)e_1 = \tfrac{1}{3}(1, 2, 2).

⟨v2,e1⟩=13(3+6+0)=3,f2=v2βˆ’3e1=(2,1,βˆ’2),βˆ₯f2βˆ₯=3,e2=13(2,1,βˆ’2).\langle v_2, e_1\rangle = \tfrac{1}{3}(3 + 6 + 0) = 3, \qquad f_2 = v_2 - 3e_1 = (2, 1, -2), \qquad \|f_2\| = 3, \qquad e_2 = \tfrac{1}{3}(2, 1, -2). ⟨v3,e1⟩=13(5βˆ’10βˆ’4)=βˆ’3,⟨v3,e2⟩=13(10βˆ’5+4)=3,\langle v_3, e_1\rangle = \tfrac{1}{3}(5 - 10 - 4) = -3, \qquad \langle v_3, e_2\rangle = \tfrac{1}{3}(10 - 5 + 4) = 3, f3=v3+3e1βˆ’3e2=(5,βˆ’5,βˆ’2)+(1,2,2)βˆ’(2,1,βˆ’2)=(4,βˆ’4,2),βˆ₯f3βˆ₯=6.f_3 = v_3 + 3e_1 - 3e_2 = (5, -5, -2) + (1, 2, 2) - (2, 1, -2) = (4, -4, 2), \qquad \|f_3\| = 6. Q=13(12221βˆ’22βˆ’21),R=(33βˆ’3033006).Q = \tfrac{1}{3}\begin{pmatrix} 1 & 2 & 2 \\ 2 & 1 & -2 \\ 2 & -2 & 1 \end{pmatrix}, \qquad R = \begin{pmatrix} 3 & 3 & -3 \\ 0 & 3 & 3 \\ 0 & 0 & 6 \end{pmatrix}.

Check column 3: βˆ’3e1+3e2+6e3=(βˆ’1,βˆ’2,βˆ’2)+(2,1,βˆ’2)+(4,βˆ’4,2)=(5,βˆ’5,βˆ’2)=v3-3e_1 + 3e_2 + 6e_3 = (-1, -2, -2) + (2, 1, -2) + (4, -4, 2) = (5, -5, -2) = v_3, with e3=13(2,βˆ’2,1)e_3 = \tfrac{1}{3}(2, -2, 1).

Problem 4 Β· Solve Without Elimination

Given: the factorization A=QRA = QR from Problem 3, Q=13(12221βˆ’22βˆ’21),R=(33βˆ’3033006),Q = \tfrac{1}{3}\begin{pmatrix} 1 & 2 & 2 \\ 2 & 1 & -2 \\ 2 & -2 & 1 \end{pmatrix}, \qquad R = \begin{pmatrix} 3 & 3 & -3 \\ 0 & 3 & 3 \\ 0 & 0 & 6 \end{pmatrix}, and b=(0,βˆ’9,0)b = (0, -9, 0) β€” find Qβˆ—bQ^*b and the solution xx of Ax=bAx = b.

What is Qβˆ—bQ^*b?

What is xx?

βœ… Correct! Rx=Qβˆ—b=(βˆ’6,βˆ’3,6)Rx = Q^*b = (-6, -3, 6) gives x3=1x_3 = 1, x2=βˆ’2x_2 = -2, x1=1x_1 = 1, and indeed A(1,βˆ’2,1)=(0,βˆ’9,0)A(1, -2, 1) = (0, -9, 0).
❌ That is bb itself. Qβˆ—bQ^*b lists the inner products ⟨b,e1⟩,⟨b,e2⟩,⟨b,e3⟩\langle b, e_1\rangle, \langle b, e_2\rangle, \langle b, e_3\rangle.
❌ The factor 13\tfrac{1}{3} was dropped. Every entry of QQ carries 13\tfrac{1}{3}, so ⟨b,e1⟩=13(0βˆ’18+0)=βˆ’6\langle b, e_1\rangle = \tfrac{1}{3}(0 - 18 + 0) = -6.
❌ Divided by 33 twice. The columns 13(1,2,2)\tfrac{1}{3}(1, 2, 2), … are already unit vectors; ⟨b,e1⟩=13(βˆ’18)=βˆ’6\langle b, e_1\rangle = \tfrac{1}{3}(-18) = -6, with no further division.
❌ This solves Rx=bRx = b. Multiplying QRx=bQRx = b on the left by Qβˆ—Q^* changes the right side to Qβˆ—bQ^*b; back substitution must use (βˆ’6,βˆ’3,6)(-6, -3, 6).
❌ Sign slip in the top row. Row 1 reads 3x1+3x2βˆ’3x3=βˆ’63x_1 + 3x_2 - 3x_3 = -6; with x2=βˆ’2x_2 = -2, x3=1x_3 = 1 this is 3x1βˆ’9=βˆ’63x_1 - 9 = -6, so x1=1x_1 = 1.
❌ The right side was divided by 33 twice. Back substitution with (βˆ’2,βˆ’1,2)(-2, -1, 2) gives this; the right side is Qβˆ—b=(βˆ’6,βˆ’3,6)Q^*b = (-6, -3, 6), three times larger, and so is the solution.
Show solution

QQ is real, so Qβˆ—Q^* is its transpose, whose rows are e1,e2,e3e_1, e_2, e_3:

Qβˆ—b=(13(0βˆ’18+0),β€…β€Š13(0βˆ’9+0),β€…β€Š13(0+18+0))=(βˆ’6,βˆ’3,6).Q^*b = \Big(\tfrac{1}{3}(0 - 18 + 0),\; \tfrac{1}{3}(0 - 9 + 0),\; \tfrac{1}{3}(0 + 18 + 0)\Big) = (-6, -3, 6).

Back substitution on Rx=Qβˆ—bRx = Q^*b, from the last row up:

6x3=6β‡’x3=1,3x2+3x3=βˆ’3β‡’x2=βˆ’2,3x1+3x2βˆ’3x3=βˆ’6β‡’3x1βˆ’9=βˆ’6β‡’x1=1.6x_3 = 6 \Rightarrow x_3 = 1, \qquad 3x_2 + 3x_3 = -3 \Rightarrow x_2 = -2, \qquad 3x_1 + 3x_2 - 3x_3 = -6 \Rightarrow 3x_1 - 9 = -6 \Rightarrow x_1 = 1.

Check: A(1,βˆ’2,1)=(1βˆ’6+5,β€…β€Š2βˆ’6βˆ’5,β€…β€Š2βˆ’0βˆ’2)=(0,βˆ’9,0)=bA(1, -2, 1) = (1 - 6 + 5,\; 2 - 6 - 5,\; 2 - 0 - 2) = (0, -9, 0) = b.

Solved: 0 / 4