Quiz 2

Gram-Schmidt Process & QR Decomposition

2164 words
11 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Gram-Schmidt Process & QR Decomposition ## 🎯 Learning Objectives After this topic you will be able to: - Apply the Gram-Schmidt process to convert any basis into an orthonormal basis - Compute the $QR$ decomposition of a matrix - Use Gram-Schmidt to find orthogonal bases for subspaces - Understand the geometric i...

Gram-Schmidt Process & QR Decomposition

🎯 Learning Objectives

After this topic you will be able to:
  • Apply the Gram-Schmidt process to convert any basis into an orthonormal basis
  • Compute the QRQR decomposition of a matrix
  • Use Gram-Schmidt to find orthogonal bases for subspaces
  • Understand the geometric intuition of subtracting projections

📋 Prerequisites

  • Orthogonality (this week) — orthonormal bases, projections
  • Inner Products (Week 7) — needed for projections
  • Gram-Schmidt is the algorithm that makes orthonormal bases computable

1. Intuition: Building Orthogonality Step by Step

Given any basis {v1,,vn}\{\mathbf{v}_1, \dots, \mathbf{v}_n\}, Gram-Schmidt produces an orthonormal basis {u1,,un}\{\mathbf{u}_1, \dots, \mathbf{u}_n\} for the same space. Idea: For each vector vk\mathbf{v}_k, subtract its projections onto all previous ui\mathbf{u}_i to get an orthogonal vector, then normalise. (Diagram)

2. The Gram-Schmidt Algorithm

