owned this note
owned this note
Published
Linked with GitHub
# 垂直子空間

This work by Jephian Lin is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).
{%hackmd 5xqeIJ7VRCGBfLtfMi0_IQ %}
```python
from lingeo import random_int_list, random_good_matrix, kernel_matrix
```
## Main idea
Let $U$ and $V$ be two subspaces under the same inner product space.
We say $U$ and $V$ are orthogonal if $\langle {\bf u}, {\bf v} \rangle = 0$ for any ${\bf u}\in U$ and ${\bf v}\in V$.
Similarly, we say a collection of subspaces $\{V_1,\ldots,V_k\}$ is orthogonal if they are pairwisely orthogonal.
If $\{V_1,\ldots,V_k\}$ is orthogonal, then they are necssarily independent.
Therefore, we have the direct sum $V_1 \oplus \cdots \oplus V_k$.
Suppose $V = V_1 \oplus \cdots \oplus V_k$.
Then every vector ${\bf v}\in V$ can be uniquely written as ${\bf v} = {\bf v}_1 + \cdots + {\bf v}_k$ with ${\bf v}_i\in V_i$ for each $i = 1,\ldots,k$.
Let $A$ be an $m\times n$ matrix.
We have seen several cases of mutually orthogonal subspaces related to $A$.
With the new terminology, we may safely say:
1. The subspaces $\operatorname{Row}(A)$ and $\operatorname{ker}(A)$ are orthogonal, and $\mathbb{R}^n = \operatorname{Row}(A) \oplus \operatorname{ker}(A)$.
1. The subspaces $\operatorname{Col}(A)$ and $\operatorname{ker}(A^\top)$ are orthogonal, and $\mathbb{R}^m = \operatorname{Col}(A) \oplus \operatorname{ker}(A^\top)$.
Suppose $V$ is a subspace in $\mathbb{R}^n$.
We also have $\mathbb{R}^n = V \oplus V^\perp$.
## Side stories
- projection matrix
## Experiments
##### Exercise 1
執行以下程式碼。
已知 $R$ 為 $A$ 的最簡階梯形式矩陣。
```python
### code
set_random_seed(0)
print_ans = False
m,n,r = 2,4,2
A = random_good_matrix(m,n,r)
R = A.rref()
H = kernel_matrix(R)
c = random_int_list(2, r=3)
b = c[0]*R[0] + c[1]*H.transpose()[0]
print("A =")
show(A)
print("R =")
show(R)
print("b = ", b)
if print_ans:
r = c[0]*R[0]
h = c[1]*H.transpose()[0]
print("r =", r)
print("h =", h)
print("|b|^2 =", b.norm()**2)
print("|r|^2 + |h|^2 = %s + %s = %s"%(r.norm()**2, h.norm()**2, r.norm()**2 + h.norm()**2))
```
##### Exercise 1(a)
將 ${\bf b}$ 寫成 ${\bf r} + {\bf h}$
其中 ${\bf r}\in\operatorname{Row}(A)$ 而 ${\bf h}\in\operatorname{ker}(A)$。
**[由李昌諺同學提供]**
答:
由 `seed(0)` 時執行程式碼得到
$$A = \begin{bmatrix}
1 & 0 & 3 & 5 \\
3 & 1 & 4 & 10
\end{bmatrix},
R = \begin{bmatrix}
1 & 0 & 3 & 5 \\
0 & 1 & -5 & -5
\end{bmatrix},
{\bf b}=(-5,5,-5,-10).
$$
令 $A$ 的各列向量為 ${\bf r}_1,{\bf r}_2$,
則 $\operatorname{Row}(A)=\operatorname{span}(\{{\bf r}_1,{\bf r}_2\})$。
$R$ 為 $A$ 的最簡階梯式,可知 ${x}_3,{x}_4$ 為自由變數。
令 $x_3=1 , x_4=0$ 時可得到 ${\bf h}_1 = (-3,5,1,0).$
令 $x_3=0 , x_4=1$ 時可得到 ${\bf h}_2 = (-5,5,0,1).$
所以 $\operatorname{ker}(A)=\operatorname{span}(\{{\bf h}_1,{\bf h}_2\})$。
假設 ${\bf r}=c_1{\bf r}_1 + c_2{\bf r}_2$ , ${\bf h}=c_3{\bf h}_1 + c_4{\bf h}_2$ 使得 ${\bf b}={\bf r}+{\bf h}$。
可以把它轉換成矩陣形式
$$\begin{bmatrix}
1 & 3 & -3 & -5 \\
0 & 1 & 5 & 5 \\
3 & 4 & 1 & 0 \\
5 & 10 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
c_1 \\
c_2 \\
c_3 \\
c_4 \\
\end{bmatrix}=
\begin{bmatrix}
-5 \\
5 \\
-5 \\
-10 \\
\end{bmatrix}.
$$
用高斯消去法計算增廣矩陣
$$\left[\begin{array}{cccc|c}
1 & 3 & -3 & -5 & -5\\
0 & 1 & 5 & 5 & 5\\
3 & 4 & 1 & 0 & -5\\
5 & 10 & 0 & 1 & -10\\
\end{array}\right] \rightarrow \cdots \rightarrow
\left[\begin{array}{cccc|c}
1 & 3 & -3 & -5 & -5\\
0 & 1 & 5 & 5 & 5\\
0 & 0 & 35 & 40 & 35\\
0 & 0 & 0 & \frac{37}{7} & 0\\
\end{array}\right]
$$
得到 $c_1 = -2,c_2 = 0,c_3 = 1,c_4 = 0.$
經過計算,得 ${\bf r}=c_1{\bf r}_1 + c_2{\bf r}_2=(-2,0,-6,-10)\in\operatorname{Row}(A)$ 而 ${\bf h}=c_3{\bf h}_1 + c_4{\bf h}_2=(-3,5,1,0)\in\operatorname{ker}(A)$ 使得 ${\bf b}={\bf r}+{\bf h}$。
**[由蔡程亦同學提供]**
答:
```seed=2```時
$$A = \begin{bmatrix}
1 & 2 & -4 & -3 \\
1 & 2 & -4 & -2
\end{bmatrix},
R = \begin{bmatrix}
1 & 2 & -4 & 0 \\
0 & 0 & 0 & 1
\end{bmatrix},
{\bf b}=(3,1,-4,0).
$$
令 $A$ 的各列向量為 ${\bf r}_1,{\bf r}_2$,
則 $\operatorname{Row}(A)=\operatorname{span}(\{{\bf r}_1,{\bf r}_2\})$。
由 $R$ 可知 ${x}_2,{x}_3$ 為自由變數。
令 $x_2=1 , x_3=0$ 可得到 ${\bf h}_1 = (-2,1,0,0).$
令 $x_2=0 , x_3=1$ 可得到 ${\bf h}_2 = (4,0,1,0).$
所以 $\operatorname{ker}(A)=\operatorname{span}(\{{\bf h}_1,{\bf h}_2\})$。
解方程式$x(1,2,-4,-3)+y(1,2,-4,-2)+z(-2,1,0,0)+w(4,0,1,0)=(3,1,-4,0)$ 。
計算得 $x=-2,y=3,z=-1,w=0$。
故 ${\bf r}=(1,2,-4,0),{\bf h}=(2,-1,0,0)$ 使得 ${\bf b}={\bf r}+{\bf h}$。
##### Exercise 1(b)
證驗 ${\bf r}$ 和 ${\bf h}$ 垂直﹐
而且 $\|{\bf b}\|^2 = \|{\bf r}\|^2 + \|{\bf h}\|^2$。
**[由李昌諺同學提供]**
答(`seed(0)`):
答:
計算
$$\begin{aligned}
\langle {\bf r}, {\bf h}\rangle
&=(-2,0,-6,10) \cdot (-3,5,1,0) \\
&= 6+0-6+0 \\
&= 0 \\
\end{aligned}
$$
又
$\|{\bf b}\|^2 = 25+25+25+100 = 175$,
$\|{\bf r}\|^2 = 4+0+36+100 = 140$,
$\|{\bf h}\|^2 = 9+25+1+0 = 35$,
得 $\|{\bf b}\|^2 = \|{\bf r}\|^2 + \|{\bf h}\|^2$。
**[由蔡程亦同學提供]**
(```seed=2```時)
計算 $$\begin{aligned}
\langle {\bf r}, {\bf h}\rangle
&=(1,2,-4,0) \cdot (2,-1,0,0) \\
&= 0. \\
\end{aligned}
$$
所以${\bf r}$ 和 ${\bf h}$ 垂直。
又
$\|{\bf b}\|^2 = 26$,$\|{\bf r}\|^2 = 21$,$\|{\bf h}\|^2 = 5$,
得 $\|{\bf b}\|^2 = \|{\bf r}\|^2 + \|{\bf h}\|^2$。
##### Exercise 1(c)
因為每一個 中的向量都可以分解成 ${\bf r}\in\operatorname{Row}(A)$ 和 ${\bf h}\in\operatorname{ker}(A)$ 中的向量相加。
說明對任何 $m\times n$ 矩陣都有
$$\{A{\bf x}: {\bf x}\in\mathbb{R}^n \} = \{ A{\bf r} : {\bf r}\in\operatorname{Row}(A)\}.
$$
## Exercises
##### Exercise 2
令 $S = \{V_1,\ldots,V_k\}$ 為一群子空間。
證明若 $S$ 是垂直的集合﹐則 $S$ 線性獨立。
##### Exercise 3
若 $S = \{V_1, V_2, V_3\}$ 垂直。
令 $V = V_1 \oplus V_2 \oplus V_3$、
$P$ 為 $V$ 的投影矩陣、
$P_1,P_2,P_3$ 分別為 $V_1,V_2,V_3$ 的投影矩陣。
##### Exercise 3(a)
說明 $P_1P_2 = P_2P_1$。
##### Exercise 3(b)
說明 $P = P_1 + P_2 + P_3$。
##### Exercise 3(c)
若 $V = \mathbb{R}^n$ 為全空間。
說明 $I_n = P_1 + P_2 + P_3$。
##### Exercise 4
依照步驟證明以下敘述等價:
1. $P$ 是某個空間的投影矩陣。
2. $P$ 對稱、而且 $P = P^2$。
##### Exercise 4(a)
證明若 $P$ 是一個投影矩陣﹐
則 $P$ 是 $\operatorname{Col}(P)$ 的投影矩陣。
因此如果 ${\bf u}\in\operatorname{Col}(P)$ 則 $P{\bf u} = {\bf u}$、
如果 ${\bf u}\in\operatorname{ker}(P^\top)$ 則 $P{\bf u} = {\bf 0}$、
同時每個向量都可以分成 ${\bf u} = P{\bf u} + (I - P){\bf u}$
使得 $P{\bf u}\in\operatorname{Col}(P)$ 且 $(I - P){\bf u}\in\operatorname{ker}(P^\top)$。
藉由這些性質說明如果條件一成立則條件二成立。
##### Exercise 4(b)
若 $P$ 對稱且 $P = P^2$。
說明 $\mathbb{R}^n = \operatorname{Col}(P) \oplus \operatorname{ker}(P)$ 且
如果 ${\bf u}\in\operatorname{Col}(P)$ 則 $P{\bf u} = {\bf u}$、
如果 ${\bf u}\in\operatorname{ker}(P)$ 則 $P{\bf u} = {\bf 0}$。
藉由這些性質說明如果條件二成立則條件一成立。
##### Exercise 5
證明若 $V = V_1 \oplus \cdots \oplus V_k$﹐
則每一個向量 ${\bf v}\in V$ 都可以被寫成 ${\bf v} = {\bf v}_1 + \cdots + {\bf v}_k$﹐
使得對每一個 $i = 1,\ldots,k$ 都有 ${\bf v}_i\in V_i$﹐
而且這種寫法唯一。
##### Exercise 6
利用垂直空間分解母空間的現象在其它向量空間也很常見。
##### Exercise 6(a)
令 $U = \mathcal{M}_{n\times n}$ 為一向量空間﹐搭配內積 $\langle A,B\rangle = \operatorname{tr}(B^\top A)$。
令 $V$ 為 $U$ 中所有對稱矩陣的集合、
令 $W$ 為 $U$ 中所有反對稱矩陣的集合。
說明 $V$ 和 $W$ 垂直且 $U = V \oplus W$。
##### Exercise 6(a)
令 $U = \mathcal{P}_{d}$ 為一向量空間﹐搭配內積
$$\langle a_0 + a_1x + \cdots + a_dx^d, b_0 + b_1x + \cdots + b_dx^d \rangle = a_0b_0 + a_1b_1 + \cdots + a_db_d.$$
令 $V$ 為 $U$ 中所有偶函數的集合、
令 $W$ 為 $U$ 中所有奇函數的集合。
說明 $V$ 和 $W$ 垂直且 $U = V \oplus W$。