第 15 章

投影到子空间

投影的几何核心是误差向量垂直于目标子空间;沿这个条件推出 x̂ = (AᵀA)⁻¹Aᵀb 与投影矩阵 P = A(AᵀA)⁻¹Aᵀ,并用一条直线拟合收尾。

Projections onto Subspaces

The geometry of projection is one condition: the error is perpendicular to the target subspace. From it follow x̂ = (AᵀA)⁻¹Aᵀb and P = A(AᵀA)⁻¹Aᵀ, applied to fitting a line.

首发于 2009.05.07中 / EN
系统课程linear-algebraprojectionleast-squaresnormal-equations
语言
字号
目录
篇内目录

为什么需要投影

本章处理 Ax=bA\mathbf{x}=\mathbf{b} 无解的情形。无解不等于没有办法:b\mathbf{b} 不在列空间里,但列空间里一定有一个离它最近的点。把 b\mathbf{b} 换成这个最近点,方程就有解了。

这就是投影。它在几何上是「垂足」,在代数上是「最小二乘」。

时间轴

时间内容
0:10投影公式 aTb/aTa\mathbf{a}^{T}\mathbf{b}/\mathbf{a}^{T}\mathbf{a}
2:03一维投影矩阵 aaT/aTa\mathbf{a}\mathbf{a}^{T}/\mathbf{a}^{T}\mathbf{a}
5:45线性性:向量加倍,投影也加倍
10:52投影矩阵的列空间与秩
16:17正交性是投影的关键
20:12列必须线性无关
22:01b\mathbf{b} 不在列空间时怎么办
25:30误差与列空间垂直得到的两个方程
28:48用四个子空间解释投影
33:18正规方程的来源
36:00P=A(ATA)−1ATP=A(A^{T}A)^{-1}A^{T}
37:31AA 可逆时 P=IP=I
39:18不能把 ATAA^{T}A 拆开
44:09最小二乘:用直线拟合三个点
46:56构造矩阵 AA 与右端 b\mathbf{b}
48:49本讲留下的计算

一维情形:投影到一条直线

图:投影的几何、投影矩阵与三个点的最小二乘拟合。

设直线由向量 a\mathbf{a} 张成,要把 b\mathbf{b} 投影到这条线上。

投影点必须在直线上,所以形如 p=xa\mathbf{p}=x\mathbf{a}。关键条件是:误差向量 e=b−xa\mathbf{e}=\mathbf{b}-x\mathbf{a} 与直线垂直,即

a⊤(b−xa)=0.\mathbf{a}^\top(\mathbf{b}-x\mathbf{a})=0.

展开:

a⊤b=x a⊤a⟹x=a⊤ba⊤a.\mathbf{a}^\top\mathbf{b}=x\,\mathbf{a}^\top\mathbf{a} \quad\Longrightarrow\quad x=\frac{\mathbf{a}^\top\mathbf{b}}{\mathbf{a}^\top\mathbf{a}}.

于是

p=xa=a⊤ba⊤a a.\mathbf{p}=x\mathbf{a}=\frac{\mathbf{a}^\top\mathbf{b}}{\mathbf{a}^\top\mathbf{a}}\,\mathbf{a}.

三个必须记住的公式

对象公式
系数x=a⊤ba⊤ax=\dfrac{\mathbf{a}^\top\mathbf{b}}{\mathbf{a}^\top\mathbf{a}}
投影向量p=ax\mathbf{p}=\mathbf{a}x
投影矩阵P=aa⊤a⊤aP=\dfrac{\mathbf{a}\mathbf{a}^\top}{\mathbf{a}^\top\mathbf{a}}

注意 PP 是 n×nn\times n 矩阵:分子是列乘行(矩阵),分母是数。

两个检验

  • 把 b\mathbf{b} 变成 2b2\mathbf{b},投影也变成 2p2\mathbf{p}。
  • 把 a\mathbf{a} 变成 2a2\mathbf{a},投影不变——直线没变,分子与分母同时乘 4,抵消。

