《线性代数导论》笔记 第4章 Orthogonality 正交性(垂直性)

Least squares


本文为《Introduction to Linear Algebra》5ed 的读书笔记

orthogonal 90°直角的,垂直的

4.0 为什么向量内积\(a^Tb\) 等于 \(|\mathbf{a}||\mathbf{b}|\cos\theta\)

ChatGPT的回答

\[\mathbf{a}\cdot\mathbf{b}=a_1b_1 + a_2b_2 \]

The formula above is the coordinate version of geometric dot product.

\[\mathbf{a}\cdot\mathbf{b}=|\mathbf{a}||\mathbf{b}|\cos\theta \]

They are the same thing, just written in two different ways.

Suppose:

\[\mathbf{a}=(a_1,a_2),\qquad \mathbf{b}=(b_1,b_2) \]

The dot product can also be derived using the cosine rule.
The length of \(\mathbf{a}-\mathbf{b}\) is \(|\mathbf{a}-\mathbf{b}|^2\)
Using coordinates:

\[|\mathbf{a}-\mathbf{b}|^2 = (a_1-b_1)^2+(a_2-b_2)^2 \]

Expanding:

\[=a_1^2-2a_1b_1+b_1^2 + a_2^2-2a_2b_2+b_2^2 \]

Rearrange:

\[==(a_1^2+a_2^2) + (b_1^2+b_2^2) - 2(a_1b_1 +a_2b_2) \]

Now from the cosine rule:

\[|\mathbf{a}-\mathbf{b}|^2 = |\mathbf{a}|^2 + |\mathbf{b}|^2 - |\mathbf{a}||\mathbf{b}|\cos\theta \]

Comparing the two equations, we get:

\[ 2(a_1b_1 +a_2b_2) = 2|\mathbf{a}||\mathbf{b}|\cos\theta \]

Therefore:

\[\boxed{\mathbf{a}\cdot\mathbf{b}=a_1b_1+b_2b_2} \]

is not a different operation. it is the same dot product calculated from the vector components.

余弦定理 可以通过 A向BC作垂线交于点D,然后求\(AC^2=CD^2+AD^2\) 可得。

从几何公式\(|\mathbf{a}||\mathbf{b}|\cos\theta\) 推导到向量内积\(a^Tb\)

之前在博客上面写的证明感觉更直白,设点乘操作为\(\mathbf{a}\cdot\mathbf{b}=|\mathbf{a}||\mathbf{b}|\cos\theta\) , 将a向量拆成a1+a2,发现\(a_1\cdot b+a_2\cdot b\)的值和\(\mathbf{a}\cdot\mathbf{b}\)相等,证明了点乘操作符是满足分配律的。 接着只要把a,b两个向量拆成正交的x,y,z轴上的向量即可,最终值等于\(a_1b_1+b_2b_2\)+...

从向量内积\(a^Tb\) 推导到\(|\mathbf{a}||\mathbf{b}|\cos\theta\)

首先,在纸上画出向量a和向量b。
对于\(a^Tb\),我们可以将\(b\)拆为\(b_r+b_n\) ,\(b_r\)属于\(a^T\)的行空间(row space),\(b_n\)属于\(a^T\)的nullspace。
\(a^Tb\)=\(a^Tb_r\) + \(a^Tb_n\) = \(a^Tb_r\) 。 \(b=b_r+b_n\), 且由于 \(a^Tb_n=0\) , \(a\)向量 垂直 \(b_n\)向量。
由于 \(b_r\)属于 \(a^T\)的行空间, 则\(b_r = ca\) 。 \(a^Tb_r=a^Tca=c|\mathbf{a}|^2\)

\(|\mathbf{a}||\mathbf{b}|\cos\theta\) =\(|\mathbf{a}||\mathbf{b_r}|=c|\mathbf{a}|^2\)

证明 \(a^Tb=0\)表示a和b垂直