Gram-Schmidt Process. Given a basis {v1,,vn}\{\mathbf{v}_1, \dots, \mathbf{v}_n\}, define:
>u1=v1v1w2=v2v2,u1u1,u2=w2w2w3=v3v3,u1u1v3,u2u2,u3=w3w3>> \begin{aligned} \mathbf{u}_1 &= \frac{\mathbf{v}_1}{\|\mathbf{v}_1\|} \\ \mathbf{w}_2 &= \mathbf{v}_2 - \langle \mathbf{v}_2, \mathbf{u}_1 \rangle \mathbf{u}_1, \quad \mathbf{u}_2 = \frac{\mathbf{w}_2}{\|\mathbf{w}_2\|} \\ \mathbf{w}_3 &= \mathbf{v}_3 - \langle \mathbf{v}_3, \mathbf{u}_1 \rangle \mathbf{u}_1 - \langle \mathbf{v}_3, \mathbf{u}_2 \rangle \mathbf{u}_2, \quad \mathbf{u}_3 = \frac{\mathbf{w}_3}{\|\mathbf{w}_3\|} \end{aligned} >
Continue: wk=vki=1k1vk,uiui\mathbf{w}_k = \mathbf{v}_k - \sum_{i=1}^{k-1} \langle \mathbf{v}_k, \mathbf{u}_i \rangle \mathbf{u}_i, then uk=wkwk\mathbf{u}_k = \frac{\mathbf{w}_k}{\|\mathbf{w}_k\|}. Example 1: Gram-Schmidt in ℝ²
Basis: v1=(3,1)\mathbf{v}_1 = (3, 1), v2=(2,2)\mathbf{v}_2 = (2, 2).
Step 1: v1=9+1=10\|\mathbf{v}_1\| = \sqrt{9+1} = \sqrt{10}, u1=(310,110)\mathbf{u}_1 = \left(\frac{3}{\sqrt{10}}, \frac{1}{\sqrt{10}}\right).
Step 2: v2,u1=6+210=810\langle \mathbf{v}_2, \mathbf{u}_1 \rangle = \frac{6+2}{\sqrt{10}} = \frac{8}{\sqrt{10}}.
w2=(2,2)810(310,110)=(2,2)810(3,1)=(2,2)(2.4,0.8)=(0.4,1.2)\mathbf{w}_2 = (2,2) - \frac{8}{\sqrt{10}}\left(\frac{3}{\sqrt{10}}, \frac{1}{\sqrt{10}}\right) = (2,2) - \frac{8}{10}(3,1) = (2,2) - (2.4, 0.8) = (-0.4, 1.2).
w2=0.16+1.44=1.6=410\|\mathbf{w}_2\| = \sqrt{0.16 + 1.44} = \sqrt{1.6} = \frac{4}{\sqrt{10}}.
u2=(0.4,1.2)4/10=(110,310)\mathbf{u}_2 = \frac{(-0.4, 1.2)}{4/\sqrt{10}} = \left(-\frac{1}{\sqrt{10}}, \frac{3}{\sqrt{10}}\right).
Check: u1,u2=310(110)+110(310)=310+310=0\langle \mathbf{u}_1, \mathbf{u}_2 \rangle = \frac{3}{\sqrt{10}}\left(-\frac{1}{\sqrt{10}}\right) + \frac{1}{\sqrt{10}}\left(\frac{3}{\sqrt{10}}\right) = -\frac{3}{10} + \frac{3}{10} = 0Example 2: Gram-Schmidt in ℝ³
Basis: v1=(1,2,2)\mathbf{v}_1 = (1, 2, 2), v2=(1,0,2)\mathbf{v}_2 = (-1, 0, 2), v3=(0,0,1)\mathbf{v}_3 = (0, 0, 1).
Step 1: v1=1+4+4=3\|\mathbf{v}_1\| = \sqrt{1+4+4} = 3, u1=(13,23,23)\mathbf{u}_1 = \left(\frac{1}{3}, \frac{2}{3}, \frac{2}{3}\right).
Step 2: v2,u1=1+0+43=33=1\langle \mathbf{v}_2, \mathbf{u}_1 \rangle = \frac{-1+0+4}{3} = \frac{3}{3} = 1.
w2=(1,0,2)1(13,23,23)=(43,23,43)\mathbf{w}_2 = (-1,0,2) - 1\left(\frac{1}{3}, \frac{2}{3}, \frac{2}{3}\right) = \left(-\frac{4}{3}, -\frac{2}{3}, \frac{4}{3}\right).
w2=16+4+169=369=2\|\mathbf{w}_2\| = \sqrt{\frac{16+4+16}{9}} = \sqrt{\frac{36}{9}} = 2.
u2=(23,13,23)\mathbf{u}_2 = \left(-\frac{2}{3}, -\frac{1}{3}, \frac{2}{3}\right).
Step 3: v3,u1=0+0+23=23\langle \mathbf{v}_3, \mathbf{u}_1 \rangle = \frac{0+0+2}{3} = \frac{2}{3}. v3,u2=0+0+23=23\langle \mathbf{v}_3, \mathbf{u}_2 \rangle = 0 + 0 + \frac{2}{3} = \frac{2}{3}.
w3=(0,0,1)23(13,23,23)23(23,13,23)\mathbf{w}_3 = (0,0,1) - \frac{2}{3}\left(\frac{1}{3}, \frac{2}{3}, \frac{2}{3}\right) - \frac{2}{3}\left(-\frac{2}{3}, -\frac{1}{3}, \frac{2}{3}\right)
=(0,0,1)(29,49,49)(49,29,49)= (0,0,1) - \left(\frac{2}{9}, \frac{4}{9}, \frac{4}{9}\right) - \left(-\frac{4}{9}, -\frac{2}{9}, \frac{4}{9}\right)
=(029+49,049+29,14949)=(29,29,19)= \left(0-\frac{2}{9}+\frac{4}{9}, 0-\frac{4}{9}+\frac{2}{9}, 1-\frac{4}{9}-\frac{4}{9}\right) = \left(\frac{2}{9}, -\frac{2}{9}, \frac{1}{9}\right).
w3=4+4+181=981=13\|\mathbf{w}_3\| = \sqrt{\frac{4+4+1}{81}} = \sqrt{\frac{9}{81}} = \frac{1}{3}.
u3=(23,23,13)\mathbf{u}_3 = \left(\frac{2}{3}, -\frac{2}{3}, \frac{1}{3}\right).
Orthonormal basis: {(13,23,23),(23,13,23),(23,23,13)}\left\{\left(\frac{1}{3}, \frac{2}{3}, \frac{2}{3}\right), \left(-\frac{2}{3}, -\frac{1}{3}, \frac{2}{3}\right), \left(\frac{2}{3}, -\frac{2}{3}, \frac{1}{3}\right)\right\}.

3. QR Decomposition