投影矩阵的两个性质

P⊤=P,P2=P.P^\top=P,\qquad P^2=P.

第一个来自 (aa⊤)⊤=aa⊤(\mathbf{a}\mathbf{a}^\top)^\top=\mathbf{a}\mathbf{a}^\top。第二个来自几何:投影两次与投影一次结果相同。代数验证:

P2=aa⊤aa⊤(a⊤a)2=a(a⊤a)a⊤(a⊤a)2=aa⊤a⊤a=P.P^2=\frac{\mathbf{a}\mathbf{a}^\top\mathbf{a}\mathbf{a}^\top}{(\mathbf{a}^\top\mathbf{a})^2} =\frac{\mathbf{a}(\mathbf{a}^\top\mathbf{a})\mathbf{a}^\top}{(\mathbf{a}^\top\mathbf{a})^2} =\frac{\mathbf{a}\mathbf{a}^\top}{\mathbf{a}^\top\mathbf{a}}=P.

这两个性质反过来也刻画了投影矩阵:对称且幂等。

推广到子空间

设子空间是矩阵 AA 的列空间,AA 的列是一组基(因此线性无关)。

投影点 p=Ax^\mathbf{p}=A\hat{\mathbf{x}},其中 x^\hat{\mathbf{x}} 是待求的系数。核心条件仍然是

e=b−Ax^⊥C(A).\mathbf{e}=\mathbf{b}-A\hat{\mathbf{x}}\perp C(A).

「垂直于整个列空间」等价于「垂直于 AA 的每一列」:

A⊤(b−Ax^)=0.A^\top(\mathbf{b}-A\hat{\mathbf{x}})=\mathbf{0}.

整理得正规方程:

A⊤A x^=A⊤b.A^\top A\,\hat{\mathbf{x}}=A^\top\mathbf{b}.

解的公式是

x^=(A⊤A)−1A⊤b,\hat{\mathbf{x}}=(A^\top A)^{-1}A^\top\mathbf{b},

投影向量与投影矩阵是

p=Ax^=A(A⊤A)−1A⊤b,\mathbf{p}=A\hat{\mathbf{x}}=A(A^\top A)^{-1}A^\top\mathbf{b}, P=A(A⊤A)−1A⊤.P=A(A^\top A)^{-1}A^\top.

与一维公式的对应

一维时 AA 只有一列 a\mathbf{a},(A⊤A)−1(A^\top A)^{-1} 就是除以 a⊤a\mathbf{a}^\top\mathbf{a},公式退化为

P=aa⊤a⊤a.P=\frac{\mathbf{a}\mathbf{a}^\top}{\mathbf{a}^\top\mathbf{a}}.

多维时不能「除」,只能求逆——这是矩阵与数的区别。

误差向量住在哪里

由 A⊤e=0A^\top\mathbf{e}=\mathbf{0} 可知

e∈N(A⊤)=C(A)⊥.\mathbf{e}\in N(A^\top)=C(A)^\perp.

这正是上一讲的正交关系:误差向量落在左零空间里,与列空间垂直。几何与四个子空间在这里严丝合缝地接上。

一个不能做的事

有人会想把 A(A⊤A)−1A⊤A(A^\top A)^{-1}A^\top 中的逆拆开:

(A⊤A)−1=A−1(A⊤)−1.(A^\top A)^{-1}=A^{-1}(A^\top)^{-1}.

这是错的,因为** AA 不是方阵,根本没有逆**。这正是本章的典型情形:AA 行多列少。只有当 AA 是方阵且可逆时才可以这样拆,而那时列空间是整个 Rn\mathbb{R}^n,投影矩阵是单位矩阵 II。

最小二乘:用一条直线拟合三个点

给定三个点 (1,1),(2,2),(3,2)(1,1),(2,2),(3,2),要找一条直线