这里我们证明两个向量的内积为0,表示这两个向量互相垂直。
设\(\mathbf{c}=\mathbf{a}-\mathbf{b}\),\(\mathbf{c}=(a_1-b_1,a_2-b_2, ...,a_n-b_n)\) 则
\(|\mathbf{c}|^2=(a_1-b_1)^2+...+(a_n-b_n)^2\)
\(=a_1^2-2a_1b_1+b_1^2+...+a_n^2-2a_nb_n+b_n^2\)
\(=a_1^2+...+a_n^2+b_1^2+...+b_n^2 -2a_1b_1-...-2a_nb_n\)
\(=|\mathbf{a}|^2 + |\mathbf{b}|^2 - 2(a_1b_1+...+a_nb_n)\)

如果内积为0,也就是\(a_1b_1+...+a_nb_n=0\),上式就变为 \(|\mathbf{c}|^2=|\mathbf{a}|^2 + |\mathbf{b}|^2\),向量a和b互相垂直。

但我感觉后面学习了 基变化相关的知识,可能更容易理解这个。

4.1 Orthogonality of the Four Subspaces

两个向量是垂直的,如果它们的点乘积是0: \(v·w=v^Tw=0\)

The row space is perpendicular to the nullspace. Every row of A is perpendicular to
every solution of Ax = 0.

The column space is perpendicular to the nullspace of \(A^T\).

DEFINITION Two subspaces \(V\) and \(W\) of a vector space are orthogonal if every vector \(v\) in \(V\) is perpendicular to every vector \(w\) in \(W\)

Example Two walls look perpendicular but those two subspaces are not orthogonal! The meeting line is in both \(V\) and \(W\) -and this line is not perpendicular to itself. Two planes (dimensions 2 and 2 in \(R^3\)) cannot be orthogonal subspaces.

Every vector \(x\) in the nullspace is perpendicular to every row of \(A\), because \(Ax = 0\).
The nullspace \(N(A)\) and the row space \(C(A^T)\) are orthogonal subspaces of \(R^n\).

由于 \(A\)里面的每个行向量和\(x\)的点乘都为0.(这个就是\(Ax=0\)的含义) 所以nullspace和row space是orthogonal的。

同理 left nullspace \(N(A)\) 和 column space \(C(A)\) 是正交的

基础的4个子空间(fundamental subspaces)不仅仅是垂直的,它们的维度也是互补的(子空间的维度相加 等于 向量的维度)

DEFINITION The orthogonal complement of a subspace \(V\) contains every vector that is perpendicular to \(V\). This orthogonal subspace is denoted by \(V^\perp\). (pronounced "\(V\) perp").

By this definition, the nullspace is the orthogonal complement of the row space.
Every x that is perpendicular to the rows satisfies \(Ax = 0\), and lies in the nullspace.

The reverse is also true. If v is orthogonal to the nullspace, it must be in the row
space.
Otherwise we could add this \(v\) as an extra row of the matrix, without changing its
nullspace. The row space would grow, which breaks the law \(r + (n - r) = n\). We conclude
that the nullspace complement \(N(A)^\perp\) is exactly the row space \(C(A^T)\).

Fundamental Theorem of Linear Algebra, Part 2
\(N(A)\) is the orthogonal complement of the row space \(C(A^T)\) (in \(R^n\)).
**\(N(A^T)\) is the orthogonal complement of the row space \(C(A)\) (in \(R^m\)).

线性代数的基础定理Part1 讲了子空间的维度。 Part2 讲了子空间之间的90°角。 正交补的补(complements)是指每个\(x\)都能被分割为一个行空间向量\(x_r\)以及一个nullspace向量\(x_n\) .
当A乘以\(x=x_r+x_n\), \(Ax=Ax_r+Ax_n\) 会:

  • nullspace 向量变为零: \(Ax_n=0\)
  • row space 向量转变为 column space向量: \(Ax_r =Ax\)

dim(V) + dim(W) = dim(V ∩ W) + dim(V + W)

Part 1 gave the dimensions of the subspaces. Part 2 gives the 90° angles between them. The point of "complements" is that every \(x\) can be split into a row space component \(X_r\) and a nullspace component \(X_n\). When \(A\) multiplies \(x = X_r + X_n\) , Figure 4.3 shows what happens to \(Ax=Ax_r+Ax_n\) :

  • The nullspace component goes to zero: \(Ax_n = 0\).
  • The row space component goes to the column space: \(Ax_r = Ax\).

