Lecture 3 · Linear Algebra III · September 16
The Closest Reachable Vector
From Exact Solutions to Best Approximations
$$Ax=x_1a_1+\dots+x_na_n$$
$A\in\R^{m\times n}$ choose $x\in\R^n$ — parameter space
$a_j,Ax,b\in\R^m$ compare here — output space
Exact solution iff $b\in\Col(A)$.
What if the target is outside the reachable space?
Mathematics for Robotics · ROB-GY 6013 · NYU Tandon · Jing Zhang · Fall 2026
Vote
The Closest Reachable Vector
Which Reachable Vector Would You Choose?
Which point on the line is closest to $b$?
A $(0,0)$
B $(1,1)$
C $(2,2)$✓
D $(3,3)$
$C$: $1^2+1^2=2$, so $d=\sqrt2$.
At $C$, what angle does the orange error segment make with the line?
0
1
2
3
4
5
−1
0
1
2
3
span{a}
d = 1
d = √2
d = 2
A
B
C
D
b
Definition
The Closest Reachable Vector
Difference, Norm, Squared Norm
So far: representable? unique? — closest needs a distance.
$$\begin{aligned}r&=u-v\\\|r\|_2^2&=r\T r=\sum_{i=1}^{m}r_i^2\\d(u,v)&=\|u-v\|_2=\sqrt{r\T r}\end{aligned}$$
$u,v,r\in\R^m$ $r$ = difference vector
$\|r\|_2$ a number $\ge0$; $=0$ iff $r=0$
$\|r\|_2^2$ a number too, no square root
4
3
u
v
r
r = (−3, 4)
‖r‖² = (−3)² + 4² = 25
‖r‖ = √25 = 5
Predict
The Closest Reachable Vector
Does Squaring Move the Best Choice?
Candidates $y=(t,t)$ on the same line, $d(t)=\|b-y\|_2$.
We minimise $d^2$ instead of $d$. Does the best $t$ move?
A yes
B no✓
Same argmin, different min: $\min d=\sqrt2$, $\min d^2=2$. Squaring is strictly increasing on $[0,\infty)$, so it keeps the order of distances.
1
2
3
4
1
3
5
t
d
d²
t = 2
√2
2
The Closest Reachable Vector
Today’s Roadmap
parameter space ℝⁿ
x
A
output space ℝᵐ
schematic
Col(A)
Ax
b
b − Ax
Find the best output first, then find parameters that produce it; the error is always measured in output space.
1 Judge orthogonality
2 Compute a projection
3 Set up least squares
4 Gram–Schmidt and QR
5 A robot step
Definition
Orthogonality and Orthonormal Bases
The Euclidean Inner Product
$$u\T v=\sum_{i=1}^{m}u_iv_i$$
$u,v\in\R^m$ real; $u\T v$ is a number, not a vector
Lecture 2 wrote $\langle u,v\rangle$
$$\begin{aligned}u\T v&=v\T u\\(c_1u+c_2u')\T v&=c_1u\T v+c_2u'\T v\end{aligned}$$
symmetry each $u_iv_i=v_iu_i$
linear $u'\in\R^m$ any other vector, $c_1,c_2$ scalars; slot 2 by symmetry
u v u i v i 1 × 3 = 3 2 × −1 = −2 u T v = 1
Tuples denote columns.
Orthogonality and Orthonormal Bases
From Inner Product to Length
$$\|u\|^2=u\T u=\sum_{i=1}^{m}u_i^2\ \ge0$$
$=0$ iff $u=0$ each term is a square, so $0$ forces every $u_i=0$
same norm the distance $\|r\|_2$, with $r$ for $u$
$$\|u\|=\sqrt{u\T u},\qquad \left\|\frac{u}{\|u\|}\right\|=1$$
$\|u\|$ the Euclidean length, a number
unit vector $\|u\|=1$; dividing by $\|u\|$ needs $u\neq0$
u₁ = 3 u₂ = 4 u u/‖u‖ ‖u‖² = 9 + 16 = 25 ‖u‖ = 5
Orthogonality and Orthonormal Bases
The Dot Product Measures Angle
$$u\T v=\|u\|\,\|v\|\cos\varphi$$
$\varphi\in[0,\pi]$ the angle between nonzero $u,v$; no angle if one is $0$, and then $u\T v=0$
why a rotation $R$ keeps $u\T v$; turn both by $R$ with $Ru=\|u\|e_1$: $u\T v=\|u\|(Rv)_1$
sign $\|u\|\|v\|>0$, so only $\cos\varphi$ can turn it
$\varphi<90^\circ$ $u\T v>0$
$\varphi=90^\circ$ $u\T v=0$
$\varphi>90^\circ$ $u\T v<0$
Orthogonality and Orthonormal Bases
The Signed Shadow
$$s=\frac{u\T v}{\|u\|}=\|v\|\cos\varphi$$
$s$ a number ($u\neq0$): the signed component of $v$ along the unit direction of $u$
$\|v\|\cos\varphi$ also needs $v\neq0$: no angle when $v=0$, though $s=0$
divisor $\|u\|$, never $\|v\|$ — measured along $u$
$|s|$ the shadow's length; $s>0$ same side as $u$, $s<0$ opposite, $s=0$ perpendicular
Vote · all that apply
Orthogonality and Orthonormal Bases
Predict the Sign
Which have a positive dot product with $u=(1,0)$?
A $v_A=(2,1)$✓
B $v_B=(0,3)$
C $v_C=(-1,2)$
D $v_D=(1,-3)$✓
$v_D$ points down: why still positive?
Longer vector, bigger dot product?
$v_D$: $u\T v_D=1>0$ with $\|v_D\|=\sqrt{10}$. $v_B$: $\|v_B\|=3$, $u\T v_B=0$. Sign follows $\varphi$: acute $+$, right $0$, obtuse $-$.
−2 −1 0 1 2 3 −3 −2 −1 0 1 2 3
A B C D
A B C D
u
Orthogonality and Orthonormal Bases
Orthogonality and the Pythagorean Theorem
$$u\perp v\iff u\T v=0$$
$\perp$ orthogonal: dot product zero
$0\T v=0$ so $0\perp$ every $v$ (no angle defined)
$$\|u+v\|^2=\|u\|^2+2\,u\T v+\|v\|^2$$
why expand $(u+v)\T(u+v)$ by linearity
$2\,u\T v$ cross term: $0$ iff $u\perp v$
Worked example
$u=(2,1)$, $v=(-1,2)$: $u\T v=-2+2=0$, so $\|(1,3)\|^2=10=5+0+5$.
u ‖u‖² = 5 v ‖v‖² = 5 u + v ‖u + v‖² = 10
Definition
Orthogonality and Orthonormal Bases
Orthogonal to a Whole Subspace
$$r\perp S\iff r\T y=0\ \text{ for every }y\in S$$
$S\subseteq\R^m$ a subspace; $y$ is every vector of it
$r\T y$ one number for each $y$ in $S$
$$S^\perp=\{r\in\R^m:\ r\T y=0\ \ \forall y\in S\}$$
a subspace $0\in S^\perp$; $(c_1r_1+c_2r_2)\T y=0$ too, by linearity
edges $\{0\}^\perp=\R^m$, $(\R^m)^\perp=\{0\}$: $r\T r=0\Rightarrow r=0$
y r S schematic
Vote
Orthogonality and Orthonormal Bases
Perpendicular to a Line, or to the Plane?
$d_1=(1,0,0)$, $d_2=(0,1,0)$, $S=\text{span}\{d_1,d_2\}$, $r=(0,1,1)$
$r\perp d_1$. Which is true?
A $r\perp S$
B $r/\|r\|\perp S$
C $r\not\perp S$: $r\T d_2=1$✓
D $r\T d_1=0$ gives $r\perp S$
$r\T d_2=1\neq0$, $d_2\in S$: $r\notin S^\perp$. $w=(0,0,1)$ passes both: $w\T d_1=w\T d_2=0$.
d₁ d₂ r S = span{d₁, d₂} 3D view: trust the number rᵀd₂ = 1 w
Orthogonality and Orthonormal Bases
Testing a Spanning Set Is Enough
$$r\T y=\sum_{i=1}^k c_i\,(r\T d_i)$$
$y∈S$ $S=\text{span}\{d_1,…,d_k\}$, so $y=\sum c_id_i$
$k$ tests settle every $y$: $r\T y$ is linear in $y$
span only independence not needed
Worked example
From the vote: $y=d_1+d_2$ gives $r\T y=1$, $w\T y=0$; $d_1$ alone misses it.
$r\perp S ⇔ r\T d_i=0$ for every $i$.
d₁ d₂ r S = span{d₁, d₂} rᵀd₂ = 1 y = d₁ + d₂ w
Orthogonality and Orthonormal Bases
The Four Fundamental Subspaces Revisited
$A\T r=(a_1\T r,…,a_n\T r)\T∈ℝ^n$, so $r\perp\text{Col}(A)⇔A\T r=0$.
$$\text{Col}(A)^⟂=\text{Null}(A\T)⊆ℝ^m,\qquad\text{Null}(A)=\text{Row}(A)^⟂⊆ℝ^n$$
$a_j$ columns of $A∈ℝ^{m×n}$: they span $\text{Col}(A)$
input apply the same definitions to $A\T$
ℝⁿ · parameters Row(A) · rank Null(A) · n − rank ⊥ ℝᵐ · outputs Col(A) · rank Null(Aᵀ) · m − rank ⊥
Strang, G. MIT 18.06 Linear Algebra , Lecture 14, orthogonal vectors and subspaces. MIT OpenCourseWare, 2010.
Sort
Orthogonality and Orthonormal Bases
Orthogonal Is Not the Same as Orthonormal
$$q_i\T q_j=\delta_{ij}$$
$\delta_{ij}$ $1$ if $i=j$ (unit), else $0$ (orthogonal)
Each pair is a basis. Sort:
A independent only
B orthogonal, not unit
C orthonormal
1 1 1 B 1 1 2 C 1 1 3 A
Orthogonality and Orthonormal Bases
Right Angles, Unit Lengths, Independence
right angles
$$\sum_i c_iv_i=0\ ⇒\ v_j\T\!\sum_i c_iv_i=c_j\|v_j\|^2=0$$
$v_i$ pairwise $\perp$, nonzero: $\|v_j\|^2>0$
all $j$ $c_j=0$: independent
fails drop nonzero: $0\perp$ all
unit lengths
Not for independence; with $\perp$: $v=\sum c_iv_i⇒c_j=v_j\T v$.
Orthonormal = both. Nonzero right angles $⇒$ independent, not conversely.
orthogonal orthonormal 1
Vote · all that apply
Orthogonality and Orthonormal Bases
What Does $Q\T Q=I$ Actually Mean?
For $Q=\begin{bmatrix}1&0\\0&1\\0&0\end{bmatrix}$, which are true?
A $Q\T Q=I_2$✓
B $QQ\T=I_3$QQᵀ = diag(1,1,0)
C $\|Qz\|=\|z\|$ for every $z\in\R^2$✓
D $Q\T v$ keeps all of any $v\in\R^3$v₃ is lost
Which $b'$ have $Q\T b'=Q\T b$?
Col(Q) x y z
lost (0, 0, 2)
QQᵀv
ℝ² Qᵀv = (2, 1) Qᵀ Q
v = (2, 1, 2) ℝ³
Orthogonality and Orthonormal Bases
Q Embeds, $Q\T$ Extracts
$Q$ embeds
$$\|Qz\|^2=z\T Q\T Qz=\|z\|^2$$
$Q$ $m×k$, columns $q_i$, $Q\T Q=I_k$; $S=\text{Col}(Q)$
$z∈ℝ^k$ $Qz∈ℝ^m$: lengths, angles kept
$Q\T$ extracts
$(Q\T b)_i=q_i\T b$: coordinates of the projection.
Full orthonormal basis Orthonormal basis of a proper subspace
$Q\T Q$ $I_m$ $I_k$
$QQ\T b$ $b$ projection
recover $b$ yes iff $b∈S$
$Q\T$ loses $b$'s $S^⟂$ component.
Orthogonal Projection
The Residual Must Be Perpendicular
$$r=b-p,\qquad p=\alpha a$$
$b$ the target in $\R^m$, off the line
$p=\alpha a$ a candidate; $\alpha$ is our only choice
$r$ what $p$ fails to explain
$$\text{lowest }\|b-\alpha a\|^2\ \Rightarrow\ a\T r=0$$
$a\T r\neq0$ $r$ keeps a part along the line: removable, so $p$ is not lowest
$a\T r=0$ nothing left along the line — why is that enough?
Definition
Orthogonal Projection
Solving the Perpendicularity Equation
$a\neq0$, $b\in\R^m$. Candidate on span$\{a\}$: $p=\alpha a$
Ask for a perpendicular residual: $a\T(b-\alpha a)=0$
Expand: $a\T b-\alpha\,a\T a=0$ — one equation, one unknown
$$\alpha=\frac{a\T b}{a\T a},\qquad p=\alpha a$$
$\alpha$ a number: how many copies of $a$
$p$ a vector in $\R^m$
$a\T a$ $=\|a\|^2>0$ as $a\neq0$; $a=0$: no line
a
r
p = αa
b
0
1
α
a number
Strang. MIT 18.06 , L15 projections onto subspaces. MIT OpenCourseWare, 2010.
Orthogonal Projection
The Same Projection as a Matrix
Substitute $\alpha$ back: the same $p$, now one map.
$$p=a\,\frac{a\T b}{a\T a}=\frac{aa\T}{a\T a}\,b$$
$a\T b$ $1\times m$ by $m\times1$: a number
$aa\T$ $m\times1$ by $1\times m$: $m\times m$, rank 1 if $a\neq0$, symmetric
$a=0$ divisor $0$: quotient undefined
Types: $\alpha$ number ·
$p$ vector · $\dfrac{aa\T}{a\T a}$ matrix
a
m × 1
×
aᵀ
1 × m
=
aaᵀ
m × m, rank 1
aᵀ
×
a
=
aᵀa, a number
Pair · predict then compute
Orthogonal Projection
Compute and Check the Projection
Alone, no arithmetic: which way does $r$ point from $p$ to $b$, and is $\alpha$ above or below 1?
Then in pairs: $\alpha$, $p$, $r$, check $r$.
1 $\alpha$ $=\dfrac{a\T b}{a\T a}=\dfrac{4}{2}=2$
2 $p$ $=\alpha a=(2,2)$
3 $r$ $=b-p=(1,-1)$
check $a\T r=1-1=0,\ \|r\|^2=2$
1
2
3
4
1
2
3
a
α = 2
p = (2, 2)
r = (1, −1)
aᵀr = 0
b
Vote
Orthogonal Projection
Does Rescaling the Basis Change the Projection?
Replace $a$ by $\lambda a$, $\lambda>0$. What happens to $a\T b$, $\alpha$, $p$?
A $a\T b$ ×λ , $\alpha$ ÷λ , $p$ same✓
B all the same
C $a\T b$ ×λ , $\alpha$ ×λ , $p$ ×λ 2
D $a\T b$ same, $\alpha$ ÷λ , $p$ same
$a\T b$ grew, $p$ did not. Why?
$a\T b=\|a\|s$ grows with the ruler; $p=\dfrac{\lambda^2aa\T}{\lambda^2a\T a}b$ needs only the line.
Orthogonal Projection
Component, Coefficient, Projection
$a\neq0$ $\lambda a,\ \lambda>0$
$s=a\T b/\|a\|$ signed shadow same
$\alpha=a\T b/\|a\|^2$ copies of $a$ ÷λ
$p=\alpha a$ vector in $\R^m$ same
Unit $a$: $s=\alpha$, the coordinate of Lecture 2; else equal only if $a\T b=0$.
Worked example
$a=(3,4)$, $b=(5,0)$: $a\T b=15$, $\|a\|=5$, $s=3$, $\alpha=3/5$, $p=(9/5,12/5)$, $r=(16/5,-12/5)$, $a\T r=0$
1
2
3
4
5
1
2
3
4
a
α = 3/5
p = αa
r
b
s = 3
Orthogonal Projection
Split the Error at Any Candidate
Why is a perpendicular residual enough to make $p$ the closest point?
Premise: $S$ any subspace, $p\in S$, $r=b-p\in S^\perp$. Take any other $y\in S$.
$$b-y=(b-p)+(p-y)$$
$p-y$ lies in $S$: a subspace is closed under subtraction
$b-p$ lies in $S^\perp$, so $(b-p)\T(p-y)=0$
right angle the two pieces are the legs, $b-y$ the hypotenuse
Orthogonal Projection
Yes: the Perpendicular Test Is Enough
Yes. Take squared lengths on that right triangle.
$$\|b-y\|^2=\|r\|^2+\|p-y\|^2\ \ge\ \|r\|^2$$
$\|r\|^2$ unavoidable: it does not depend on $y$
$\|p-y\|^2$ the extra, $\ge0$, zero only at $y=p$
Optimal · every $y\neq p$ adds a positive square
Unique · nothing else ties $p$
Built for a line; a general $S$ still needs a construction.
Orthogonal Projection
A Candidate That Is Not Yet Best
An illustration of the converse: a residual still leaning along $S$.
$$\|(b-y)-\tau\|^2=\|b-y\|^2-\|\tau\|^2$$
$\tau$ the orthogonal projection of $b-y$ onto the line; step to $y+\tau\in S$
$b-y-\tau$ the perpendicular part, untouched
why Pythagoras: $\tau\perp(b-y-\tau)$
At $\alpha=1$: $b-y=(2,0)$, $\tau=(1,1)$; at $y+\tau=p$: $4-2=2$, nothing left to improve.
Definition
Orthogonal Projection
The Projection Theorem
$S⊆\R^m$ a subspace: each $b∈\R^m$ splits one way only, and that $p$ is closest.
$$b=p+r,\qquad p∈S,\quad r∈S^\bot$$
unique $p+r=p'+r'⇒p-p'=r'-r∈S∩S^\bot=\{0\}$ (⊥ itself)
closest proved, for any $y∈S$
exists construction follows, from an orthonormal basis $Q$
edges $b∈S⇒r=0$; $b∈S^\bot⇒p=0$
Lecture 1 $S=$Col$(A)$: $b=\hat b+r$, $r∈$Null$(A\T)$, dims add
S⊥
S
0
p
r
b
schematic
Orthogonal Projection
Projection onto a Subspace: $p=QQ\T b$
Q = 1 0
0 4/5
0 3/5 b = 2
1
2
$Q∈\R^{m×k}$ with $Q\T Q=I_k$: columns $q_i$ orthonormal, spanning $S$.
$$c=Q\T b∈\R^k,\qquad p=Qc=QQ\T b$$
extract $c_i=q_i\T b$: the part of $b$ along $q_i$
rebuild $p=c_1q_1+\dots+c_kq_k∈S$
$c$ the coordinates of $p$; of $b$ too iff $b∈S$
sizes $m×k$ times $\R^k$: $p∈\R^m$
Worked example
$Q\T b=(2,2)$, $p=(2,8/5,6/5)$
S
1 1 2 2 Qᵀb ℝ²
2q₁ 2q₂ p
q₁
q₂
b
Orthogonal Projection
Checking the Two Requirements
Q = 1 0
0 4/5
0 3/5 b = 2
1
2
Both requirements, one at a time.
1. $p∈S$: $p=Q(Q\T b)$, $Q$ times a vector of $\R^k$.
$$Q\T(b-p)=Q\T b-(Q\T Q)Q\T b=0$$
2. $b-p$ ⊥ each $q_i$ ⇒ ⊥ $S$ (spanning test) ⇒ $p$ is the closest point
needs $Q\T Q=I_k$; a general basis $A$ needs a correction factor, not plain $AA\T$
here $r=(0,-3/5,4/5)$: $q_1\T r=0$, $q_2\T r=-12/25+12/25=0$
S
q₁
q₂
p
r
b
Vote
Orthogonal Projection
Does Moving b Out of the Plane Change the Prediction?
Q = 1 0
0 4/5
0 3/5 b = 2
1
2
Same $S$ and $b$. Add $w=(0,-3,4)$, ⊥ $q_1$ and $q_2$. For $b+w=(2,-2,6)$:
A projection changes, residual same
B projection same, residual changes✓
C both stay the same
D both change
$Q\T w=0⇒QQ\T(b+w)=QQ\T b$; $r$ becomes $r+w$. Same for every $w∈S^\perp$ (Null$(A\T)$ if $S=$ Col$(A)$). $τ∈S$: $QQ\T(b+τ)=p+τ$, $r$ same.
Vote
Orthogonal Projection
Which Matrix Is an Orthogonal Projector?
Each of these flattens the plane onto the axis. Which sends every $v$ to its orthogonal projection? On $v=(1,2)$: does a second pass move $Pv$? Is the discarded direction ⊥ the axis?
A 1 0 0 0 ✓
B 1 1 0 0
C 2 0 0 0
A discards $e_2$, ⊥ the axis. B discards $(1,-1)$: oblique, though $P_B^2=P_B$. C $P(Pv)=(4,0)≠Pv$. The ⊥ residual decides; idempotence alone is not enough.
Definition
Orthogonal Projection
What the Projection Matrix Does
Orthogonal projector onto $S$: a matrix $P$ with $Pb∈S$ and $b-Pb∈S^\bot$ for every $b∈\R^m$ (the two requirements checked).
$$P=QQ\T∈\R^{m×m},\qquad Pb=p$$
why $QQ\T$ passes both; the closest point is unique
size $Q$ is $m×k$: $P$ is $m×m$, rank $k$, symmetric
unique any orthonormal basis of $S$ gives the same $P$
edges $S=\{0\}$: $P=0$; $S=\R^m$: $P=I$
S
0
b
Pb
b′
Pb′
Orthogonal Projection
Applying It Twice Changes Nothing
$$P^2=Q(Q\T Q)Q\T=QQ\T=P$$
reason $Pb∈S$, and the closest point of $S$ to a point of $S$ is itself
reads $P(Pb)=Pb$ for every $b$: the second pass moves nothing
uses $Q\T Q=I_k$, nothing else
$P^2=P$ alone means a projection, not necessarily orthogonal: the vote's $P_B$ is idempotent, yet $(1,-1)$, the direction it discards, is not ⊥ the axis.
S
0
v
orthogonal
oblique
(1, −1)
Orthogonal Projection
Symmetry Is the Missing Half
$$P\T=(QQ\T)\T=QQ\T=P$$
why $(UV)\T=V\T U\T$, $(Q\T)\T=Q$
so far $QQ\T$: symmetric, idempotent
$P\T=P=P^2$ ⇔ orthogonal projector onto Col$(P)$
(⇒) $Pb∈$ Col$(P)$; $P\T(b-Pb)=P(b-Pb)=Pb-P^2b=0$: $b-Pb∈$ Col$(P)^\perp$
(⇐) $P$ fixes Col$(P)$: $P^2=P$. Any $a,b$: $a\T Pb=(Pa)\T Pb$ [$a-Pa⟂Pb$] $=(Pa)\T b$ [$b-Pb⟂Pa$] $=a\T P\T b$: $P\T=P$
vote: $P_B\neq P_B\T$, $P_C^2\neq P_C$
Orthogonal Projection
What P Keeps and What It Discards
$$(I-P)\T=I-P,\qquad (I-P)^2=I-2P+P^2=I-P$$
$I-P$ orthogonal projector onto $S^\bot$: $Q\T(I-P)b=0$, $P(I-P)=0$
$b=p+r$ $Pp=p$, $Pr=0$
$λ$ 1 on kept $p≠0$, 0 on discarded $r≠0$ (Lecture 2)
$λ=0$ $P$ singular: $P(b+w)=Pb$ for $w∈S^\bot$, so $Pb$ does not determine the $S^\bot$ part of $b$
edges $P=0$: no $λ=1$; $P=I$: no $λ=0$
S⊥
S
b
Pp = p, λ = 1
Pr = 0, λ = 0
Least Squares
Three Measurements, Two Unknowns
Model $y\approx\beta_0+\beta_1t$ at inputs $t_i$.
1
0
1
1
1
2
β₀
β₁
≈
1
2
2
all ones · β₀, the shared height
the inputs tᵢ · β₁, the slope
$A\in\R^{3\times2}$ $m=3$ readings, $n=2$ parameters
$x=(\beta_0,\beta_1)$ intercept and slope, the unknowns
$b$ the readings $y_i$, one per input $t_i$
$b\notin$ Col$(A)$ no exact $x$
Vote
Least Squares
Which Errors Are We Minimizing?
For $y_i\approx\beta_0+\beta_1t_i$, which errors does ordinary least squares minimize?
1 2 1 2
A
1 2 1 2
B
1 2 1 2
C
A vertical distances, squared✓
B shortest distances, squared
C horizontal distances, squared
Model: $t_i$ exact, all error in $y_i$, so $r_i$ = reading − model at $t_i$: vertical. Stacked, one arrow in $\R^3$: at the best fit $r=b-A\hat x\perp$ Col$(A)$.
Least Squares
The Objective and Its Objects
$$r=b-Ax,\qquad f(x)=\|Ax-b\|_2^2=\|r\|_2^2$$
$x\in\R^n$ the parameters $(\beta_0,\beta_1)$ we choose
$Ax,b,r\in\R^m$ prediction, readings, residual: measurement space
$f(x)$ one number, $\ge0$; any $A$, no rank assumption
$|r_i|$ the side of square $i$ — a side cannot be negative
$e=-r$ Lecture 5 writes $e=Ax-b$
$cf$, $c>0$ same minimiser, gradient $\times c$
Least Squares
Minimum and Minimiser
schematic
one bottom
a flat valley
both in parameter space ℝⁿ
$$\min_x f(x)\in\R,\qquad \hat x\in\arg\min_x f(x)\subseteq\R^n$$
$\min$ the smallest value $f$ reaches — one number (ours: p53)
$\arg\min$ the set of $x$ reaching it: one point or many
$\hat x$ any member of that set; any $A$, any rank
The best output $A\hat x$ is always unique; the best parameter vector $\hat x$ need not be.
Match · pairs
Least Squares
Fitting Is Projection in Measurement Space
What kind of object is each, a line, a point or a plane, and in which space?
A the numbers $(\beta_0,\beta_1)$point in ℝ² ②
B $Ax$point in ℝ³ ③
C the candidate lineline in the (t, y) plot ①
D every possible $Ax$plane in ℝ³ ④
Vote
Least Squares
Perpendicular Columns: Which Gram Entries Change?
From Lecture 1: for $G=A\T A$ with columns $a_1,a_2$, the entry is $G_{ij}=a_i\T a_j$.
$a_2$ is turned until perpendicular to $a_1$ and then doubled in length. What happens to $G_{11},G_{12},G_{22}$?
A unchanged, $0$, $\times4$✓
B $1$, $0$, $1$
C unchanged, $0$, $\times2$
D $0$, unchanged, $\times4$
Definition
Least Squares
The Gram Matrix
$$G=A\T A\in\R^{n\times n},\qquad G_{ij}=a_i\T a_j$$
$a_j$ column $j$ of $A\in\R^{m\times n}$ — any $A$, any rank
$G_{ij}$ row $i$, column $j$: column $i$ dotted with column $j$
$G\T=G$ symmetric, because $a_i\T a_j=a_j\T a_i$
$n$ the number of parameters, not of measurements
Worked example
$a_1=(1,1,1)$, $a_2=(0,1,2)$
G =
a₁ᵀa₁ 1+1+1 = 3
a₁ᵀa₂ 0+1+2 = 3
a₂ᵀa₁ 3
a₂ᵀa₂ 0+1+4 = 5
Boyd, S. and Vandenberghe, L. Introduction to Applied Linear Algebra , least squares. Cambridge, 2018.
Least Squares
Reading the Entries
schematic
φ
‖a₁‖
‖a₂‖
G =
‖a₁‖²
‖a₁‖‖a₂‖cos φ
‖a₁‖‖a₂‖cos φ
‖a₂‖²
$$G_{ii}=\|a_i\|^2,\qquad G_{ij}=\|a_i\|\,\|a_j\|\cos\varphi$$
$G_{ii}$ squared length of column $i$
$G_{ij}$ lengths and angle at once (p8)
$\varphi$ between $a_i,a_j$, both $\neq0$
Large $|G_{ij}|$ alone does not imply near-parallel columns. $G=I$ exactly for orthonormal columns, singular exactly for dependent ones (p55).
Break
10 minutes
10 min
The Gram matrix records every dot product between two columns of $A$.
Which equations does it give for the best-fit parameters?
For our three readings: $G=A\T A=\begin{bmatrix}3&3\\3&5\end{bmatrix}$
Least Squares
The Normal Equations Are Necessary
Necessary
If $\hat x$ minimises, $r=b-A\hat x\perp$ Col$(A)$ (p29)
$\perp$ Col$(A)$ $\Leftrightarrow$ $a_i\T r=0$ for every column (p14)
so $A\T r=0$: $r\in$ Null$(A\T)$ (p15)
$$A\T(b-A\hat x)=0\Rightarrow\boxed{A\T A\hat x=A\T b}$$
$A\T A$ $n\times n$, any $A$; $A\T b\in\R^n$
necessary every minimiser solves it; the converse: p50–51
schematic
Col(A)
a₁
a₂
r
Ax̂
b
a₁ᵀr = 0
a₂ᵀr = 0
Least Squares
Reading the n Equations
$$a_i\T(A\hat x)=\sum_j(a_i\T a_j)\hat x_j=a_i\T b$$
row $i$ what column $i$ measures is matched; the leftover is invisible to it
$n\times n$ $n$ equations, $n$ unknowns, any $A$; solvable: take $Ax=\hat b$; $A\T(b-\hat b)=0$ (p29); only one? p54
Move $b$ by any $w\in$ Null$(A\T)=$ Col$(A)^\perp$ (p15): $A\T b$, and the equations, do not change (p32).
schematic
aᵢ
0
same shadow
r
Ax̂
b
w
b+w
Vote · all that apply
Least Squares
What Changes Along the Valley?
$A$ is $3\times2$, all ones; $b=(1,2,3)$. Move $x$ along $z=(1,-1)$. Which change?
A parameters $x$✓
B prediction $Ax$A(x+z) = Ax
C residual $r=b-Ax$Ax fixed
D objective $f=\|Ax-b\|^2$f = ‖r‖²
Steps leaving $Ax$ fixed are exactly Null$(A)=$ span$\{(1,-1)\}$: dependent columns leave least squares solvable — minimisers fill $(1,1)+$Null$(A)$, one $\hat b$.
Predict
Least Squares
Are the Normal Equations Enough?
$\hat x$ solves $A\T A\hat x=A\T b$. For every $A$, which is guaranteed? $\hat x$ is…
A a global minimiser✓
B flat here, but lower somewhere elsenever lower: p51
C the only minimiserexactly when Null(A)={0}
A, for every $A$: nothing gets below $\|r\|^2$. C is conditional, not false — it needs Null$(A)=\{0\}$ (p54), and p49 had a line of ties.
Least Squares
Why They Are Enough
Sufficient
Take any other $\hat x+z$:
$$A(\hat x+z)-b=Az-r$$
$z\in\R^n$ any step in parameter space; $r=b-A\hat x$
$$\|Az-r\|^2=\|Az\|^2-2z\T(A\T r)+\|r\|^2$$
cross term $A\T r=0$ is the equation $\hat x$ solves, so it is $0$
$$\|A(\hat x+z)-b\|^2=\|r\|^2+\|Az\|^2\ge\|r\|^2$$
both squares global minimum; equality exactly when $Az=0$
schematic
Col(A)
Az
Az − r
r
Ax̂
A(x̂+z)
b
Least Squares
The Whole Set of Minimisers
$$\boxed{\hat x\ \text{minimises}\iff A\T A\hat x=A\T b}$$
every $A$ ⇒ p47 (necessary), ⇐ p51 (enough); no rank assumption
$$\mathrm{argmin}\,f=\hat x+\mathrm{Null}(A)$$
Lecture 1 $x_p+\Null(A)$; all share one $\hat b$, one $r$
p49: $\hat x=(1,1)$, $z=(1,0)\notin$ Null$(A)$: $Az=(1,1,1)$, $f=2+3=5$.
parameter space ℝⁿ
output space ℝᵐ
schematic
x̂
Null(A)
A
Col(A)
r
b̂
b
Groups · predict then compute
Least Squares
Solve the Three-Point Fit
$G=$3 3 3 5 , $A\T b=(5,6)$. Predict the signs of $r$, then find $\hat x,\hat b,r$.
$(-,+,-)$: the line runs below the middle point
$\beta_0=\frac76$, $\beta_1=\frac12$
$\hat b=(\frac76,\frac53,\frac{13}6)$
$A\T r=0$; min $\|r\|^2=\frac{1+4+1}{36}=\frac16$, $\|r\|=\frac1{\sqrt6}$
Why needn’t $r=0$?
1
2
1
2
t
y
−1/6
+1/3
−1/6
Transfer · alone / pairs
Least Squares
When Is the Minimiser Unique?
$$\hat x+\mathrm{Null}(A)=\{\hat x\}\iff\mathrm{Null}(A)=\{0\}\iff\mathrm{rank}\,A=n$$
$n$ number of parameters
One point or a family.
For new readings, choose a method; find $\hat x,r$. Is $\hat x$ unique?
$A\T b=(7,10)$; $\hat x=(5/6,3/2)$ $r=(1,-2,1)/6$; $A\T r=0$. Rank unchanged: unique.
previous fit
1 2
1
β₀
β₁
x̂
dependent case
1 2
1
x₁
x₂
Least Squares
Gram Positivity and the Equivalent Conditions
$$z\T Gz=z\T A\T Az=\|Az\|^2\ge0$$
$G=A\T A$ symmetric $n\times n$, any $A$
Positive definite : symmetric $G$, $z\T Gz>0$ for $z\neq0$.
Null$(A)=\{0\}\iff G$ pos. definite — $\|Az\|^2>0$
$\iff G$ invertible — $Az=0\Rightarrow Gz=0$, $Gz=0\Rightarrow Az=0$: Null$(G)$ = Null$(A)$
$\iff$ one $\hat x$ — argmin $=\hat x+$Null$(A)$ (p52)
Fails: $G$ singular, flat valley.
Boyd and Vandenberghe. Introduction to Applied Linear Algebra , least squares. Cambridge, 2018.
Least Squares
Closed Forms Under Full Column Rank
Rank $A=n$ (p54)
$$\hat x=(A\T A)^{-1}A\T b,\quad P=A(A\T A)^{-1}A\T$$
$\hat x\in\R^n$ $A\T A$ invertible (p55); in code, solve the system
$P$ $m\times m$, symmetric, rank $n$; rank $<n$: next lecture
$Pb\in$ Col$(A)$, $A\T(b-Pb)=0$: the projection (p29) — $P$ depends only on Col$(A)$.
$A=Q$ orthonormal: $Q\T Q=I$, $P=QQ\T$ (p30). Otherwise the Gram factor corrects the basis.
Gram–Schmidt Orthogonalization
Why We Want an Orthonormal Basis
any basis
$$P=A(A\T A)^{-1}A\T$$
cost build $A\T A$, then solve
orthonormal basis
$$P=QQ\T$$
$Q\T b$ coordinates of $Pb=\sum_i q_i(q_i\T b)$: one each
Can we build such a $Q$ for the same Col$(A)$?
Shadows add up for perpendicular directions; unit length drops the denominators. Old span · overlap · remainder · normalise.
b
q₁
q₂
orthonormal
≠ b
b
a₁
a₂
skewed
Vote
Gram–Schmidt Orthogonalization
Which Subtraction Makes It Orthogonal?
$q_1=(1,0)$, $a_2=(1,1)$. Sketch each result: which removes exactly the part along $q_1$?
A $a_2-q_1(q_1\T a_2)$✓ (0, 1)
B $a_2-q_1\|a_2\|$(1−√2, 1)
C $a_2/\|a_2\|$(1/√2, 1/√2)
D $a_2+q_1(q_1\T a_2)$(2, 1)
$q_1\T a_2$ is signed; the shadow’s length is $|q_1\T a_2|$. $a_2'=(-1,1)$: $q_1\T a_2'=-1$, $a_2'-q_1(-1)=a_2'+q_1=(0,1)$.
1
2
−1
1
D B C a₂′
u₂
a₂
q₁
Worked example
Gram–Schmidt Orthogonalization
Gram–Schmidt on Two Vectors
The columns from Lecture 2
$a_1=(2,1)$, $a_2=(1,2)$
normalise $\|a_1\|=\sqrt5\neq0$, $q_1=(2,1)/\sqrt5$
component $q_1\T a_2=4/\sqrt5$ (becomes $r_{12}$)
remainder $u_2=(1,2)-(8/5,4/5)=(-3/5,\,6/5)$
normalise $\|u_2\|=3/\sqrt5\neq0$, $q_2=(-1,2)/\sqrt5$
1
2
1
2
(8/5, 4/5)
u₂
q₂
a₁
a₂
q₁
Definition
Gram–Schmidt Orthogonalization
Keep the New Direction, Remove the Overlap
$$u_j=a_j-\sum_{i<j}q_i(q_i\T a_j),\quad q_j=\frac{u_j}{\|u_j\|}$$
$S_{j-1}$ span of the orthonormal $q_1,…,q_{j-1}$; $j=1$: empty sum, $S_0=\{0\}$
$\sum$ $=$ projection onto $S_{j-1}$ only because the $q_i$ are orthonormal
$u_j\in\R^m$ remainder; dividing needs $u_j\neq0$ ($j=1$: $u_1=a_1\neq0$)
Sⱼ₋₁
proj
uⱼ qⱼ
aⱼ
Axler. Linear Algebra Done Right , 4th ed., 6B. Springer, 2024.
Pair · predict then compute
Gram–Schmidt Orthogonalization
Orthogonalize Our Fitting Matrix
$q_1=(1,1,1)/\sqrt3$, $u_2\in$ span$\{a_1,a_2\}$. Predict its entries and the checks.
component $q_1\T a_2=(0+1+2)/\sqrt3=\sqrt3$
projection $q_1(q_1\T a_2)=(1,1,1)$
remainder $u_2=a_2-(1,1,1)=(-1,0,1)$
normalise $q_2=(-1,0,1)/\sqrt2$
check $q_1\T q_2=0$, $\|q_1\|=\|q_2\|=1$ $\sqrt3 q_1+\sqrt2 q_2=a_2$
x
y
z
√3
u₂
q₂
a₁
a₂
q₁
Gram–Schmidt Orthogonalization
The General Procedure
Scope: $a_1,…,a_n$ independent — $A$ of full column rank.
$$\begin{aligned}&\text{for }j=1,…,n:\\&\quad u_j=a_j-\textstyle\sum_{i<j}q_i(q_i\T a_j)\\&\quad q_j=u_j/\|u_j\|\end{aligned}$$
$a_j$ column $j$ of $A\in\R^{m\times n}$
$q_i\T a_j$ coefficient on earlier $q_i$
Under that scope $\|u_j\|>0$ at every step, so each division is legal.
span{q₁, q₂}
u₃
q₃
a₃
q₁
q₂
Gram–Schmidt Orthogonalization
Why the Result Is Orthogonal
$$q_i\T u_j=q_i\T a_j-\sum_{l<j}(q_i\T q_l)(q_l\T a_j)$$
assume $q_1,…,q_{j-1}$ already orthonormal — the induction
$i<j$ $q_i\T q_l=1$ at $l=i$, else $0$: one term survives
$u_j$ the remainder before normalising, in $\R^m$
$=q_i\T a_j-q_i\T a_j=0$ for every $i<j$.
$q_j=u_j/\|u_j\|$, so $q_i\T q_j=0$ too: scaling cannot change a zero.
Sⱼ₋₁
proj
qᵢ
uⱼ
aⱼ
Gram–Schmidt Orthogonalization
Why the Span Is Unchanged
After subtracting the projection, can we still rebuild $a_j$?
$$a_j=\sum_{i<j}(q_i\T a_j)q_i+\|u_j\|q_j$$
$\|u_j\|$ $>0$ by the scope
span$\{q_1..q_j\}=$span$\{a_1..a_j\}$ ⊇: this identity at each step $i\le j$ ⊆: solve for $q_j$: from $a_j$ and earlier $q$’s (induction)
Kept: $q_i\T a_j$ and $\|u_j\|$ — column $j$ of $R$
Sⱼ₋₁
aⱼ
‖uⱼ‖qⱼ
rebuild aⱼ
Sⱼ₋₁
aⱼ
uⱼ
qⱼ
rebuild qⱼ
Predict
Gram–Schmidt Orthogonalization
What If Nothing Remains?
Lower $a_3$ into the plane: which hits 0, $a_3$ or $u_3$?
$u_3=0$ means:
A $a_3\perp q_1,q_2$
B $a_3\in$ span$\{q_1,q_2\}$✓
C $a_3=0$
D $q_1,q_2$ invalid
No $q_3$ out of it: that column added no new direction, not that the space has none.
Rounding can hide exact dependence; a tiny $\|u_3\|/\|a_3\|$ ($a_3\neq0$) shows near-dependence, not exact dependence.
Gram–Schmidt Orthogonalization
What the Procedure Does Not Do
Why we could divide: $u_j=0$ would write $a_j$ from the earlier $q$’s, which independence forbids.
Without it, halting at $u_j=0$ is not basis extraction: $[e_1,2e_1,e_2]$ stops at $j=2$, missing $e_2$.
Skip it, carry on in the original order, index the kept $q$’s. Pivoting instead reorders columns: $A\Pi=QR$; it is a different algorithm.
skipped q₁ q₂
a₁
a₂ = 2a₁
a₃
QR Factorization and Least Squares
Record the Coefficients: $A=QR$
A = 1 0
1 1
1 2 Q = 1/√3 −1/√2
1/√3 0
1/√3 1/√2
A
a₁
a₂
=
Q
q₁
q₂
R
√3
√3
0
√2
q₁
q₂
a₁
a₂
$$a_j=\sum_{i\le j}r_{ij}q_i$$
$r_{ij}$ $=q_i\T a_j$, $i<j$
$r_{jj}$ $=q_j\T a_j=\|u_j\|>0$: columns independent
$$Q\T A=(Q\T Q)R=R$$
$Q\T Q$ $=I_n$ (p19)
$R$ column $j$: $a_j$ in the $q$-basis
Worked example
$q_1\T a_2=\sqrt3$, $\|u_2\|=\sqrt2$; check $\sqrt3q_1+\sqrt2q_2=a_2$
QR Factorization and Least Squares
What $Ax=Q(Rx)$ Means
parameters ℝⁿ
x
(1, 1)
R
coordinates ℝⁿ
Rx
(2√3, √2)
Q
outputs ℝᵐ
Q(Rx)
(1, 2, 3)
∈ Col(A)
$$Ax=Q(Rx)$$
$x$ parameters, $\in\R^n$
$Rx$ $Ax$ in the $q$-basis, also $\in\R^n$
$Q$ keeps lengths (p19); $R$ need not
$$R\T R=A\T A=G$$
always $R\T R=(QR)\T QR$
here $G\neq I$: $R$ is not a rotation
Fill in
QR Factorization and Least Squares
Why Is $R$ Upper Triangular?
a₁
a₂
a₃
q₁
q₂
q₃
r₁₁
r₁₂
r₁₃
r₂₂
r₂₃
r₃₃
0
0
0
$a_j$ uses only $q_1,\dots,q_j$ (p67). Why is $r_{ij}=q_i\T a_j=0$ for $i>j$?
A The columns of $A$ are orthogonal
B $q_i\perp q_1,\dots,q_j$, so $\perp$ their span✓
C Orthonormal $Q$ forces triangular $R$
D Only when $A$ is square
$a_j\in\text{span}\{q_1,\dots,q_j\}$ (p64), $q_i\perp$ it: the zeros are structural.
QR Factorization and Least Squares
Read the Shapes Before the Entries
m × n
m
n
A
=
m × n
Q
0
R
n × n
Here $m\ge n$ and $A$ has full column rank.
$$Q\in\R^{m\times n},\ R\in\R^{n\times n},\ Q\T Q=I_n$$
thin $Q$ is as tall as $A$ (p19)
shapes $(m\times n)(n\times n)=(m\times n)$
$QQ\T$ $\neq I_m$ once $n<m$ (p18)
We assume full column rank so this construction cannot break down and $R$ is invertible.
QR Factorization and Least Squares
Why $R$ Is Invertible
r₁₁
r₂₂
r₃₃
0
0
0
R
diagonal = ‖u₁‖, ‖u₂‖, ‖u₃‖
never computed
e.g.
‖u₂‖ = 0
$$\det R=r_{11}\cdots r_{nn}\neq0$$
$r_{jj}>0$ $r_{jj}=\|u_j\|$, and $u_j=0$ would put $a_j$ in the span of the earlier columns (p66)
$\neq0$ triangular; ours $\sqrt3\sqrt2=\sqrt6$
Rank $<n$: Gram–Schmidt stalls; any $R$ has an ${r_{jj}=0}$, so $\det R=0$ and the solve divides by zero.
QR Factorization and Least Squares
QR Is Not Diagonalization
$A=V\Lambda V^{-1}$ $A=QR$
directions eigenvectors orthonormal columns
middle diagonal upper triangular
use modes, powers outputs, least squares
needs square $A$ yes no
eigenvectors? $V$: yes $Q$: usually no
Is $q_1$ an eigenvector of $A$?
No: $Aq_1=(5,4)/\sqrt5\nparallel(2,1)$; eigenvectors $(1,1),(1,-1)$, $\Lambda=\mathrm{diag}(3,1)$.
$R=$√5 4/√5 0 3/√5 , $\det R=3$.
QR Factorization and Least Squares
Split the Error in the New Coordinates
Col(A)
schematic
QQᵀb
b
QRx − b
Q(Rx − Qᵀb)
−(I − QQᵀ)b
QRx
Throughout $r=b-Ax$, so $QRx-b=-r$ and $\|QRx-b\|=\|r\|$: the same error, drawn from $b$ to the prediction.
Do not start from $QRx=b$: generally false.
$$QRx-b=Q(Rx-Q\T b)-(I-QQ\T)b$$
check $=QRx-QQ\T b-b+QQ\T b$
goal $\min_x\|r\|^2$
QR Factorization and Least Squares
Why the Two Parts Are Perpendicular
Col(A)
schematic
b
QRx
in Col(A)
⊥ Col(A)
The two pieces of $QRx-b$:
$$Q(Rx-Q\T b)\in\text{Col}(Q)=\text{Col}(A)$$
$=$ the span was kept
$$Q\T(I-QQ\T)b=Q\T b-Q\T b=0$$
$\Rightarrow$ $\perp$ every $q_i$, so $\perp\text{Col}(A)$
$(I-QQ\T)b$ $=(I-P)b$, the projection's residual; drawn leg $-(I-P)b$
The same perpendicular-error decomposition, in the same colours.
QR Factorization and Least Squares
Pythagoras in the New Coordinates
outputs ℝᵐ
schematic
Col(A)
b
‖QRx − b‖²
‖(I − QQᵀ)b‖²
‖Q(Rx − Qᵀb)‖²
coordinates ℝⁿ
z = Rx − Qᵀb
‖Qz‖ = ‖z‖
The two parts are perpendicular (p74):
$$\|QRx-b\|^2=\|Q(Rx-Q\T b)\|^2+\|(I-QQ\T)b\|^2$$
$+$ cross term $=0$: squares add (p11)
$$\|Ax-b\|^2=\|Rx-Q\T b\|^2+\|(I-QQ\T)b\|^2$$
$z=Rx-Q\T b$ $\|Qz\|^2=z\T Q\T Qz=\|z\|^2$ (p19)
QR Factorization and Least Squares
Adjustable and Unavoidable Error
At the solution, which part must be zero?
$$\|Ax-b\|^2=\|Rx-Q\T b\|^2+\|(I-QQ\T)b\|^2$$
second no $x$ in it: unavoidable
first $R$ invertible (p71): it can reach $0$
Coordinate part, reachable because $R$ is invertible: $\boxed{R\hat x=Q\T b}$, by back-substitution. Residual $0$ only if $b\in\text{Col}(A)$; here $\|r\|^2=1/6$, so $\|r\|=1/\sqrt6$.
Pair
QR Factorization and Least Squares
Solve the Same Fit with QR
Which unknown comes first, and why?
$$\begin{bmatrix}\sqrt3&\sqrt3\\0&\sqrt2\end{bmatrix}\hat x=\begin{bmatrix}5/\sqrt3\\1/\sqrt2\end{bmatrix}$$
$\hat x$ $(β_0,β_1)$
$R$ $r_{jj}>0$
$β_1$: the bottom row has one unknown.
$\sqrt2β_1=1/\sqrt2⇒β_1=1/2$
$\sqrt3(β_0+1/2)=5/\sqrt3⇒β_0=7/6$
Same $\hat x$ as the normal equations: $R\hat x=Q\T b$.
1
2
1
2
t
y
Predict
QR Factorization and Least Squares
Very Different Parameters, Almost the Same Prediction
What becomes hard when we infer parameters from measurements?
$0.2$ in the data moves the fitted $x$ by $2\sqrt2$, ≈14×: an amplification for these two data vectors in these parameter units, not $κ_2(A)$.
Near dependence = sensitivity (p79); exact ($a_2\parallel a_1$) = non-uniqueness (p54).
QR Factorization and Least Squares
Largest Stretch over Smallest Stretch
$$κ_2(A)=\frac{\max_{\|z\|=1}\|Az\|_2}{\min_{\|z\|=1}\|Az\|_2}$$
$A$ $m\times n$, $m\ge n$
$z$ parameter direction, $\|z\|_2=1$
The second lecture measured how a matrix stretches directions; the new object is the ratio.
min $>0$ $⇔$ Null$(A)=\{0\}$: no unit $z$ is flattened.
Rank lost: some unit $z$ has $Az=0$, so min $=0$ and $κ_2(A)=∞$ by convention.
Discuss
QR Factorization and Least Squares
Which Computational Route Would You Choose?
Which is correct?
A QR cures the sensitivity
B Forming $A\T A$ can hurt the numerics✓
C Normal equations fail even exactly
D Every QR code is equally stable
Conditioning is the problem's, stability the algorithm's. In exact arithmetic the normal equations are right; in floating point classical Gram–Schmidt can lose orthogonality.
QR Factorization and Least Squares
Squaring the Ratio
$$κ_2(R)=κ_2(A),\qquad κ_2(A\T A)=κ_2(A)^2$$
$R$ $\|Rz\|=\|QRz\|=\|Az\|$, $Q$ an isometry
$A\T A$ full column rank; proved next lecture
The triangular coefficient matrix has $A$'s stretch ratio; the normal equations square it.
Rules of thumb, not bounds: about $\log_{10}κ_2$ digits lost; sensitivity also depends on the residual, so $κ_2(A)$ alone does not settle it.
Trefethen, L. N. and Bau, D. Numerical Linear Algebra , Lecture 18 conditioning of least squares problems. SIAM, 1997.
Robotics Application
The Local Model
θ₁
θ₂
ptarget
e
∂f/∂θ₁
∂f/∂θ₂
$e(θ)=f(θ)-p_{\rm target}\in\R^2$
$$e(θ+Δθ)≈e(θ)+J(θ)Δθ$$
$f$ tip position, nonlinear in $θ$
$θ=(θ_1,θ_2)$ joint angles in radians; $Δθ$ small
$J(θ)$ $∂f/∂θ$; column $j$: tip velocity per unit joint rate
$JΔθ$ a displacement, not a velocity
Near a singularity $J$ can be ill-conditioned; at a singularity it loses rank.
$\det J=l_1l_2\sinθ_2$, link lengths $l_1,l_2>0$
Lynch, K. M. and Park, F. C. Modern Robotics , 5.3 singularities and 6.2 numerical inverse kinematics. Cambridge, 2017.
Transfer
Robotics Application
One Least-Squares Step
θ₁
θ₂
ptarget
e
−e
$A=$ $J$
$x=$ $Δθ$
$b=$ $-e$
$$\min_{Δθ}\|JΔθ+e\|^2$$
$JΔθ+e$ the model's error after the step
$J$ full column rank here
sign $b-Ax=-(JΔθ+e)$
The predicted change must cancel $e$: the tip change we ask for is $-e$.
$J=QR⇒RΔθ=-Q\T e$, the fit's triangular solve
$q_i$ columns of $Q$, not joints
$m=n=2$ the step solves $JΔθ=-e$ exactly; $m\ge n$ is the general case
Robotics Application
Predicted Motion and Actual Motion
$$e(θ)+JΔθ=0\ \text{ but }\ e(θ+Δθ)\neq0$$
in this example
$e(θ)+JΔθ$ the model's error after the step; $0$ here
$e(θ+Δθ)$ the true error after moving
$E(Δθ)$ their difference: model discrepancy, $O(\|Δθ\|^2)$
Zero linearised error need not mean zero true error.
Linearise, step, measure, relinearise, repeat — each step small enough that the linear model stays accurate.
Robotics Application
Ill-Conditioned or Singular?
$$\det J=l_1l_2\sinθ_2$$
$l_1,l_2$ link lengths; $θ_2$ elbow angle
across the arm
along the arm
θ₂ = 2°
$\det J\neq0$: full rank, $R$ invertible
QR runs; step size depends on $e$'s direction
across the arm
along the arm
unreachable by thelocal linear model
θ₂ = 0°
$\det J=0$: rank $1$, $r_{22}=0$
Ordinary solve fails, yet minimisers exist; no joint rate gives along-arm tip velocity
Synthesis and Exit Ticket
One Problem, Four Views
Geometryany A
$\hat b=\operatorname{proj}_{\Col(A)}\,b$
the closest reachable output
Algebraany A
$A\T A\hat x=A\T b$
the equations every minimiser satisfies
Computationfull column rank
$A=QR$
the minimiser satisfies $R\hat x=Q\T b$
Roboticsfull column rank · local model
$RΔθ=-Q\T e$
one step, then relinearise
Synthesis and Exit Ticket
One Best Output, Sometimes Many Parameter Vectors
measurement space ℝᵐ
Col(A)
b
r
b̂
Every $A$ and $b$: one closest $\hat b$, one $r\perp\Col(A)$.
parameter space ℝⁿ
x̂
x̂ + Null(A)
independent columns
dependent, nullity 1
$\{x:Ax=\hat b\}=\hat x+\Null(A)$: one point exactly when the columns are independent.
Projection: no assumption. $R\hat x=Q\T b$ and $(A\T A)^{-1}$: full column rank.
Pair
Synthesis and Exit Ticket
Find the Incorrect Claim
Which claim is false? Sketch Col($A$) and $b$ so it fails.
A $r=b-A\hat x$ is $\perp$ each column of $A$.
B If $b\in$ Col($A$), the minimum residual is 0.
C A nonzero minimum residual forces a non-unique $\hat x$.false
D Full column rank makes $\hat x$ unique.
full column rank?
yes
no
b ∈ Col(A)?
yes
no
r = 0
r ≠ 0
one x̂
many x̂
one x̂
many x̂
Col(A)
a₁
a₂
b̂
r
b
‖r‖² = 1/6
schematic
Exit ticket · alone
Synthesis and Exit Ticket
Exit Ticket
$q=(0,1)$, $b=(3,2)$. Projection $p$? Residual $r$?✓ $p=(0,2)$, $r=(3,0)$
Why does $A\T r=0$ not force $r=0$? One sentence of reasoning. ✓ $r\neq0$ can lie in $\text{Col}(A)^{\perp}$
Thin QR, full rank: which part of $\|QRx-b\|^2$ can no $x$ change?✓ $\|(I-QQ\T)b\|^2$
Hand in before the answers.
Nearly dependent or rank-deficient columns: next lecture.
1
2
3
1
2
3
p
r
q
b