b=C+Dtb=C+Dt

使总误差最小。

如果直线穿过三个点,就应满足

C+D=1,C+2D=2,C+3D=2.\begin{aligned} C+D&=1,\\ C+2D&=2,\\ C+3D&=2. \end{aligned}

写成矩阵形式:

[111213]⏟A[CD]⏟x=[122]⏟b.\underbrace{\begin{bmatrix}1&1\\1&2\\1&3\end{bmatrix}}_{A} \underbrace{\begin{bmatrix}C\\D\end{bmatrix}}_{\mathbf{x}} = \underbrace{\begin{bmatrix}1\\2\\2\end{bmatrix}}_{\mathbf{b}}.

三个方程、两个未知数,通常无解。我们不去解它,而是解正规方程:

A⊤Ax^=A⊤b.A^\top A\hat{\mathbf{x}}=A^\top\mathbf{b}.

下一讲会把这个例子算完,得到 C=2/3C=2/3、D=1/2D=1/2,即最佳直线

b=23+12t.b=\frac{2}{3}+\frac{1}{2}t.

为什么要用所有点

另一种做法是丢掉一个方程,解剩下的方阵系统。但这等于宣称「某些测量是完美的,另一些毫无价值」,没有依据。最小二乘让所有点都参与,按平方误差加权。

代价是它对离群点敏感:一个远离直线的点,平方后误差会被放大,可能把整条线拉偏。统计学里因此有稳健回归等替代方法。

本讲结论

  • 投影的唯一几何条件是误差向量垂直于目标子空间。
  • 一维:x=a⊤b/a⊤ax=\mathbf{a}^\top\mathbf{b}/\mathbf{a}^\top\mathbf{a},P=aa⊤/a⊤aP=\mathbf{a}\mathbf{a}^\top/\mathbf{a}^\top\mathbf{a}。
  • 多维:正规方程 A⊤Ax^=A⊤bA^\top A\hat{\mathbf{x}}=A^\top\mathbf{b},P=A(A⊤A)−1A⊤P=A(A^\top A)^{-1}A^\top。
  • 投影矩阵对称且幂等:P⊤=PP^\top=P,P2=PP^2=P。
  • 误差向量属于左零空间,与列空间正交。
  • 最小二乘就是用投影解一个无解的方程组。

理解检验

1. 为什么「误差垂直于直线」能唯一确定投影点?

参考答案:直线上的点都形如 p=xa\mathbf{p}=x\mathbf{a},条件

a⊤(b−xa)=0\mathbf{a}^\top(\mathbf{b}-x\mathbf{a})=0

展开得 x=a⊤ba⊤ax=\dfrac{\mathbf{a}^\top\mathbf{b}}{\mathbf{a}^\top\mathbf{a}}。因为 a≠0\mathbf{a}\ne\mathbf{0},分母 a⊤a>0\mathbf{a}^\top\mathbf{a}>0,所以 xx 被唯一确定。

几何上还有一个更直接的论证:若直线上有两个点 p≠q\mathbf{p}\ne\mathbf{q} 都使误差垂直于直线,则 p−q\mathbf{p}-\mathbf{q} 在直线上,同时

p−q=(b−q)−(b−p)\mathbf{p}-\mathbf{q}=(\mathbf{b}-\mathbf{q})-(\mathbf{b}-\mathbf{p})

是两个与直线垂直的向量之差,也垂直于直线。一个向量既在直线上又与直线垂直,只能满足 (p−q)⊤(p−q)=0(\mathbf{p}-\mathbf{q})^\top(\mathbf{p}-\mathbf{q})=0,即 p=q\mathbf{p}=\mathbf{q},矛盾。所以垂足唯一。

2. 把 a\mathbf{a} 换成 3a3\mathbf{a},投影矩阵会变吗?为什么?

参考答案:不变。代入定义:

P′=(3a)(3a)⊤(3a)⊤(3a)=9 aa⊤9 a⊤a=aa⊤a⊤a=P.P'=\frac{(3\mathbf{a})(3\mathbf{a})^\top}{(3\mathbf{a})^\top(3\mathbf{a})} =\frac{9\,\mathbf{a}\mathbf{a}^\top}{9\,\mathbf{a}^\top\mathbf{a}} =\frac{\mathbf{a}\mathbf{a}^\top}{\mathbf{a}^\top\mathbf{a}}=P .

原因是投影只依赖子空间(这条直线),而不依赖用哪个向量去张成它;a\mathbf{a} 与 3a3\mathbf{a} 张成同一条直线。同理,把 b\mathbf{b} 换成 2b2\mathbf{b} 时,投影变成 2p2\mathbf{p}——投影对 b\mathbf{b} 是线性的。

3. 证明多维投影矩阵满足 P2=PP^2=P。

参考答案:设 P=A(A⊤A)−1A⊤P=A(A^\top A)^{-1}A^\top。则

P2=A(A⊤A)−1A⊤A(A⊤A)−1A⊤.P^2=A(A^\top A)^{-1}A^\top A(A^\top A)^{-1}A^\top .

中间三个因子 A⊤A(A⊤A)−1=IA^\top A(A^\top A)^{-1}=I,于是

P2=A(A⊤A)−1A⊤=P.P^2=A(A^\top A)^{-1}A^\top=P .

几何含义是:把向量投影到列空间后,它已经在列空间里,再投影一次不动。另外 P⊤=PP^\top=P,因为

P⊤=(A(A⊤A)−1A⊤)⊤=A((A⊤A)−1)⊤A⊤=A(A⊤A)−1A⊤=P,P^\top=\big(A(A^\top A)^{-1}A^\top\big)^\top =A\big((A^\top A)^{-1}\big)^\top A^\top =A(A^\top A)^{-1}A^\top=P,

用到了 A⊤AA^\top A 对称、其逆也对称。对称加幂等正是投影矩阵的刻画。

4. 为什么不能把 (A⊤A)−1(A^\top A)^{-1} 拆成 A−1(A⊤)−1A^{-1}(A^\top)^{-1}?

参考答案:因为本章的 AA 是 m×nm\times n 且 m>nm>n,不是方阵,根本没有逆。公式 B−1C−1=(CB)−1B^{-1}C^{-1}=(CB)^{-1} 只对可逆方阵成立;对非方阵写 A−1A^{-1} 本身就是无意义的符号。

A⊤AA^\top A 是 n×nn\times n 方阵,在 AA 的列无关时可逆,所以 (A⊤A)−1(A^\top A)^{-1} 存在;但这与「AA 可逆」是两回事。只有当 AA 本身是 n×nn\times n 可逆矩阵时,才有 (A⊤A)−1=A−1(A⊤)−1(A^\top A)^{-1}=A^{-1}(A^\top)^{-1},而此时列空间是整个 Rn\mathbb{R}^n,投影矩阵退化为

P=A(A⊤A)−1A⊤=A A−1(A⊤)−1A⊤=I.P=A(A^\top A)^{-1}A^\top=A\,A^{-1}(A^\top)^{-1}A^\top=I .

5. 写出用直线 b=C+Dtb=C+Dt 拟合三个点时对应的 AA、x\mathbf{x} 与 b\mathbf{b}。

参考答案:三个点是 (t,b)=(1,1),(2,2),(3,2)(t,b)=(1,1),(2,2),(3,2),直线 b=C+Dtb=C+Dt 在每个点给出一个方程:

C+D⋅1=1,C+D⋅2=2,C+D⋅3=2.\begin{aligned} C+D\cdot1&=1,\\ C+D\cdot2&=2,\\ C+D\cdot3&=2. \end{aligned}

按未知量 (C,D)(C,D) 的系数组成矩阵:

A=[111213],x=[CD],b=[122].A=\begin{bmatrix}1&1\\1&2\\1&3\end{bmatrix}, \qquad \mathbf{x}=\begin{bmatrix}C\\D\end{bmatrix}, \qquad \mathbf{b}=\begin{bmatrix}1\\2\\2\end{bmatrix}.

第一列是常数列(对应截距 CC),第二列是 tt 的取值(对应斜率 DD)。三个方程、两个未知数,通常无解,所以要解正规方程 A⊤Ax^=A⊤bA^\top A\hat{\mathbf{x}}=A^\top\mathbf{b} 求最小二乘解。

与前后课程的关系

上一讲证明了四个子空间的正交关系;这一讲用它构造投影。下一讲把投影矩阵算到底,给出最小二乘的数值例子,并证明 A⊤AA^\top A 在列无关时可逆。

Why project

This chapter handles the case where Ax=bA\mathbf{x}=\mathbf{b} has no solution. No solution does not mean no answer: b\mathbf{b} is outside the column space, but the column space has a nearest point. Replacing b\mathbf{b} by that point makes the system solvable.

That is projection. Geometrically it is a foot of a perpendicular; algebraically it is least squares.

Timeline

TimeTopic
0:10The projection formula
2:03The one-dimensional projection matrix
5:45Linearity of projection
10:52Column space and rank of the projection matrix
16:17Orthogonality is the key
20:12The columns must be independent
22:01When b\mathbf{b} lies outside the column space
25:30Two equations from the perpendicular error
28:48Explaining projection with the four subspaces
33:18Where the normal equation comes from
36:00The projection matrix PP
37:31When AA is invertible, P=IP=I
39:18You cannot split ATAA^{T}A apart
44:09Fitting a line to three points
46:56Building AA and b\mathbf{b}
48:49The computation left for next time

The one-dimensional case: projecting onto a line

Figure:Projection geometry, the projection matrix, and a three-point least-squares fit。

Let the line be spanned by a\mathbf{a}, and project b\mathbf{b} onto it.

The projection lies on the line, so it has the form p=xa\mathbf{p}=x\mathbf{a}. The key condition is that the error e=b−xa\mathbf{e}=\mathbf{b}-x\mathbf{a} is perpendicular to the line:

a⊤(b−xa)=0.\mathbf{a}^\top(\mathbf{b}-x\mathbf{a})=0.

Expanding,

a⊤b=x a⊤a⟹x=a⊤ba⊤a.\mathbf{a}^\top\mathbf{b}=x\,\mathbf{a}^\top\mathbf{a} \quad\Longrightarrow\quad x=\frac{\mathbf{a}^\top\mathbf{b}}{\mathbf{a}^\top\mathbf{a}}.

Therefore

p=xa=a⊤ba⊤a a.\mathbf{p}=x\mathbf{a}=\frac{\mathbf{a}^\top\mathbf{b}}{\mathbf{a}^\top\mathbf{a}}\,\mathbf{a}.

Three formulas to remember

ObjectFormula
Coefficientx=a⊤ba⊤ax=\dfrac{\mathbf{a}^\top\mathbf{b}}{\mathbf{a}^\top\mathbf{a}}
Projection vectorp=ax\mathbf{p}=\mathbf{a}x
Projection matrixP=aa⊤a⊤aP=\dfrac{\mathbf{a}\mathbf{a}^\top}{\mathbf{a}^\top\mathbf{a}}

PP is n×nn\times n: the numerator is a column times a row (a matrix), the denominator is a scalar.

Two sanity checks

  • Doubling b\mathbf{b} doubles the projection.
  • Doubling a\mathbf{a} leaves the projection unchanged: the line is the same, and numerator and denominator both gain a factor of 4.

Two properties of a projection matrix

P⊤=P,P2=P.P^\top=P,\qquad P^2=P.

The first follows from (aa⊤)⊤=aa⊤(\mathbf{a}\mathbf{a}^\top)^\top=\mathbf{a}\mathbf{a}^\top. The second is geometric: projecting twice is the same as projecting once. Algebraically,