向量线性无关主要是 垂直的那个分量引起的 。

Every vector goes to the column space! Multiplying by A cannot do anything else.
More than that: Every vector b in the column space comes from one and only one vector \(X_r\) in the row space.

There is an \(r\) by \(r\) invertible matrix hiding inside \(A\), if we throw away the two nullspaces.

From the row space to the column space, A is invertible

Combining Bases from Subspaces

a basis is (linearly independent vectors that span the space).
When the count is right, one property implies the other:

Any \(n\) independent vectors in \(R^n\) must span \(R^n\). So they are a basis.
Any \(n\) vectors that span \(R^n\) must be independent. So they are a basis.

If the \(n\) columns of \(A\) are independent, they span \(R^n\). So \(Ax = b\) is solvable.
If the \(n\) columns span \(R^n\), they are independent. So \(Ax = b\) has only one solution.

If uniqueness implies existence and existence implies uniqueness. Then A is invertible.

If there are no free variables, the solution x is unique. There must be n pivot columns.
Then back substitution solves Ax = b (the solution exists).

Each \(x\) is the sum \(x_r + x_n\) of a row space vector \(x_r\) and a nullspace vector \(x_n\) ,

知识要点

  1. Subspaces \(V\) and \(W\) are orthogonal if every \(v\) in \(V\) is orthogonal to every \(w\) in \(W\).
  2. \(V\) and \(W\) are "orthogonal complements" if \(W\) contains all vectors perpendicular to \(V\) (and vice versa). Inside \(R^n\), the dimensions of complements \(V\) and \(W\) add to \(n\).
  3. The nullspace \(N(A)\) and the row space \(C(A^T)\) are orthogonal complements, with dimensions \((n - r) + r = n\). Similarly \(N(A^T)\) and \(C(A)\) are orthogonal complements with \((m - r) + r = m\).
  4. Any \(n\) independent vectors in \(R^n\) span \(R^n\) . Any \(n\) spanning vectors are independent.

Problem Set 4.1

第9题:

证明:如果 \(A^TAx=0\) ,那么\(Ax=0\) 。
解:因为 \(Ax\)必然位于\(A\)的column space, 接着\(A^TAx=0\)表示\(Ax\)位于 \(A^T\)的nullspace。 而这两个spaces是orthogonal的,\(Ax\)同时属于这两个向量空间,但这两个向量空间的 交集只有 0向量。 所以如果\(A^TAx=0\) ,那么\(Ax=0\) 。

因为 \(A^TAx=0\) ,那么\(Ax=0\) 。 所以 \(A^TA\)和\(A\)有着相同的 nullspace.

4.2 Projections

\(A^TA\) is invertible if and only if \(A\) has linearly independent columns.

首先4.1的第9题,证明了\(A^TA\)和\(A\)有着相同的 nullspace.
因此,如果\(A\)有着线性无关的列,说明nullspace只包含0向量。 \(A^TA\)有着相同的nullspace,因此\(A^TA\)的列也是线性无关的,column rank = row rank = n

\(A^TA\) 就是n个列向量彼此的内积。

4.3 Least Squares Approximations 最小二乘近似

\(Ax = b\) 经常会没有解。这是因为等式多于未知数,行多于列。(根本原因感觉还是因为模型过于简单,没有考虑到的因素就会以噪音的形式出现)

当\(Ax=b\) 没有解,可以等式两边乘以\(A^T\),求解 normal equation \(A^TA\hat{x}=A^Tb\)

这里等式两边乘以\(A^T\),是在求向量相等不得的时候,退而求其次,转而求内积相等。
\(A^TA\hat{x}=A^Tb\) 被称为垂直等式(normal equation),是因为\(e=A\hat{x}-b\) 垂直于\(A\)的列向量。
当\(e\)垂直\(A\)的列空间,\(e\)的长度最短,此时可以看作误差最小。
\(|e|\)最小时,\(e^2\)也是最小。 \(e^2 = e_1^2 + e_2^2 + e_3^2 + e_4^2\) ,因此也被称为最小(误差)二乘近似。