Definition (QR Decomposition). For an m×nm \times n matrix AA with linearly independent columns, the QRQR decomposition is:
>A=QR>> A = QR >
where QQ is m×nm \times n with orthonormal columns and RR is n×nn \times n upper triangular. How to get RR: When Gram-Schmidt produces qj\mathbf{q}_j from aj\mathbf{a}_j, the entries of RR are:
  • rii=wir_{ii} = \|\mathbf{w}_i\| (norm before normalisation)
  • rji=ai,qjr_{ji} = \langle \mathbf{a}_i, \mathbf{q}_j \rangle for j<ij < i
  • rji=0r_{ji} = 0 for j>ij > i
Example 3: QR of a 2×2 matrix
>A=[3212]>> A = \begin{bmatrix} 3 & 2 \\ 1 & 2 \end{bmatrix} >
.
From Example 1: q1=(310,110)\mathbf{q}_1 = \left(\frac{3}{\sqrt{10}}, \frac{1}{\sqrt{10}}\right), q2=(110,310)\mathbf{q}_2 = \left(-\frac{1}{\sqrt{10}}, \frac{3}{\sqrt{10}}\right).
So
>Q=[310110110310]>> Q = \begin{bmatrix} \frac{3}{\sqrt{10}} & -\frac{1}{\sqrt{10}} \\ \frac{1}{\sqrt{10}} & \frac{3}{\sqrt{10}} \end{bmatrix} >
.
RR: r11=v1=10r_{11} = \|\mathbf{v}_1\| = \sqrt{10}. r12=v2,q1=810r_{12} = \langle \mathbf{v}_2, \mathbf{q}_1 \rangle = \frac{8}{\sqrt{10}}. r22=w2=410r_{22} = \|\mathbf{w}_2\| = \frac{4}{\sqrt{10}}.
>R=[108100410]>> R = \begin{bmatrix} \sqrt{10} & \frac{8}{\sqrt{10}} \\ 0 & \frac{4}{\sqrt{10}} \end{bmatrix} >
.
Check:
>QR=[310110110310][108100410]=[324104101810+1210]=[3212]=A>> QR = \begin{bmatrix} \frac{3}{\sqrt{10}} & -\frac{1}{\sqrt{10}} \\ \frac{1}{\sqrt{10}} & \frac{3}{\sqrt{10}} \end{bmatrix} \begin{bmatrix} \sqrt{10} & \frac{8}{\sqrt{10}} \\ 0 & \frac{4}{\sqrt{10}} \end{bmatrix} = \begin{bmatrix} 3 & \frac{24}{10} - \frac{4}{10} \\ 1 & \frac{8}{10} + \frac{12}{10} \end{bmatrix} = \begin{bmatrix} 3 & 2 \\ 1 & 2 \end{bmatrix} = A >

4. Modified Gram-Schmidt (Numerical Stability)

For computer implementation, the modified Gram-Schmidt is preferred:
  • For each kk, subtract projections one at a time
  • This reduces rounding errors But the classical Gram-Schmidt (described above) is what you'll use on exams.

5. Edge Cases & Gotchas

SituationWhat Happens
Vector is already orthogonalwk=vk\mathbf{w}_k = \mathbf{v}_k (no subtraction needed)
** $\\mathbf{w}_k\
Starting basis not orderedDifferent orders produce different orthonormal bases

6. Common Pitfalls

❌ Pitfall 1: Arithmetic errors in subtraction

Keep fractions or use exact arithmetic. Rounding early leads to wrong results.

❌ Pitfall 2: Forgetting to subtract ALL previous projections

For w3\mathbf{w}_3, you must subtract projections onto u1\mathbf{u}_1 and u2\mathbf{u}_2, not just u2\mathbf{u}_2.

❌ Pitfall 3: Normalising too early

First compute the orthogonal wk\mathbf{w}_k, then normalise to get uk\mathbf{u}_k.

7. Formula Summary Table

StepFormula
First orthonormal vector$\mathbf{u}_1 = \mathbf{v}_1 / \
Orthogonal componentwk=vki=1k1vk,uiui\mathbf{w}_k = \mathbf{v}_k - \sum_{i=1}^{k-1} \langle \mathbf{v}_k, \mathbf{u}_i \rangle \mathbf{u}_i
Normalise$\mathbf{u}_k = \mathbf{w}_k / \
**QR: QQ **Columns are ui\mathbf{u}_i
**QR: RR **$r_{ii} = \

8. 📝 Practice Questions