P2=aa⊤aa⊤(a⊤a)2=a(a⊤a)a⊤(a⊤a)2=aa⊤a⊤a=P.P^2=\frac{\mathbf{a}\mathbf{a}^\top\mathbf{a}\mathbf{a}^\top}{(\mathbf{a}^\top\mathbf{a})^2} =\frac{\mathbf{a}(\mathbf{a}^\top\mathbf{a})\mathbf{a}^\top}{(\mathbf{a}^\top\mathbf{a})^2} =\frac{\mathbf{a}\mathbf{a}^\top}{\mathbf{a}^\top\mathbf{a}}=P.

Conversely, a symmetric idempotent matrix is a projection matrix.

Projecting onto a subspace

Let the subspace be the column space of AA, whose columns form a basis and are therefore independent.

The projection is p=Ax^\mathbf{p}=A\hat{\mathbf{x}}, with x^\hat{\mathbf{x}} the coefficients to be found. The condition is still

e=b−Ax^⊥C(A).\mathbf{e}=\mathbf{b}-A\hat{\mathbf{x}}\perp C(A).

Being perpendicular to the whole column space means being perpendicular to each column:

A⊤(b−Ax^)=0.A^\top(\mathbf{b}-A\hat{\mathbf{x}})=\mathbf{0}.

Rearranging gives the normal equations:

A⊤A x^=A⊤b.A^\top A\,\hat{\mathbf{x}}=A^\top\mathbf{b}.

The solution is

x^=(A⊤A)−1A⊤b,\hat{\mathbf{x}}=(A^\top A)^{-1}A^\top\mathbf{b},

and the projection vector and matrix are

p=Ax^=A(A⊤A)−1A⊤b,\mathbf{p}=A\hat{\mathbf{x}}=A(A^\top A)^{-1}A^\top\mathbf{b}, P=A(A⊤A)−1A⊤.P=A(A^\top A)^{-1}A^\top.

Correspondence with the one-dimensional formula

In one dimension AA is the single column a\mathbf{a}, and (A⊤A)−1(A^\top A)^{-1} is division by a⊤a\mathbf{a}^\top\mathbf{a}:

P=aa⊤a⊤a.P=\frac{\mathbf{a}\mathbf{a}^\top}{\mathbf{a}^\top\mathbf{a}}.

In higher dimensions division is replaced by inversion — the difference between a scalar and a matrix.

Where the error lives

From A⊤e=0A^\top\mathbf{e}=\mathbf{0},

e∈N(A⊤)=C(A)⊥.\mathbf{e}\in N(A^\top)=C(A)^\perp.

This is exactly the orthogonality from the previous lecture: the error lies in the left null space, perpendicular to the column space. Geometry and the four subspaces meet precisely here.

Something you must not do

It is tempting to split the inverse:

(A⊤A)−1=A−1(A⊤)−1.(A^\top A)^{-1}=A^{-1}(A^\top)^{-1}.

That is wrong, because AA is not square and has no inverse. This is the typical case of the chapter: more rows than columns. The split is legal only when AA is square and invertible, and then the column space is all of Rn\mathbb{R}^n and the projection matrix is the identity II.

Least squares: fitting a line to three points

Given the points (1,1),(2,2),(3,2)(1,1),(2,2),(3,2), find the line

b=C+Dtb=C+Dt

with the smallest total error.

If the line passed through all three points, it would satisfy

C+D=1,C+2D=2,C+3D=2.\begin{aligned} C+D&=1,\\ C+2D&=2,\\ C+3D&=2. \end{aligned}

In matrix form:

[111213]⏟A[CD]⏟x=[122]⏟b.\underbrace{\begin{bmatrix}1&1\\1&2\\1&3\end{bmatrix}}_{A} \underbrace{\begin{bmatrix}C\\D\end{bmatrix}}_{\mathbf{x}} = \underbrace{\begin{bmatrix}1\\2\\2\end{bmatrix}}_{\mathbf{b}}.