Problem Set 4.3

对于 \(b = C + Dt\) ,

  • 已知系统性的全局参数\(C\)和\(D\), 对于不同的\(t\),推导出相关的\(b\),被称为推演法。
  • 已知一系列数据\(b\)和\(t\),分析归纳出系统性的全局参数 \(C\)和\(D\),被称为归纳法。

这里的方法不仅可以求线性函数的参数,还可以求复杂函数的参数,因为数据代入复杂函数化简后得到的还是线性函数。

比如对于\(t=0,1,3,4\),存在 \(b=0,8,8,20\)

\[\begin{equation} \begin{split} C+D×0 = 0 \newline C+D×1 = 8 \\ C+D×3 = 8 \\ C+D×4 = 20 \\ \end{split} \end{equation} \]

将上面等式整理成矩阵形式:

\[\begin{bmatrix} 1 & 0\\ 1 & 1\\ 1 & 3\\ 1 & 4\\ \end{bmatrix} \begin{bmatrix} C\\ D \end{bmatrix} = \begin{bmatrix} 0\\ 8\\ 8\\ 20 \end{bmatrix} \]

这里矩阵按行向量看,是推演法。矩阵按列向量看是归纳法。

4.4 Orthonormal Bases and Gram-Schmidt

DEFINITION The vectors \(q_1,...,q_n\) are orthonormal if