Q1: Gram-Schmidt in ℝ²
Orthonormalise {(1,2),(3,4)}\{(1,2), (3,4)\}.
Solution: u1=(1,2)5=(15,25)\mathbf{u}_1 = \frac{(1,2)}{\sqrt{5}} = \left(\frac{1}{\sqrt{5}}, \frac{2}{\sqrt{5}}\right).
(3,4),u1=3+85=115\langle (3,4), \mathbf{u}_1 \rangle = \frac{3+8}{\sqrt{5}} = \frac{11}{\sqrt{5}}. w2=(3,4)115(15,25)=(3,4)115(1,2)=(15115,20225)=(45,25)\mathbf{w}_2 = (3,4) - \frac{11}{\sqrt{5}}\left(\frac{1}{\sqrt{5}}, \frac{2}{\sqrt{5}}\right) = (3,4) - \frac{11}{5}(1,2) = \left(\frac{15-11}{5}, \frac{20-22}{5}\right) = \left(\frac{4}{5}, -\frac{2}{5}\right).
w2=16+425=2025=25\|\mathbf{w}_2\| = \sqrt{\frac{16+4}{25}} = \sqrt{\frac{20}{25}} = \frac{2}{\sqrt{5}}. u2=(4/5,2/5)2/5=(25,15)\mathbf{u}_2 = \frac{(4/5, -2/5)}{2/\sqrt{5}} = \left(\frac{2}{\sqrt{5}}, -\frac{1}{\sqrt{5}}\right). Q2: Gram-Schmidt in ℝ³
Orthonormalise {(1,0,1),(1,1,0),(0,1,1)}\{(1,0,1), (1,1,0), (0,1,1)\}.
Solution: u1=(1,0,1)2=(12,0,12)\mathbf{u}_1 = \frac{(1,0,1)}{\sqrt{2}} = \left(\frac{1}{\sqrt{2}}, 0, \frac{1}{\sqrt{2}}\right).
(1,1,0),u1=1+0+02=12\langle (1,1,0), \mathbf{u}_1 \rangle = \frac{1+0+0}{\sqrt{2}} = \frac{1}{\sqrt{2}}. w2=(1,1,0)12(1,0,1)=(12,1,12)\mathbf{w}_2 = (1,1,0) - \frac{1}{2}(1,0,1) = \left(\frac{1}{2}, 1, -\frac{1}{2}\right). w2=14+1+14=32=62\|\mathbf{w}_2\| = \sqrt{\frac{1}{4}+1+\frac{1}{4}} = \sqrt{\frac{3}{2}} = \frac{\sqrt{6}}{2}. u2=(1/2,1,1/2)6/2=(16,26,16)\mathbf{u}_2 = \frac{(1/2, 1, -1/2)}{\sqrt{6}/2} = \left(\frac{1}{\sqrt{6}}, \frac{2}{\sqrt{6}}, -\frac{1}{\sqrt{6}}\right).
(0,1,1),u1=0+0+12=12\langle (0,1,1), \mathbf{u}_1 \rangle = \frac{0+0+1}{\sqrt{2}} = \frac{1}{\sqrt{2}}. (0,1,1),u2=0+216=16\langle (0,1,1), \mathbf{u}_2 \rangle = \frac{0+2-1}{\sqrt{6}} = \frac{1}{\sqrt{6}}.
w3=(0,1,1)12(1,0,1)16(1,2,1)\mathbf{w}_3 = (0,1,1) - \frac{1}{2}(1,0,1) - \frac{1}{6}(1,2,-1). =(0,1,1)(12,0,12)(16,13,16)= (0,1,1) - \left(\frac{1}{2}, 0, \frac{1}{2}\right) - \left(\frac{1}{6}, \frac{1}{3}, -\frac{1}{6}\right). =(01216,1013,112+16)=(23,23,23)= \left(0-\frac{1}{2}-\frac{1}{6}, 1-0-\frac{1}{3}, 1-\frac{1}{2}+\frac{1}{6}\right) = \left(-\frac{2}{3}, \frac{2}{3}, \frac{2}{3}\right).
w3=4+4+49=129=23\|\mathbf{w}_3\| = \sqrt{\frac{4+4+4}{9}} = \sqrt{\frac{12}{9}} = \frac{2}{\sqrt{3}}. u3=(13,13,13)\mathbf{u}_3 = \left(-\frac{1}{\sqrt{3}}, \frac{1}{\sqrt{3}}, \frac{1}{\sqrt{3}}\right). Q3: QR decomposition
Find the QR decomposition of
>A=[100111]>> A = \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ 1 & 1 \end{bmatrix} >
.
Solution: v1=(1,0,1)\mathbf{v}_1 = (1,0,1), u1=(1,0,1)2\mathbf{u}_1 = \frac{(1,0,1)}{\sqrt{2}}. v2=(0,1,1)\mathbf{v}_2 = (0,1,1), v2,u1=0+0+12=12\langle \mathbf{v}_2, \mathbf{u}_1 \rangle = \frac{0+0+1}{\sqrt{2}} = \frac{1}{\sqrt{2}}. w2=(0,1,1)12(1,0,1)=(12,1,12)\mathbf{w}_2 = (0,1,1) - \frac{1}{2}(1,0,1) = \left(-\frac{1}{2}, 1, \frac{1}{2}\right). w2=14+1+14=32\|\mathbf{w}_2\| = \sqrt{\frac{1}{4}+1+\frac{1}{4}} = \sqrt{\frac{3}{2}}. u2=(16,26,16)\mathbf{u}_2 = \left(-\frac{1}{\sqrt{6}}, \frac{2}{\sqrt{6}}, \frac{1}{\sqrt{6}}\right).
>Q=[12160261216]>> Q = \begin{bmatrix} \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{6}} \\ 0 & \frac{2}{\sqrt{6}} \\ \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{6}} \end{bmatrix} >
,
>R=[212032]>> R = \begin{bmatrix} \sqrt{2} & \frac{1}{\sqrt{2}} \\ 0 & \sqrt{\frac{3}{2}} \end{bmatrix} >
. Q4: Gram-Schmidt on dependent set
What happens if you apply Gram-Schmidt to {(1,2),(2,4)}\{(1,2), (2,4)\}?
Solution: u1=(1,2)5\mathbf{u}_1 = \frac{(1,2)}{\sqrt{5}}. (2,4),u1=2+85=105\langle (2,4), \mathbf{u}_1 \rangle = \frac{2+8}{\sqrt{5}} = \frac{10}{\sqrt{5}}. w2=(2,4)105(1,2)=(2,4)(2,4)=(0,0)\mathbf{w}_2 = (2,4) - \frac{10}{5}(1,2) = (2,4) - (2,4) = (0,0). w2=0\|\mathbf{w}_2\| = 0 — the algorithm fails because the set is dependent. Q5: Gram-Schmidt with different inner product
Orthonormalise {1,x}\{1, x\} in P1P_1 with p,q=01p(x)q(x)dx\langle p, q \rangle = \int_0^1 p(x)q(x) dx.
Solution: 12=011dx=1\|1\|^2 = \int_0^1 1 dx = 1, so u1=1\mathbf{u}_1 = 1.
x,1=01xdx=12\langle x, 1 \rangle = \int_0^1 x dx = \frac{1}{2}. w2=x121=x12\mathbf{w}_2 = x - \frac{1}{2} \cdot 1 = x - \frac{1}{2}. x122=01(x12)2dx=01(x2x+14)dx=1312+14=46+312=112\|x-\frac{1}{2}\|^2 = \int_0^1 (x-\frac{1}{2})^2 dx = \int_0^1 (x^2 - x + \frac{1}{4}) dx = \frac{1}{3} - \frac{1}{2} + \frac{1}{4} = \frac{4-6+3}{12} = \frac{1}{12}. x12=123\|x-\frac{1}{2}\| = \frac{1}{2\sqrt{3}}.
u2=x1/21/(23)=23(x1/2)=23x3\mathbf{u}_2 = \frac{x - 1/2}{1/(2\sqrt{3})} = 2\sqrt{3}(x - 1/2) = 2\sqrt{3}x - \sqrt{3}.
Orthonormal basis: {1,23x3}\{1, 2\sqrt{3}x - \sqrt{3}\}. Q6: QR for solving Ax=b
Using QR, solve Ax=bA\mathbf{x} = \mathbf{b} where
>A=[3212]>> A = \begin{bmatrix} 3 & 2 \\ 1 & 2 \end{bmatrix} >
,
>b=[53]>> \mathbf{b} = \begin{bmatrix} 5 \\ 3 \end{bmatrix} >
.
Solution: From Example 3, A=QRA = QR with
>Q=[3/101/101/103/10]>> Q = \begin{bmatrix} 3/\sqrt{10} & -1/\sqrt{10} \\ 1/\sqrt{10} & 3/\sqrt{10} \end{bmatrix} >
,
>R=[108/1004/10]>> R = \begin{bmatrix} \sqrt{10} & 8/\sqrt{10} \\ 0 & 4/\sqrt{10} \end{bmatrix} >
.
>QTb=[3/101/101/103/10][53]=[15+3105+910]=[1810410]>> Q^T \mathbf{b} = \begin{bmatrix} 3/\sqrt{10} & 1/\sqrt{10} \\ -1/\sqrt{10} & 3/\sqrt{10} \end{bmatrix} \begin{bmatrix} 5 \\ 3 \end{bmatrix} = \begin{bmatrix} \frac{15+3}{\sqrt{10}} \\ \frac{-5+9}{\sqrt{10}} \end{bmatrix} = \begin{bmatrix} \frac{18}{\sqrt{10}} \\ \frac{4}{\sqrt{10}} \end{bmatrix} >
.
Solve Rx=QTbR\mathbf{x} = Q^T\mathbf{b}: 10x1+810x2=1810\sqrt{10}x_1 + \frac{8}{\sqrt{10}}x_2 = \frac{18}{\sqrt{10}} 410x2=410x2=1\frac{4}{\sqrt{10}}x_2 = \frac{4}{\sqrt{10}} \Rightarrow x_2 = 1 10x1+810=181010x1=1010x1=1\sqrt{10}x_1 + \frac{8}{\sqrt{10}} = \frac{18}{\sqrt{10}} \Rightarrow \sqrt{10}x_1 = \frac{10}{\sqrt{10}} \Rightarrow x_1 = 1. Solution: x=(1,1)\mathbf{x} = (1,1). Q7: Orthogonal basis for a plane
Find an orthonormal basis for W={(x,y,z)x+y+z=0}W = \{(x,y,z) \mid x + y + z = 0\}.
Solution: Find any basis. Let x=1,y=0z=1x = 1, y = 0 \Rightarrow z = -1: v1=(1,0,1)\mathbf{v}_1 = (1,0,-1). Let x=0,y=1z=1x = 0, y = 1 \Rightarrow z = -1: v2=(0,1,1)\mathbf{v}_2 = (0,1,-1).
Apply Gram-Schmidt: u1=(1,0,1)2\mathbf{u}_1 = \frac{(1,0,-1)}{\sqrt{2}}.
(0,1,1),u1=0+0+12=12\langle (0,1,-1), \mathbf{u}_1 \rangle = \frac{0+0+1}{\sqrt{2}} = \frac{1}{\sqrt{2}}. w2=(0,1,1)12(1,0,1)=(12,1,12)\mathbf{w}_2 = (0,1,-1) - \frac{1}{2}(1,0,-1) = \left(-\frac{1}{2}, 1, -\frac{1}{2}\right). w2=14+1+14=32\|\mathbf{w}_2\| = \sqrt{\frac{1}{4}+1+\frac{1}{4}} = \sqrt{\frac{3}{2}}. u2=(16,26,16)\mathbf{u}_2 = \left(-\frac{1}{\sqrt{6}}, \frac{2}{\sqrt{6}}, -\frac{1}{\sqrt{6}}\right). Q8: Projection using QR
Project b=(1,2,3)\mathbf{b} = (1,2,3) onto the column space of AA from Q3 using QR.
Solution: From Q3, proj=QQTb\text{proj} = QQ^T\mathbf{b}.
>QTb=[1/201/21/62/61/6][123]=[1+321+4+36]=[4266]=[226]>> Q^T\mathbf{b} = \begin{bmatrix} 1/\sqrt{2} & 0 & 1/\sqrt{2} \\ -1/\sqrt{6} & 2/\sqrt{6} & 1/\sqrt{6} \end{bmatrix} \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix} = \begin{bmatrix} \frac{1+3}{\sqrt{2}} \\ \frac{-1+4+3}{\sqrt{6}} \end{bmatrix} = \begin{bmatrix} \frac{4}{\sqrt{2}} \\ \frac{6}{\sqrt{6}} \end{bmatrix} = \begin{bmatrix} 2\sqrt{2} \\ \sqrt{6} \end{bmatrix} >
.
>proj=Q(22,6)T=22[1/201/2]+6[1/62/61/6]=[202]+[121]=[123]>> \text{proj} = Q(2\sqrt{2}, \sqrt{6})^T = 2\sqrt{2}\begin{bmatrix} 1/\sqrt{2} \\ 0 \\ 1/\sqrt{2} \end{bmatrix} + \sqrt{6}\begin{bmatrix} -1/\sqrt{6} \\ 2/\sqrt{6} \\ 1/\sqrt{6} \end{bmatrix} = \begin{bmatrix} 2 \\ 0 \\ 2 \end{bmatrix} + \begin{bmatrix} -1 \\ 2 \\ 1 \end{bmatrix} = \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix} >
.
Interesting — b\mathbf{b} is already in C(A)C(A)! Check: A(1,1)=(1,0,1)+(0,1,1)=(1,1,2)A(1,1) = (1,0,1)+(0,1,1) = (1,1,2). Wait, that doesn't give (1,2,3). Let me recheck...
Actually (1,2,3)(1,2,3) is in C(A)C(A):
>A=[100111]>> A = \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ 1 & 1 \end{bmatrix} >
. Solve Ax=(1,2,3)A\mathbf{x} = (1,2,3): x=1x=1, y=2y=2, 1+2=31+2=3 ✓. So b\mathbf{b} is indeed in C(A)C(A) and projection = itself. Q9: Orthogonal polynomials
Apply Gram-Schmidt to {1,x,x2}\{1, x, x^2\} on [1,1][-1,1] with f,g=11f(x)g(x)dx\langle f,g \rangle = \int_{-1}^1 f(x)g(x) dx.
Solution: 12=111dx=2\|1\|^2 = \int_{-1}^1 1 dx = 2, u1=12\mathbf{u}_1 = \frac{1}{\sqrt{2}}.
x,1=11xdx=0\langle x, 1 \rangle = \int_{-1}^1 x dx = 0 (odd). w2=x0=x\mathbf{w}_2 = x - 0 = x. x2=11x2dx=23\|x\|^2 = \int_{-1}^1 x^2 dx = \frac{2}{3}, u2=x2/3=32x\mathbf{u}_2 = \frac{x}{\sqrt{2/3}} = \sqrt{\frac{3}{2}}x.
x2,1=11x2dx=23\langle x^2, 1 \rangle = \int_{-1}^1 x^2 dx = \frac{2}{3}. x2,x=11x3dx=0\langle x^2, x \rangle = \int_{-1}^1 x^3 dx = 0. w3=x22/3210=x213\mathbf{w}_3 = x^2 - \frac{2/3}{2} \cdot 1 - 0 = x^2 - \frac{1}{3}. x2132=11(x423x2+19)dx=2549+29=2529=181045=845\|x^2 - \frac{1}{3}\|^2 = \int_{-1}^1 (x^4 - \frac{2}{3}x^2 + \frac{1}{9}) dx = \frac{2}{5} - \frac{4}{9} + \frac{2}{9} = \frac{2}{5} - \frac{2}{9} = \frac{18-10}{45} = \frac{8}{45}. u3=x21/38/45=458(x213)\mathbf{u}_3 = \frac{x^2 - 1/3}{\sqrt{8/45}} = \sqrt{\frac{45}{8}}(x^2 - \frac{1}{3}).
These are (up to scaling) the Legendre polynomials: P0=1P_0=1, P1=xP_1=x, P2=12(3x21)P_2=\frac{1}{2}(3x^2-1). Q10: QR and least squares
Why is QR useful for least squares?
Solution: The least squares solution to AxbA\mathbf{x} \approx \mathbf{b} (when AA is full column rank) solves ATAx=ATbA^T A \mathbf{x} = A^T \mathbf{b}. With A=QRA = QR where QQ has orthonormal columns: ATA=RTQTQR=RTRA^T A = R^T Q^T Q R = R^T R (since QTQ=IQ^T Q = I). ATb=RTQTbA^T \mathbf{b} = R^T Q^T \mathbf{b}. So RTRx=RTQTbRx=QTbR^T R \mathbf{x} = R^T Q^T \mathbf{b} \Rightarrow R\mathbf{x} = Q^T\mathbf{b}. This triangular system is easy to solve by back substitution — no need to form ATAA^T A!

🔗 Cross-References

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.