Three equations, two unknowns, generally unsolvable. Instead of solving it, solve the normal equations:

A⊤Ax^=A⊤b.A^\top A\hat{\mathbf{x}}=A^\top\mathbf{b}.

The next lecture finishes the arithmetic, giving C=2/3C=2/3 and D=1/2D=1/2, so the best line is

b=23+12t.b=\frac{2}{3}+\frac{1}{2}t.

Why use every point

The alternative is to discard an equation and solve a square system. That amounts to declaring some measurements perfect and others worthless, with no justification. Least squares lets every point contribute, weighted by squared error.

The price is sensitivity to outliers: a point far from the line has its error squared, so it can drag the whole fit. Statistics therefore also offers robust regression.

Takeaways

  • The only geometric condition for a projection is that the error is perpendicular to the target subspace.
  • One dimension: x=a⊤b/a⊤ax=\mathbf{a}^\top\mathbf{b}/\mathbf{a}^\top\mathbf{a} and P=aa⊤/a⊤aP=\mathbf{a}\mathbf{a}^\top/\mathbf{a}^\top\mathbf{a}.
  • Higher dimensions: A⊤Ax^=A⊤bA^\top A\hat{\mathbf{x}}=A^\top\mathbf{b} and P=A(A⊤A)−1A⊤P=A(A^\top A)^{-1}A^\top.
  • Projection matrices are symmetric and idempotent: P⊤=PP^\top=P and P2=PP^2=P.
  • The error lies in the left null space, orthogonal to the column space.
  • Least squares is projection applied to an unsolvable system.

Check your understanding

1. Why does "the error is perpendicular to the line" determine the projection uniquely?

Reference answer: Every point on the line is p=xa\mathbf{p}=x\mathbf{a}, and the condition

a⊤(b−xa)=0\mathbf{a}^\top(\mathbf{b}-x\mathbf{a})=0

expands to x=a⊤ba⊤ax=\dfrac{\mathbf{a}^\top\mathbf{b}}{\mathbf{a}^\top\mathbf{a}}. Since a≠0\mathbf{a}\ne\mathbf{0}, the denominator a⊤a>0\mathbf{a}^\top\mathbf{a}>0, so xx is determined uniquely.

Geometrically: if two distinct points p≠q\mathbf{p}\ne\mathbf{q} on the line both had perpendicular error, then p−q\mathbf{p}-\mathbf{q} lies on the line while

p−q=(b−q)−(b−p)\mathbf{p}-\mathbf{q}=(\mathbf{b}-\mathbf{q})-(\mathbf{b}-\mathbf{p})

is a difference of two vectors perpendicular to the line, hence also perpendicular to it. A vector that is both on the line and perpendicular to it satisfies (p−q)⊤(p−q)=0(\mathbf{p}-\mathbf{q})^\top(\mathbf{p}-\mathbf{q})=0, so p=q\mathbf{p}=\mathbf{q}, a contradiction. The foot is unique.

2. If a\mathbf{a} is replaced by 3a3\mathbf{a}, does the projection matrix change? Why?

Reference answer: It does not change. Substituting,

P′=(3a)(3a)⊤(3a)⊤(3a)=9 aa⊤9 a⊤a=aa⊤a⊤a=P.P'=\frac{(3\mathbf{a})(3\mathbf{a})^\top}{(3\mathbf{a})^\top(3\mathbf{a})} =\frac{9\,\mathbf{a}\mathbf{a}^\top}{9\,\mathbf{a}^\top\mathbf{a}} =\frac{\mathbf{a}\mathbf{a}^\top}{\mathbf{a}^\top\mathbf{a}}=P .

The reason: projection depends on the subspace (the line), not on which vector spans it, and a\mathbf{a} and 3a3\mathbf{a} span the same line. Likewise, replacing b\mathbf{b} by 2b2\mathbf{b} doubles the projection — projection is linear in b\mathbf{b}.

