第 17 章

正交矩阵与 Gram-Schmidt

正交单位列让 QᵀQ=I,投影与最小二乘随之退化为点积;Gram-Schmidt 把任意无关列变成正交单位列,并给出 A=QR 分解。

Orthogonal Matrices and Gram-Schmidt

Orthonormal columns give QᵀQ=I, so projection and least squares collapse into dot products; Gram-Schmidt turns any independent columns into orthonormal ones and yields A=QR.

首发于 2019.09.25中 / EN
系统课程linear-algebraorthonormalgram-schmidtqr-decomposition
语言
字号
目录
篇内目录

正交单位向量

一组向量 q1,…,qn\mathbf{q}_1,\dots,\mathbf{q}_n 称为正交单位(orthonormal),如果

qi⊤qj={1,i=j,0,i≠j.\mathbf{q}_i^\top\mathbf{q}_j= \begin{cases} 1,&i=j,\\ 0,&i\neq j. \end{cases}

用 Kronecker 记号写作 qi⊤qj=δij\mathbf{q}_i^\top\mathbf{q}_j=\delta_{ij}。

把它们作为列放进矩阵 QQ,上述条件等价于

Q⊤Q=I.Q^\top Q=I.

这是整章最简洁的一条公式。

一个重要的推论

正交单位向量自动线性无关。若 ∑ciqi=0\sum c_i\mathbf{q}_i=\mathbf{0},两边点乘 qj\mathbf{q}_j:

cj=0.c_j=0.

所有系数为零,故无关。

时间轴

时间内容
0:07正交单位向量
3:17QTQ=IQ^{T}Q=I
4:37对角线为 1,其余为 0
6:36正交矩阵必须是方阵
13:42置换矩阵也是正交矩阵
15:11非方阵但列正交的情形
17:38正交列的好处
19:31QQTQQ^{T} 的投影意义
23:42非方阵只有左逆
25:27Gram-Schmidt 开始
26:54从 a1,a2a_1,a_2 构造 q1,q2q_1,q_2
29:48减去投影得到垂直分量
31:04误差向量就是垂直方向
38:35两个向量的数值例子
41:29单位化得到 q1,q2q_1,q_2
45:04AA 与 QQ 张成同一个列空间
46:28A=QRA=QR 中的 RR

正交矩阵

当 QQ 是方阵时,Q⊤Q=IQ^\top Q=I 意味着

Q⊤=Q−1.Q^\top=Q^{-1}.

这样的方阵称为正交矩阵。注意术语:矩形情形只说「列正交单位」,只有方阵才叫正交矩阵。

例子

  1. 置换矩阵:
Q=[001100010].Q=\begin{bmatrix}0&0&1\\1&0&0\\0&1&0\end{bmatrix}.

每列都是单位坐标向量,彼此正交。

  1. 旋转矩阵:
Q=[cos⁡θ−sin⁡θsin⁡θcos⁡θ].Q=\begin{bmatrix}\cos\theta&-\sin\theta\\ \sin\theta&\cos\theta\end{bmatrix}.

两列都是单位向量,点积 −cos⁡θsin⁡θ+sin⁡θcos⁡θ=0-\cos\theta\sin\theta+\sin\theta\cos\theta=0。

  1. Hadamard 矩阵:
Q=12[111−1].Q=\frac{1}{\sqrt2}\begin{bmatrix}1&1\\1&-1\end{bmatrix}.

四阶版本是

Q=12[11111−11−111−1−11−1−11].Q=\frac12\begin{bmatrix} 1&1&1&1\\ 1&-1&1&-1\\ 1&1&-1&-1\\ 1&-1&-1&1 \end{bmatrix}.

这类「只含 ±1\pm1」的正交矩阵只存在于某些阶数,哪些阶数可行至今没有完全解决。

矩形情形

QQ 不必是方阵。例如

Q=13[1−22−122]Q=\frac13\begin{bmatrix}1&-2\\2&-1\\2&2\end{bmatrix}

两列都是单位向量且正交,但 QQ 是 3×23\times2。此时

Q⊤Q=I2,QQ⊤≠I3.Q^\top Q=I_2, \qquad QQ^\top\neq I_3.

QQ⊤QQ^\top 是一个秩为 2 的投影矩阵。

为什么正交单位列好用

投影矩阵不用求逆

一般公式是

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

当 A=QA=Q 时,Q⊤Q=IQ^\top Q=I,逆消失:

P=QQ⊤.P=QQ^\top.

若 QQ 还是方阵,则 QQ⊤=IQQ^\top=I,投影到整个空间,P=IP=I。

验证两个性质:

(QQ⊤)⊤=QQ⊤,(QQ^\top)^\top=QQ^\top, (QQ⊤)2=Q(Q⊤Q)Q⊤=QQ⊤.(QQ^\top)^2=Q(Q^\top Q)Q^\top=QQ^\top.

最小二乘退化为点积

正规方程 Q⊤Qx^=Q⊤bQ^\top Q\hat{\mathbf{x}}=Q^\top\mathbf{b} 变成

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

逐分量写:

x^i=qi⊤b.\hat{x}_i=\mathbf{q}_i^\top\mathbf{b}.

也就是说,每个系数就是 b\mathbf{b} 在第 ii 个基向量上的投影长度。不需要解方程组,不需要求逆。

这是傅里叶级数、球谐展开等大量数学的共同结构:在正交基下,系数由内积直接给出。

Gram-Schmidt:把无关向量变成正交单位向量

给定线性无关的 a,b,c\mathbf{a},\mathbf{b},\mathbf{c},要构造正交单位向量。

两个向量的情形

第一步:保留第一个方向。

A=a.\mathbf{A}=\mathbf{a}.

第二步:从 b\mathbf{b} 中减去它在 A\mathbf{A} 方向上的投影。

B=b−A⊤bA⊤A A.\mathbf{B}=\mathbf{b}-\frac{\mathbf{A}^\top\mathbf{b}}{\mathbf{A}^\top\mathbf{A}}\,\mathbf{A}.

剩下的部分就是误差向量,垂直于 A\mathbf{A}。验证:

A⊤B=A⊤b−A⊤bA⊤A A⊤A=0.\mathbf{A}^\top\mathbf{B} =\mathbf{A}^\top\mathbf{b} -\frac{\mathbf{A}^\top\mathbf{b}}{\mathbf{A}^\top\mathbf{A}}\,\mathbf{A}^\top\mathbf{A} =0.

最后归一化:

q1=A∥A∥,q2=B∥B∥.\mathbf{q}_1=\frac{\mathbf{A}}{\|\mathbf{A}\|}, \qquad \mathbf{q}_2=\frac{\mathbf{B}}{\|\mathbf{B}\|}.

三个向量的情形

第三个向量要同时减去它在已经构造出的两个方向上的投影:

C=c−A⊤cA⊤A A−B⊤cB⊤B B.\mathbf{C}=\mathbf{c} -\frac{\mathbf{A}^\top\mathbf{c}}{\mathbf{A}^\top\mathbf{A}}\,\mathbf{A} -\frac{\mathbf{B}^\top\mathbf{c}}{\mathbf{B}^\top\mathbf{B}}\,\mathbf{B}.

再归一化得到 q3\mathbf{q}_3。

一般地,第 kk 步减去它在前面所有方向上的投影:

vk=ak−∑i=1k−1qi⊤akqi⊤qi qi.\mathbf{v}_k=\mathbf{a}_k-\sum_{i=1}^{k-1}\frac{\mathbf{q}_i^\top\mathbf{a}_k}{\mathbf{q}_i^\top\mathbf{q}_i}\,\mathbf{q}_i.

(若前面已归一化,分母为 1。)

数值例子

取

a=[111],b=[102].\mathbf{a}=\begin{bmatrix}1\\1\\1\end{bmatrix}, \qquad \mathbf{b}=\begin{bmatrix}1\\0\\2\end{bmatrix}.

第一步:

A=[111],A⊤A=3,A⊤b=1+0+2=3.\mathbf{A}=\begin{bmatrix}1\\1\\1\end{bmatrix}, \qquad \mathbf{A}^\top\mathbf{A}=3, \qquad \mathbf{A}^\top\mathbf{b}=1+0+2=3.

第二步:

B=b−33A=[102]−[111]=[0−11].\mathbf{B}=\mathbf{b}-\frac{3}{3}\mathbf{A} =\begin{bmatrix}1\\0\\2\end{bmatrix}-\begin{bmatrix}1\\1\\1\end{bmatrix} =\begin{bmatrix}0\\-1\\1\end{bmatrix}.

验证 A⊤B=0−1+1=0\mathbf{A}^\top\mathbf{B}=0-1+1=0。

第三步归一化:

q1=13[111],q2=12[0−11].\mathbf{q}_1=\frac{1}{\sqrt3}\begin{bmatrix}1\\1\\1\end{bmatrix}, \qquad \mathbf{q}_2=\frac{1}{\sqrt2}\begin{bmatrix}0\\-1\\1\end{bmatrix}.

列空间不变

Gram-Schmidt 只做「减去已有方向的投影」与「缩放」,得到的 QQ 与原矩阵 AA 有相同的列空间。它只是把同一空间换成了更好的基:从无关但不正交,变成正交单位。

A=QR 分解

如果 AA 的列是 a1,…,an\mathbf{a}_1,\dots,\mathbf{a}_n,Gram-Schmidt 给出的 QQ 满足

A=QR,A=QR,

其中 RR 是上三角矩阵。

以两列为例:

[a1a2]=[q1q2][q1⊤a1q1⊤a20q2⊤a2].\begin{bmatrix}\mathbf{a}_1&\mathbf{a}_2\end{bmatrix} = \begin{bmatrix}\mathbf{q}_1&\mathbf{q}_2\end{bmatrix} \begin{bmatrix} \mathbf{q}_1^\top\mathbf{a}_1 & \mathbf{q}_1^\top\mathbf{a}_2\\ 0 & \mathbf{q}_2^\top\mathbf{a}_2 \end{bmatrix}.

为什么左下角是零?因为 q2\mathbf{q}_2 的构造保证了它与 a1\mathbf{a}_1 正交:

q2⊤a1=0.\mathbf{q}_2^\top\mathbf{a}_1=0.

更一般地,第 jj 列只用到 q1,…,qj\mathbf{q}_1,\dots,\mathbf{q}_j,所以 RR 的第 jj 列在 jj 行以下全为零——这正是上三角。

与 LU 的类比

分解目的结果结构
A=LUA=LU消元下三角 × 上三角
A=QRA=QR正交化正交单位列 × 上三角

两者都是把矩阵拆成「结构更好的因子」。QR 在数值计算中尤其重要:解最小二乘时用 QR 比直接求 A⊤AA^\top A 的逆更稳定。

本讲结论

  • 正交单位列满足 Q⊤Q=IQ^\top Q=I;方阵时 Q⊤=Q−1Q^\top=Q^{-1},称为正交矩阵。
  • 正交单位向量自动线性无关。
  • 投影矩阵简化为 QQ⊤QQ^\top,最小二乘系数简化为 x^i=qi⊤b\hat{x}_i=\mathbf{q}_i^\top\mathbf{b}。
  • Gram-Schmidt 通过逐步减去投影构造正交方向,再归一化。
  • A=QRA=QR,RR 上三角;Gram-Schmidt 不改变列空间。

理解检验

1. 为什么正交单位向量一定线性无关?用点乘写出证明。

参考答案:设

c1q1+c2q2+⋯+cnqn=0.c_1\mathbf{q}_1+c_2\mathbf{q}_2+\cdots+c_n\mathbf{q}_n=\mathbf{0}.

两边点乘 qj\mathbf{q}_j,利用 qi⊤qj=δij\mathbf{q}_i^\top\mathbf{q}_j=\delta_{ij}:

c1(q1⊤qj)+⋯+cn(qn⊤qj)=cj⋅1=cj.c_1(\mathbf{q}_1^\top\mathbf{q}_j)+\cdots+c_n(\mathbf{q}_n^\top\mathbf{q}_j) =c_j\cdot1=c_j .

左边等于 0⊤qj=0\mathbf{0}^\top\mathbf{q}_j=0,所以 cj=0c_j=0。由于 jj 任意,全部系数为零,故线性无关。

关键点是正交性把「解一个方程组」变成了「分别点乘」:每个系数被单独分离出来。

2. 矩形 QQ 满足 Q⊤Q=IQ^\top Q=I,为什么 QQ⊤QQ^\top 不是 II?它的秩是多少?

参考答案:设 QQ 是 m×nm\times n 且 n<mn<m,例如本讲的 3×23\times2 例子。Q⊤Q=InQ^\top Q=I_n 只说明 nn 个列向量正交单位;而 QQ⊤QQ^\top 是 m×mm\times m 矩阵。

由秩的性质

rank⁡(QQ⊤)≤rank⁡(Q)=n<m,\operatorname{rank}(QQ^\top)\le \operatorname{rank}(Q)=n<m,

所以 QQ⊤QQ^\top 的秩至多为 nn,不可能是满秩的 ImI_m。几何上 QQ⊤QQ^\top 是把 Rm\mathbb{R}^m 投影到 QQ 的列空间(一个 nn 维子空间)的投影矩阵,它把与该子空间正交的方向全部压成零;而 ImI_m 保留所有方向。只有在 QQ 是方阵时 QQ⊤=IQQ^\top=I 才成立。

3. 用 Gram-Schmidt 处理 a=(1,0,0)\mathbf{a}=(1,0,0)、b=(1,1,0)\mathbf{b}=(1,1,0),写出 QQ 与 RR。

参考答案:第一步,A=a=(1,0,0)\mathbf{A}=\mathbf{a}=(1,0,0),A⊤A=1\mathbf{A}^\top\mathbf{A}=1,A⊤b=1\mathbf{A}^\top\mathbf{b}=1。

第二步,减去投影:

B=b−A⊤bA⊤AA=(1,1,0)−1⋅(1,0,0)=(0,1,0).\mathbf{B}=\mathbf{b}-\frac{\mathbf{A}^\top\mathbf{b}}{\mathbf{A}^\top\mathbf{A}}\mathbf{A} =(1,1,0)-1\cdot(1,0,0)=(0,1,0).

两者已是单位向量,归一化不改变它们:

q1=(1,0,0)⊤,q2=(0,1,0)⊤,\mathbf{q}_1=(1,0,0)^\top,\qquad \mathbf{q}_2=(0,1,0)^\top, Q=[100100].Q=\begin{bmatrix}1&0\\0&1\\0&0\end{bmatrix}.

RR 的元素是 rij=qi⊤ajr_{ij}=\mathbf{q}_i^\top\mathbf{a}_j(i≤ji\le j),其余为零:

R=[q1⊤aq1⊤b0q2⊤b]=[1101].R=\begin{bmatrix} \mathbf{q}_1^\top\mathbf{a}&\mathbf{q}_1^\top\mathbf{b}\\ 0&\mathbf{q}_2^\top\mathbf{b} \end{bmatrix} =\begin{bmatrix}1&1\\0&1\end{bmatrix}.

验证

QR=[100100][1101]=[110100],QR=\begin{bmatrix}1&0\\0&1\\0&0\end{bmatrix}\begin{bmatrix}1&1\\0&1\end{bmatrix} =\begin{bmatrix}1&1\\0&1\\0&0\end{bmatrix},

其两列正是 a\mathbf{a} 与 b\mathbf{b}(作为 3×23\times2 矩阵的列)。

4. 为什么 RR 的左下角元素为零?这与 Gram-Schmidt 的构造有何关系?

参考答案:RR 的元素是 rij=qi⊤ajr_{ij}=\mathbf{q}_i^\top\mathbf{a}_j。对 i>ji>j,需要说明 qi⊥aj\mathbf{q}_i\perp\mathbf{a}_j。

Gram-Schmidt 在构造 qi\mathbf{q}_i 时,从 ai\mathbf{a}_i 出发减去了它在 q1,…,qi−1\mathbf{q}_1,\dots,\mathbf{q}_{i-1} 上的全部投影,所以 qi\mathbf{q}_i 与前面所有 q1,…,qi−1\mathbf{q}_1,\dots,\mathbf{q}_{i-1} 正交。另一方面,aj\mathbf{a}_j(j<ij<i)属于 span⁡{q1,…,qj}⊆span⁡{q1,…,qi−1}\operatorname{span}\{\mathbf{q}_1,\dots,\mathbf{q}_j\}\subseteq\operatorname{span}\{\mathbf{q}_1,\dots,\mathbf{q}_{i-1}\},因此 qi⊥aj\mathbf{q}_i\perp\mathbf{a}_j,即 rij=0r_{ij}=0。

所以 RR 在主对角线以下全为零——上三角结构正是「第 jj 列只用到前 jj 个正交方向」的直接结果。

5. 在正交基下,最小二乘解的第 ii 个分量为什么就是 qi⊤b\mathbf{q}_i^\top\mathbf{b}?

参考答案:当矩阵的列是正交单位向量时,A=QA=Q 且 Q⊤Q=IQ^\top Q=I。正规方程

Q⊤Qx^=Q⊤bQ^\top Q\hat{\mathbf{x}}=Q^\top\mathbf{b}

左边的 Q⊤QQ^\top Q 就是单位矩阵,于是直接得到

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

逐分量写,第 ii 个分量是

x^i=qi⊤b,\hat{x}_i=\mathbf{q}_i^\top\mathbf{b},

即 b\mathbf{b} 与第 ii 个基向量的内积。

原因在于正交基消除了「交叉项」:一般情形下第 ii 个方程含有与其他系数耦合的项,需要联立求解;正交单位时,qi⊤qj=0\mathbf{q}_i^\top\mathbf{q}_j=0(i≠ji\ne j),每个方程只剩一个未知量,系数被独立地投影出来。这正是傅里叶系数、球谐展开中「系数=内积」的统一来源。

与前后课程的关系

这一讲结束了正交性章节:从向量正交、子空间正交,到正交基与正交矩阵。下一讲进入行列式,届时 QQ 的行列式、体积与正交变换的几何意义会再次出现。

Orthonormal vectors

Vectors q1,…,qn\mathbf{q}_1,\dots,\mathbf{q}_n are orthonormal when

qi⊤qj={1,i=j,0,i≠j.\mathbf{q}_i^\top\mathbf{q}_j= \begin{cases} 1,&i=j,\\ 0,&i\neq j. \end{cases}

With the Kronecker delta, qi⊤qj=δij\mathbf{q}_i^\top\mathbf{q}_j=\delta_{ij}.

Put them in the columns of QQ. The condition becomes

Q⊤Q=I.Q^\top Q=I.

That is the cleanest formula in the chapter.

An immediate consequence

Orthonormal vectors are automatically independent. If ∑ciqi=0\sum c_i\mathbf{q}_i=\mathbf{0}, take the dot product with qj\mathbf{q}_j:

cj=0.c_j=0.

All coefficients vanish, so the vectors are independent.

Timeline

TimeTopic
0:07Orthonormal vectors
3:17QTQ=IQ^{T}Q=I
4:37Ones on the diagonal, zeros elsewhere
6:36Orthogonal matrices are square
13:42Permutation matrices are orthogonal
15:11Rectangular matrices with orthonormal columns
17:38Why orthonormal columns help
19:31The projection meaning of QQTQQ^{T}
23:42Only a left inverse in the rectangular case
25:27Gram-Schmidt begins
26:54Producing q1,q2q_1,q_2 from a1,a2a_1,a_2
29:48Subtracting the projection
31:04The error vector is the perpendicular piece
38:35A numerical example with two vectors
41:29Normalizing to get q1,q2q_1,q_2
45:04AA and QQ span the same column space
46:28The RR in A=QRA=QR

Orthogonal matrices

When QQ is square, Q⊤Q=IQ^\top Q=I gives

Q⊤=Q−1.Q^\top=Q^{-1}.

Such a square matrix is called an orthogonal matrix. Note the terminology: a rectangular matrix only has "orthonormal columns"; only the square case earns the name orthogonal matrix.

Examples

  1. Permutation matrix:
Q=[001100010].Q=\begin{bmatrix}0&0&1\\1&0&0\\0&1&0\end{bmatrix}.

Each column is a coordinate unit vector, and they are mutually orthogonal.

  1. Rotation matrix:
Q=[cos⁡θ−sin⁡θsin⁡θcos⁡θ].Q=\begin{bmatrix}\cos\theta&-\sin\theta\\ \sin\theta&\cos\theta\end{bmatrix}.

Both columns are unit vectors and their dot product is −cos⁡θsin⁡θ+sin⁡θcos⁡θ=0-\cos\theta\sin\theta+\sin\theta\cos\theta=0.

  1. Hadamard matrix:
Q=12[111−1].Q=\frac{1}{\sqrt2}\begin{bmatrix}1&1\\1&-1\end{bmatrix}.

The four-by-four version is

Q=12[11111−11−111−1−11−1−11].Q=\frac12\begin{bmatrix} 1&1&1&1\\ 1&-1&1&-1\\ 1&1&-1&-1\\ 1&-1&-1&1 \end{bmatrix}.

Orthogonal matrices with only ±1\pm1 entries exist for some sizes; exactly which sizes admit them is still open.

Rectangular case

QQ need not be square. For instance

Q=13[1−22−122]Q=\frac13\begin{bmatrix}1&-2\\2&-1\\2&2\end{bmatrix}

has two orthonormal columns but is 3×23\times2. Then

Q⊤Q=I2,QQ⊤≠I3.Q^\top Q=I_2, \qquad QQ^\top\neq I_3.

QQ⊤QQ^\top is a rank-2 projection matrix.

Why orthonormal columns are better

No inversion in the projection

The general formula is

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

With A=QA=Q, Q⊤Q=IQ^\top Q=I, so the inverse disappears:

P=QQ⊤.P=QQ^\top.

If QQ is also square, QQ⊤=IQQ^\top=I: projection onto the whole space is the identity.

The two properties still hold:

(QQ⊤)⊤=QQ⊤,(QQ^\top)^\top=QQ^\top, (QQ⊤)2=Q(Q⊤Q)Q⊤=QQ⊤.(QQ^\top)^2=Q(Q^\top Q)Q^\top=QQ^\top.

Least squares becomes a dot product

The normal equations Q⊤Qx^=Q⊤bQ^\top Q\hat{\mathbf{x}}=Q^\top\mathbf{b} reduce to

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

Component by component,

x^i=qi⊤b.\hat{x}_i=\mathbf{q}_i^\top\mathbf{b}.

In words: each coefficient is the projection of b\mathbf{b} onto the ii-th basis vector. No system to solve, no inverse.

This is the shared structure of Fourier series, spherical harmonics, and much of applied mathematics: in an orthonormal basis, coefficients come directly from inner products.

Gram-Schmidt: from independent to orthonormal

Given independent a,b,c\mathbf{a},\mathbf{b},\mathbf{c}, construct orthonormal vectors.

Two vectors

Step one: keep the first direction.

A=a.\mathbf{A}=\mathbf{a}.

Step two: subtract from b\mathbf{b} its projection onto A\mathbf{A}.

B=b−A⊤bA⊤A A.\mathbf{B}=\mathbf{b}-\frac{\mathbf{A}^\top\mathbf{b}}{\mathbf{A}^\top\mathbf{A}}\,\mathbf{A}.

The remainder is perpendicular to A\mathbf{A}. Check:

A⊤B=A⊤b−A⊤bA⊤A A⊤A=0.\mathbf{A}^\top\mathbf{B} =\mathbf{A}^\top\mathbf{b} -\frac{\mathbf{A}^\top\mathbf{b}}{\mathbf{A}^\top\mathbf{A}}\,\mathbf{A}^\top\mathbf{A} =0.

Finally normalize:

q1=A∥A∥,q2=B∥B∥.\mathbf{q}_1=\frac{\mathbf{A}}{\|\mathbf{A}\|}, \qquad \mathbf{q}_2=\frac{\mathbf{B}}{\|\mathbf{B}\|}.

Three vectors

The third vector must lose its components along both directions already built:

C=c−A⊤cA⊤A A−B⊤cB⊤B B.\mathbf{C}=\mathbf{c} -\frac{\mathbf{A}^\top\mathbf{c}}{\mathbf{A}^\top\mathbf{A}}\,\mathbf{A} -\frac{\mathbf{B}^\top\mathbf{c}}{\mathbf{B}^\top\mathbf{B}}\,\mathbf{B}.

Normalize to get q3\mathbf{q}_3.

In general, step kk subtracts the projections onto all earlier directions:

vk=ak−∑i=1k−1qi⊤akqi⊤qi qi.\mathbf{v}_k=\mathbf{a}_k-\sum_{i=1}^{k-1}\frac{\mathbf{q}_i^\top\mathbf{a}_k}{\mathbf{q}_i^\top\mathbf{q}_i}\,\mathbf{q}_i.

(If the earlier vectors are already normalized, the denominators are 1.)

A numerical example

Take

a=[111],b=[102].\mathbf{a}=\begin{bmatrix}1\\1\\1\end{bmatrix}, \qquad \mathbf{b}=\begin{bmatrix}1\\0\\2\end{bmatrix}.

Step one:

A=[111],A⊤A=3,A⊤b=1+0+2=3.\mathbf{A}=\begin{bmatrix}1\\1\\1\end{bmatrix}, \qquad \mathbf{A}^\top\mathbf{A}=3, \qquad \mathbf{A}^\top\mathbf{b}=1+0+2=3.

Step two:

B=b−33A=[102]−[111]=[0−11].\mathbf{B}=\mathbf{b}-\frac{3}{3}\mathbf{A} =\begin{bmatrix}1\\0\\2\end{bmatrix}-\begin{bmatrix}1\\1\\1\end{bmatrix} =\begin{bmatrix}0\\-1\\1\end{bmatrix}.

Check: A⊤B=0−1+1=0\mathbf{A}^\top\mathbf{B}=0-1+1=0.

Step three, normalize:

q1=13[111],q2=12[0−11].\mathbf{q}_1=\frac{1}{\sqrt3}\begin{bmatrix}1\\1\\1\end{bmatrix}, \qquad \mathbf{q}_2=\frac{1}{\sqrt2}\begin{bmatrix}0\\-1\\1\end{bmatrix}.

The column space does not change

Gram-Schmidt only subtracts projections and rescales, so QQ and AA have the same column space. It merely replaces one basis by a better one: from independent but skewed to orthonormal.

The A=QR factorization

If the columns of AA are a1,…,an\mathbf{a}_1,\dots,\mathbf{a}_n, Gram-Schmidt produces QQ with

A=QR,A=QR,

where RR is upper triangular.

For two columns:

[a1a2]=[q1q2][q1⊤a1q1⊤a20q2⊤a2].\begin{bmatrix}\mathbf{a}_1&\mathbf{a}_2\end{bmatrix} = \begin{bmatrix}\mathbf{q}_1&\mathbf{q}_2\end{bmatrix} \begin{bmatrix} \mathbf{q}_1^\top\mathbf{a}_1 & \mathbf{q}_1^\top\mathbf{a}_2\\ 0 & \mathbf{q}_2^\top\mathbf{a}_2 \end{bmatrix}.

Why is the lower-left entry zero? Because q2\mathbf{q}_2 was constructed orthogonal to a1\mathbf{a}_1:

q2⊤a1=0.\mathbf{q}_2^\top\mathbf{a}_1=0.

More generally, the jj-th column uses only q1,…,qj\mathbf{q}_1,\dots,\mathbf{q}_j, so column jj of RR is zero below row jj — exactly upper triangular.

Analogy with LU

FactorizationPurposeStructure
A=LUA=LUEliminationlower triangular × upper triangular
A=QRA=QROrthogonalizationorthonormal columns × upper triangular

Both split a matrix into better-structured factors. QR is especially important numerically: solving least squares with QR is more stable than forming (A⊤A)−1(A^\top A)^{-1} directly.

Takeaways

  • Orthonormal columns satisfy Q⊤Q=IQ^\top Q=I; for a square matrix Q⊤=Q−1Q^\top=Q^{-1}, and it is called orthogonal.
  • Orthonormal vectors are automatically independent.
  • Projection reduces to QQ⊤QQ^\top, and least-squares coefficients to x^i=qi⊤b\hat{x}_i=\mathbf{q}_i^\top\mathbf{b}.
  • Gram-Schmidt builds orthogonal directions by subtracting projections, then normalizes.
  • A=QRA=QR with RR upper triangular; the column space is unchanged.

Check your understanding

1. Why are orthonormal vectors necessarily independent? Write the dot-product proof.

Reference answer: Suppose

c1q1+c2q2+⋯+cnqn=0.c_1\mathbf{q}_1+c_2\mathbf{q}_2+\cdots+c_n\mathbf{q}_n=\mathbf{0}.

Take the dot product with qj\mathbf{q}_j and use qi⊤qj=δij\mathbf{q}_i^\top\mathbf{q}_j=\delta_{ij}:

c1(q1⊤qj)+⋯+cn(qn⊤qj)=cj⋅1=cj.c_1(\mathbf{q}_1^\top\mathbf{q}_j)+\cdots+c_n(\mathbf{q}_n^\top\mathbf{q}_j) =c_j\cdot1=c_j .

The left side equals 0⊤qj=0\mathbf{0}^\top\mathbf{q}_j=0, so cj=0c_j=0. Since jj is arbitrary, all coefficients vanish and the set is independent.

The point is that orthogonality turns "solve a system" into "take dot products": each coefficient is isolated.

2. For rectangular QQ with Q⊤Q=IQ^\top Q=I, why is QQ⊤≠IQQ^\top\neq I? What is its rank?

Reference answer: Let QQ be m×nm\times n with n<mn<m, as in the lecture's 3×23\times2 example. The relation Q⊤Q=InQ^\top Q=I_n says only that the nn columns are orthonormal; but QQ⊤QQ^\top is m×mm\times m.

By the rank inequality

rank⁡(QQ⊤)≤rank⁡(Q)=n<m,\operatorname{rank}(QQ^\top)\le \operatorname{rank}(Q)=n<m,

the rank of QQ⊤QQ^\top is at most nn, so it cannot be the full-rank ImI_m. Geometrically, QQ⊤QQ^\top projects Rm\mathbb{R}^m onto the nn-dimensional column space of QQ, collapsing every orthogonal direction to zero, whereas ImI_m preserves all directions. Only for square QQ does QQ⊤=IQQ^\top=I hold.

3. Apply Gram-Schmidt to a=(1,0,0)\mathbf{a}=(1,0,0) and b=(1,1,0)\mathbf{b}=(1,1,0); write QQ and RR.

Reference answer: Step one: A=a=(1,0,0)\mathbf{A}=\mathbf{a}=(1,0,0), with A⊤A=1\mathbf{A}^\top\mathbf{A}=1 and A⊤b=1\mathbf{A}^\top\mathbf{b}=1.

Step two, subtract the projection:

B=b−A⊤bA⊤AA=(1,1,0)−1⋅(1,0,0)=(0,1,0).\mathbf{B}=\mathbf{b}-\frac{\mathbf{A}^\top\mathbf{b}}{\mathbf{A}^\top\mathbf{A}}\mathbf{A} =(1,1,0)-1\cdot(1,0,0)=(0,1,0).

Both are already unit vectors, so normalizing changes nothing:

q1=(1,0,0)⊤,q2=(0,1,0)⊤,\mathbf{q}_1=(1,0,0)^\top,\qquad \mathbf{q}_2=(0,1,0)^\top, Q=[100100].Q=\begin{bmatrix}1&0\\0&1\\0&0\end{bmatrix}.

The entries of RR are rij=qi⊤ajr_{ij}=\mathbf{q}_i^\top\mathbf{a}_j for i≤ji\le j, and zero otherwise:

R=[q1⊤aq1⊤b0q2⊤b]=[1101].R=\begin{bmatrix} \mathbf{q}_1^\top\mathbf{a}&\mathbf{q}_1^\top\mathbf{b}\\ 0&\mathbf{q}_2^\top\mathbf{b} \end{bmatrix} =\begin{bmatrix}1&1\\0&1\end{bmatrix}.

Check:

QR=[100100][1101]=[110100],QR=\begin{bmatrix}1&0\\0&1\\0&0\end{bmatrix}\begin{bmatrix}1&1\\0&1\end{bmatrix} =\begin{bmatrix}1&1\\0&1\\0&0\end{bmatrix},

whose two columns are exactly a\mathbf{a} and b\mathbf{b}.

4. Why is the lower-left entry of RR zero, and how does the construction force it?

Reference answer: The entries are rij=qi⊤ajr_{ij}=\mathbf{q}_i^\top\mathbf{a}_j. For i>ji>j we must show qi⊥aj\mathbf{q}_i\perp\mathbf{a}_j.

When Gram-Schmidt builds qi\mathbf{q}_i, it starts from ai\mathbf{a}_i and subtracts its projections onto q1,…,qi−1\mathbf{q}_1,\dots,\mathbf{q}_{i-1}, so qi\mathbf{q}_i is orthogonal to all earlier q1,…,qi−1\mathbf{q}_1,\dots,\mathbf{q}_{i-1}. Since aj\mathbf{a}_j with j<ij<i lies in span⁡{q1,…,qj}⊆span⁡{q1,…,qi−1}\operatorname{span}\{\mathbf{q}_1,\dots,\mathbf{q}_j\}\subseteq\operatorname{span}\{\mathbf{q}_1,\dots,\mathbf{q}_{i-1}\}, we get qi⊥aj\mathbf{q}_i\perp\mathbf{a}_j, i.e. rij=0r_{ij}=0.

So RR is zero below the diagonal — the upper triangular structure is a direct consequence of "column jj uses only the first jj orthogonal directions."

5. In an orthonormal basis, why is the ii-th least-squares coefficient exactly qi⊤b\mathbf{q}_i^\top\mathbf{b}?

Reference answer: With orthonormal columns, A=QA=Q and Q⊤Q=IQ^\top Q=I. The normal equations

Q⊤Qx^=Q⊤bQ^\top Q\hat{\mathbf{x}}=Q^\top\mathbf{b}

have Q⊤Q=IQ^\top Q=I on the left, giving directly

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

Componentwise, the ii-th coefficient is

x^i=qi⊤b,\hat{x}_i=\mathbf{q}_i^\top\mathbf{b},

the inner product of b\mathbf{b} with the ii-th basis vector.

The reason is that an orthonormal basis removes the cross terms: in general the ii-th equation couples to the other coefficients and the system must be solved jointly; when qi⊤qj=0\mathbf{q}_i^\top\mathbf{q}_j=0 for i≠ji\ne j, each equation contains a single unknown, and every coefficient is projected out independently. This is the common source of "coefficient equals inner product" in Fourier series and spherical harmonic expansions.

How this connects to the course

This lecture closes the orthogonality chapter: from orthogonal vectors and subspaces to orthogonal bases and orthogonal matrices. The next chapter turns to determinants, where the determinant of QQ, volume, and the geometry of orthogonal transformations reappear.

来源