\[q_i^Tq_j = \left \{ \begin{aligned} & 0 \quad when \space i\neq j \quad(\textbf{orthogonal} \space vectors)\\ &1 \quad when \space i = j \quad(\textbf{unit} \space vectors:||\textbf{q}_i||=1) \end{aligned} \right. \]

A matrix with orthonormal columns is assigned the special letter \(Q\).

对于一个矩阵,如果它的列向量是 标准正交(orthonormal) 的,则使用特殊符号\(Q\)表示这个矩阵。
这里\(Q\) 看着确实挺像是 一个\(O\) 再加一个\(n\)的

A matrix \(Q\) with orthonormal columns satisfies \(Q^TQ=I\) :

\[Q^TQ= \begin{bmatrix} —q_1^T— \\ —q_2^T— \\ —q_n^T— \\ \end{bmatrix} \begin{bmatrix} | & | & | \\ q_1 & q_2 & q_n \\ | & | & | \\ \end{bmatrix} = \begin{bmatrix} 1 & 0 & \cdots & 0\\ 0 & 1 & \cdots & 0\\ \vdots & \vdots & \ddots & \vdots\\ 0 & 0 & \cdots &1\\ \end{bmatrix} =I \]

A Gram matrix is a matrix of all pairwise inner products of a set of vectors. If your vectors are the columns of a matrix A, the Gram matrix is \(G=A^TA\) .

形如\(A^TA\) 这种求向量两两内积的矩阵,被称为 Gram matrix。

为什么旋转矩阵的列是标准正交的(orthonormal)

旋转矩阵 \(Q\) 会逆时针旋转平面上的每个向量 \(\theta\) 角度

\[Q= \begin{bmatrix} cos\theta & -sin\theta \\ sin\theta & cos\theta \end{bmatrix} \quad Q^T=Q^{-1}= \begin{bmatrix} cos\theta & sin\theta \\ -sin\theta & cos\theta \end{bmatrix} \]

旋转操作在几何上有一个最根本的特性:旋转不改变物体的形状和大小。

保内积:旋转前后,任意两个向量的夹角不变。即对于任意单位向量 \(u\),\(v\),旋转矩阵 \(R\) 必须满足:\((Ru)⋅(Rv)=u⋅v\)

将内积写成转置形式:\((Ru)^T(Rv)=u^TR^TRv=u^Tv\)。
由于这对任意单位向量 \(u\),\(v\) 都成立,必然推出: \(R^TR=I\)

保长度(保距):旋转不改变向量的模长。即\(||Rv|| =||v||\) 。

要让 \((Rv)^T(Rv)=v^TR^TRv=v^Tv\) ,则必然推出\(R^TR=I\)

所以 下面2个条件是等价的:

  1. 矩阵不会改变向量的长度。
  2. 矩阵的列是标准正交的。

并且它们能推出 向量角度不变。

条件 能否推出其他?
① 保角(角度不变) 只能推出矩阵是“共形变换”(相似变换),可能是 kR(旋转+均匀缩放),不能推出②或③。
② 保长(长度不变) 可以推出③,且是等价的。
③ 列标准正交\((R^TR=I)\) 可以推出②,且是等价的;也能推出①(因为长度不变则内积不变,角度自然不变)。

为什么标准正交基(orthonormal bases) 能够简化投影公式

如果我们用\(Q\) 代替\(A\) ,那么\(A^TA\)就会简化成 \(Q^TQ=I\) ,下面我们用空白部分代替单位矩阵\(I\)

\[ \begin{aligned} & \_\_\hat{x}=Q^Tb\newline & p = Q\hat{x}\newline & P=Q\_\_Q^T \end{aligned} \]

对于 标准正交基, 投影矩阵是 \(P=QQ^T\) , \(p=Q\hat{x}=QQ^Tb\)

\[p= \begin{bmatrix} | & | & | \\ q_1 & q_2 & q_n \\ | & | & | \\ \end{bmatrix} \begin{bmatrix} q_1^Tb \\ q_2^Tb \\ q_n^Tb \\ \end{bmatrix} = q_1(q_1^Tb)+...+q_n(q_n^Tb) \]

标准正交基的投影 这个应该是上两章节通用投影的 原型,不能说这个是简化版,应该说前两章讲的是标准正交基的泛化版本。。

\(p=A(A^TA)^{-1}A^Tb\) 相比 \(p=QQ^Tb\) 多出了 中间 \(A^TA\)的逆(inverse)的部分。

为什么会多出这部分?
首先\(A^TA\) 是\(A\)里面列向量的两两内积,这边乘以 \(A^TA\)的逆,或许是为了消除 列向量两两内积的部分?

从投影的逻辑来看,如果 \(b\) 所投射的目标向量空间的基,如果不是正交的,那么内积便会有重复的部分,如果不是单位向量,那么内积便会放大或者缩小。

\(p=Q\hat{x}=QQ^Tb\) 在干什么?

\(q^Tb\) 就是q·b,是点乘,在求内积
因为内积的公式是 |a||b|cosθ

所以这里其中一个向量是单位向量的话,结果就是 另一个向量在这个单位向量上的投影

如果单位向量是互相垂直的,也就是绝对独立,没有任何的重复冗余。那么一个向量和这些单位向量的内积(长度)再乘以单位向量(方向),\(qq^Tb\)就是起到了将向量拆解的效果.

计算投影的向量,是为了得到一个最接近\(b\)的投影向量,因此需要尽可能的接近\(b\),所以\(Q\)里面的必须是单位向量,这样计算内积不会改变投影向量的大小。并且\(Q\)里面的单位向量必须正交,这样加起来还原的时候,不会有重复的投影。

Gram-Schmidt 正交化

上面说到正交单位向量(orthonormal vectors)的价值,现在我们来讲解"Gram-Schmidt方法"是怎么产生 正交单位向量(orthonormal vectors)

首先我们会有3个独立的向量\(a\), \(b\), \(c\) ,正交就是没有冗余的意思,正交化就是消除冗余的分量。

首先是 向量\(a\), 由于此时只有一个向量,我们可以令\(A = a\) ,直接保留原向量。
接着是向量\(b\),我们需要得到一个垂直\(A\)的向量\(B\) 。 这里只需要从\(b\)中减去\(b\)在\(A\)上的投影(消除冗余),就能得到垂直的部分,也就是正交向量\(B\)。 (因为一个向量A它的分量不是垂直于向量空间S,就是在向量空间S内部)

\[B = b- \dfrac{A^Tb}{A^TA}A \]

对于接下来新增的向量, 我们需要保证它们是垂直于之前的向量的。这里需要从新增向量中减去它们在之前向量上面的投影。

\[C = c- \dfrac{A^Tc}{A^TA}A -\dfrac{B^Tc}{B^TB}B \]

最后正交向量 \(A,B,C,D\) 各自除以自己的长度。得到的正交单位向量\(q_1,q_2,q_3,q_4\) 是orthonormal的

A=QR 因式分解

我们从矩阵A开始,它的列是\(a,b,c\) 。最终我们得到矩阵\(Q\),它的列是\(q_1,q_2,q_3\) 。 这些矩阵是以哪种形式相关的?毕竟向量\(a,b,c\)可以由\(q_1,q_2,q_3\)组合得到(反之亦然),一定存在某个矩阵连接着\(A\)和\(Q\)。这个矩阵就是上三角矩阵\(R\), \(A=QR\)

每一步 \(a_1,...,a_k\) 是\(q_1,...,q_k\)的组合。 后续的\(q\)不会影响当前的\(a\)。 连接矩阵\(R\)是上三角形的。

\[\begin{bmatrix} a & b & c \end{bmatrix} = \begin{bmatrix} q_1 & q_2 & q_3 \end{bmatrix} \begin{bmatrix} q_1^Ta & q_1^Tb & q_1^Tc \\ & q_2^Tb & q_2^Tc \\ & & q_3^Tc \end{bmatrix} \]

\(A=QR\) 就是 将向量 \(a, b, c\) 转化为 \(q_1, q_2, q_3\)的过程。

可以看到 \(A=QR\) 就是将 \(a, b, c\) 分别投影到\(q_1, q_2, q_3\)上,再重新组装 正交分量的过程

\(A=QR\) 两边乘以\(Q^T\) ,可以得到\(R=Q^TA\)

这里的\(Q\) 需要先通过上面的 "Gram-Schmidt正交化方法" 获得。
接着我们才能通过 \(R=Q^TA\) 获得 \(R\) 。

为什么需要得到\(R\)呢,因为首先\(R\) 是上三角形矩阵,每个列向量都线性无关,\(R\)是有逆矩阵的。

并且,我们可以通过\(A^TA = (QR)^TQR = R^TQ^TQR = R^TR\) ,将\(A^TA\) 转化为 \(R^TR\)

\(A^TA\hat{x}=A^Tb\) 可以简化为 \(R^TR\hat{x}=R^TQ^Tb\) , 最后我们得到\(R\hat{x}=Q^Tb\) , 或者说是\(\hat{x}=R^{-1}Q^Tb\)

这样我们就将无法解决的\(Ax=b\)转化为\(R\hat{x}=Q^Tb\) ,回代法可以快速解决。

证明 Hadamard matrix \(H_n^TH_n=nI_n\)

\(H_n^TH_n=nI_n\) ,主对角线之外的项全为0,意味着 \(H_n\)矩阵的列互相垂直。
如何证明,可以用数学归纳法证明。

首先,我们假设\(H_n^TH_n=nI_n\)

存在 \(H_{2n}=\begin{bmatrix}H_n&H_n\\H_n&-H_n\end{bmatrix}\), \(H_{2n}^T=\begin{bmatrix}H_n^T&H_n^T\\H_n^T&-H_n^T\end{bmatrix}\)

可以得到

\[H_{2n}^TH_{2n}= \begin{bmatrix} H_n^T & H_n^T\\ H_n^T & -H_n^T \end{bmatrix} \begin{bmatrix} H_n & H_n\\ H_n & -H_n \end{bmatrix} = \begin{bmatrix} 2H_n^TH_n & 0\\ 0 & 2H_n^TH_n \end{bmatrix} = \begin{bmatrix} 2nI_n & 0\\ 0 & 2nI_n \end{bmatrix} = 2nI_{2n} \]

并且存在 \(H_2=\begin{bmatrix}1&1\\1&-1\end{bmatrix}\) 满足 \(H_n^TH_n=nI_n\)

因此\(H_n^TH_n=nI_n\quad n=2^C\) 成立

Problem Set 4.4

\(Q=I-2uu^T\) 在\(u^Tu=1\)的时候是反射矩阵(reflection matrix). 两次反射可以得到 \(Q^2=I\) .
a) Show that \(Qu=-u\). The mirror is perpendicular to \(u\).

posted @ 2026-10-28 14:25  dewxin  阅读(5)  评论(0)    收藏  举报