3. Prove that the higher-dimensional projection matrix satisfies P2=PP^2=P.

Reference answer: With P=A(A⊤A)−1A⊤P=A(A^\top A)^{-1}A^\top,

P2=A(A⊤A)−1A⊤A(A⊤A)−1A⊤.P^2=A(A^\top A)^{-1}A^\top A(A^\top A)^{-1}A^\top .

The middle three factors satisfy A⊤A(A⊤A)−1=IA^\top A(A^\top A)^{-1}=I, so

P2=A(A⊤A)−1A⊤=P.P^2=A(A^\top A)^{-1}A^\top=P .

Geometrically: once a vector has been projected into the column space, it already lies there, so projecting again leaves it fixed. Also P⊤=PP^\top=P, because

P⊤=(A(A⊤A)−1A⊤)⊤=A((A⊤A)−1)⊤A⊤=A(A⊤A)−1A⊤=P,P^\top=\big(A(A^\top A)^{-1}A^\top\big)^\top =A\big((A^\top A)^{-1}\big)^\top A^\top =A(A^\top A)^{-1}A^\top=P,

using that A⊤AA^\top A is symmetric and so is its inverse. Symmetry plus idempotence characterizes projection matrices.

4. Why can (A⊤A)−1(A^\top A)^{-1} not be split into A−1(A⊤)−1A^{-1}(A^\top)^{-1}?

Reference answer: Because in this chapter AA is m×nm\times n with m>nm>n and is not square, so it has no inverse at all. The identity B−1C−1=(CB)−1B^{-1}C^{-1}=(CB)^{-1} applies only to invertible square matrices; writing A−1A^{-1} for a non-square matrix is meaningless.

A⊤AA^\top A is n×nn\times n and is invertible when the columns of AA are independent, so (A⊤A)−1(A^\top A)^{-1} exists — but that is a different statement from "AA is invertible." Only when AA is itself an invertible n×nn\times n matrix does (A⊤A)−1=A−1(A⊤)−1(A^\top A)^{-1}=A^{-1}(A^\top)^{-1} hold, and then the column space is all of Rn\mathbb{R}^n and the projection collapses to

P=A(A⊤A)−1A⊤=A A−1(A⊤)−1A⊤=I.P=A(A^\top A)^{-1}A^\top=A\,A^{-1}(A^\top)^{-1}A^\top=I .

5. Write the AA, x\mathbf{x}, and b\mathbf{b} for fitting a line b=C+Dtb=C+Dt through three points.

Reference answer: The points are (t,b)=(1,1),(2,2),(3,2)(t,b)=(1,1),(2,2),(3,2), and b=C+Dtb=C+Dt gives one equation per point:

C+D⋅1=1,C+D⋅2=2,C+D⋅3=2.\begin{aligned} C+D\cdot1&=1,\\ C+D\cdot2&=2,\\ C+D\cdot3&=2. \end{aligned}

Collecting coefficients of the unknowns (C,D)(C,D):

A=[111213],x=[CD],b=[122].A=\begin{bmatrix}1&1\\1&2\\1&3\end{bmatrix}, \qquad \mathbf{x}=\begin{bmatrix}C\\D\end{bmatrix}, \qquad \mathbf{b}=\begin{bmatrix}1\\2\\2\end{bmatrix}.

The first column is the constant column (the intercept CC), the second holds the tt values (the slope DD). Three equations, two unknowns: usually unsolvable, so solve the normal equations A⊤Ax^=A⊤bA^\top A\hat{\mathbf{x}}=A^\top\mathbf{b} for the least-squares solution.

How this connects to the course

The previous lecture proved the orthogonality of the four subspaces; this one uses it to construct projections. The next carries the projection matrix through a numerical least-squares example and proves that A⊤AA^\top A is invertible when the columns of AA are independent.

来源