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, row_space_matrix, left_kernel_matrix
```
## Main idea
Let $A$ be an $m\times n$ matrix.
Then
$$\begin{aligned}
f_A: \mathbb{R}^n &\rightarrow \mathbb{R}^m \\
{\bf u} &\mapsto A{\bf u}
\end{aligned}
$$
defines a linear function.
With this connection,
- $\operatorname{range}(f_A) = \operatorname{Col}(A)$,
- $\operatorname{ker}(f_A) = \operatorname{ker}(A)$,
- $\operatorname{rank}(f_A) = \operatorname{rank}(A)$,
- $\operatorname{null}(f_A) = \operatorname{null}(A)$.
By the dimension theorem, the following are equivalent:
1. $f_A$ is injective.
2. $\operatorname{null}(A) = 0$.
3. $\operatorname{rank}(A) = n$.
On the other hand, $f_A$ is surjective if and only if $\operatorname{rank}(A) = m$.
Therefore, the inverse of $f_A$ exists only when $\operatorname{rank}(A) = m = n$.
When the inverse function exists, $f_A^{-1} = f_{A^{-1}}$.
Let $I_n$ be the identity matrix.
Then $f_{I_n} = \operatorname{id}_{\mathbb{R}^n}$.
Let $\mathcal{E}_n = \{ {\bf e}_1, \ldots, {\bf e}_n \}$ be the standard basis of $\mathbb{R}^n$.
Let
$$D = \begin{bmatrix}
d_1 & ~ & ~ \\
~ & \ddots & ~ \\
~ & ~ & d_n \\
\end{bmatrix}
$$
be an $n\times n$ diagonal matrix.
Then $f_D$ is a scaling function that satisfying
$$\begin{array}{ccc}
{\bf e}_1 &\mapsto
& d_1{\bf e}_1, \\
&\vdots & \\
{\bf e}_n &\mapsto & d_n{\bf e}_n. \\
\end{array}
$$
In particular, if $A$ is a diagonal matrix whose diagonal entries are $1$ or $0$, then $f_A$ is a projection.
If $A$ is a diagonal matrix whose diagonal entries are $1$ or $-1$, then $f_A$ is a reflection.
Let
$$R_\theta = \begin{bmatrix}
\cos\theta & -\sin\theta \\
\sin\theta & \cos\theta
\end{bmatrix}.
$$
Let $R(i,j,\theta)$ be the $n\times n$ matrix obtained $I_n$ by replacing the $2\times 2$ principal submatrix on the $i$-th and $j$-th rows/columns with $R_\theta$.
Then $R(i,j,\theta)$ is called the **Givens rotation**.
The function $f_{R(i,j,\theta)}$ is a rotation on the $i,j$-coordinates.
A **permutation** is a bijection between $\{1, \ldots, n\}$ to itself.
Let $\sigma$ be a permutation on $\{1,\ldots,n\}$.
Define the matrix $P$ such that the $\sigma(i),i$-entry is $1$ for $i = 1,\ldots, n$ while other entries are zero.
Then $f_P$ is a function sending ${\bf e}_i$ to ${\bf e}_{\sigma(i)}$.
## Side stories
- build $A$ from $A{\bf e}_i$
## Experiments
##### Exercise 1
執行以下程式碼。
已知 $\left[\begin{array}{c|c} R & {\bf r} \end{array}\right]$ 為 $\left[\begin{array}{c|c} A & {\bf b} \end{array}\right]$ 的最簡階梯形式矩陣。
令 $f_A$ 為對應到矩陣 $A$ 的線性函數。
```python
### code
set_random_seed(0)
print_ans = False
ran = choice([True, False])
ker = choice([True, False])
m,n,r = 3,4,2
A = random_good_matrix(m,n,r)
v = vector(random_int_list(n))
b = A * v + ( zero_vector(m) if ran else left_kernel_matrix(A).row(0) )
u = kernel_matrix(A).column(0) + ( zero_vector(n) if ker else row_space_matrix(A).row(0) )
Ab = A.augment(b, subdivide=True)
Rr = Ab.rref()
print("[ A | b ] =")
show(Ab)
print("[ R | r ] =")
show(Rr)
print("u =", u)
if print_ans:
print("b in range(f_A)?", ran)
print("u in kernel(f_A)?", ker)
```
:::warning
- [x] 複製題目裡的數字過來,並好好排版
:::
$$\begin{aligned}\left[\begin{array}{c|c} A & \bb \end{array}\right] = \left[\begin{array}{cccc|c} 1 & 4 & -12 & 15 & -45 \\ -4 & -15 & 45 & -57 & 170 \\ -11 & -42 & 126 & -159 & 475 \end{array}\right],
\end{aligned}$$
$$\begin{aligned}\left[\begin{array}{c|c} R & \br \end{array}\right] = \left[\begin{array}{cccc|c} 1 & 0 & 0 & 3 & -5 \\ 0 & 1 & -3 & 3 & -10 \\ 0 & 0 & 0 & 0 & 0 \end{array}\right],
\end{aligned}$$
$${\bf u} = (0,3,1,0)$$
##### Exercise 1(a)
判斷 ${\bf b}$ 是否落在 $\operatorname{range}(f_A)$ 中。
$Ans:$
因為 $A\bx = \bb$ 有解,因此 $\bb$ 在落在 $\operatorname{range}(f_A)$ 中。
##### Exercise 1(b)
判斷 ${\bf u}$ 是否落在 $\operatorname{ker}(f_A)$ 中。
$Ans:$
因為 $R\bu = 0$,因此 $\bu$ 落在 $\operatorname{ker}(f_A)$ 中。
## Exercises
##### Exercise 2
對以下各矩陣 $A$:
1. 說明 $f_A$ 的作用。
2. 寫出 $\operatorname{range}(f)$ 及 $\operatorname{rank}(f)$。
3. 寫出 $\operatorname{ker}(f)$ 及 $\operatorname{null}(f)$。
4. 判斷 $f_A$ 是否可逆;若可逆﹐其反函數為何?
##### Exercise 2(a)
$$A = \begin{bmatrix}
1 & 0 & 0 \\
0 & 2 & 0 \\
0 & 0 & 3 \\
\end{bmatrix}.
$$
:::warning
- [x] 中英數間空格
- [x] $f_A$為一對角矩陣,可 --> 函數 $f_A$ 的作用為
- [x] $$\operatorname{range}(f) = ( \begin{bmatrix}
1 \\
0 \\
0 \\
\end{bmatrix}
, \begin{bmatrix}
0 \\
2 \\
0 \\
\end{bmatrix} , \begin{bmatrix}
0 \\
0 \\
3 \\
\end{bmatrix}),
$$ -->
$$\operatorname{range}(f) = \vspan\left\{ \begin{bmatrix}
1 \\
0 \\
0 \\
\end{bmatrix}
, \begin{bmatrix}
0 \\
2 \\
0 \\
\end{bmatrix} , \begin{bmatrix}
0 \\
0 \\
3 \\
\end{bmatrix}
\right\},
$$
- [x] $\operatorname{ker}(f) = 0$ --> $\ker(f) = \{\bzero\}$
- [x] 反函數是一個函數,不會是一個矩陣
- [x] 後面幾題有類似的問題。
:::
$Ans:$
函數 $f_A$ 的作用為將 ${\bf e}_1$ 乘以 $1$ 倍,${\bf e}_2$ 乘以 $2$ 倍,${\bf e}_3$ 乘以 $3$ 倍,
$$\operatorname{range}(f) = \vspan\left\{ \begin{bmatrix}
1 \\
0 \\
0 \\
\end{bmatrix}
, \begin{bmatrix}
0 \\
2 \\
0 \\
\end{bmatrix} , \begin{bmatrix}
0 \\
0 \\
3 \\
\end{bmatrix}
\right\},
$$
$\operatorname{rank}(f) = 3$。
$\ker(f) = \{\bzero\}$,$\operatorname{null}(f) = 0$。
函數 $f_A$ 為可逆函數,且其反函數為的作用為 ${\bf e}_1$ 乘以 $1$ 倍,${\bf e}_2$ 乘以 $\frac{1}{2}$ 倍,${\bf e}_3$ 乘以 $\frac{1}{3}$ 倍。
換句話說,$f$ 的反函數為 $f_B$,其中
$$B = \begin{bmatrix}
1 & 0 & 0 \\
0 & \frac{1}{2}\ & 0 \\
0 & 0 & \frac{1}{3} \\
\end{bmatrix}.
$$
##### Exercise 2(b)
$$A = \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 0 \\
\end{bmatrix}.
$$
:::warning
- [x] 這題的作用可以寫成投影
:::
$Ans:$
函數 $f_A$ 可將 ${\bf e}_1$ 乘以 $1$ 倍,${\bf e}_2$ 乘以 $1$ 倍,${\bf e}_3$ 變為 $0$,也就是對 $xy$-平面投影。
$$\operatorname{range}(f) = \vspan\left\{ \begin{bmatrix}
1 \\
0 \\
0 \\
\end{bmatrix}
, \begin{bmatrix}
0 \\
1 \\
0 \\
\end{bmatrix}
\right\},
$$
$\operatorname{rank}(f) = 2$。
$$\ker(f) = \vspan\left\{ \begin{bmatrix}
0 \\
0 \\
1 \\
\end{bmatrix}
\right\},
$$
$\operatorname{null}(f) = 1$。
函數 $f_A$ 為不可逆函數
##### Exercise 2(c)
$$A = \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & -1 \\
\end{bmatrix}.
$$
:::warning
- [x] 這題的作用可以寫成鏡射
函數 $f_A$ 的用為對 $xy$-平面鏡射。
:::
$Ans:$
函數 $f_A$ 可將 ${\bf e}_1$ 乘以 $1$ 倍,${\bf e}_2$ 乘以 $1$ 倍,${\bf e}_3$ 乘以 $-1$ 倍,作用為對 $xy$-平面鏡射。
$$\operatorname{range}(f) = \vspan\left\{ \begin{bmatrix}
1 \\
0 \\
0 \\
\end{bmatrix}
, \begin{bmatrix}
0 \\
1 \\
0 \\
\end{bmatrix} , \begin{bmatrix}
0 \\
0 \\
-1 \\
\end{bmatrix}
\right\},
$$
$\operatorname{rank}(f) = 3$。
$\ker(f) = \{\bzero\}$,$\operatorname{null}(f) = 0$。
函數 $f_A$ 為可逆函數,且其反函數可將 ${\bf e}_1$ 乘以 $1$ 倍,${\bf e}_2$ 乘以 $1$ 倍,${\bf e}_3$ 乘以 $-1$ 倍,作用為對 $xy$-平面鏡射。
所以實際上 $f_A$ 的反函數跟 $f_A$ 一樣。
##### Exercise 2(d)
$$A = \begin{bmatrix}
1 & 0 & 0 \\
0 & \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \\
0 & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\
\end{bmatrix}.
$$
:::warning
- [x] 這題的作用可以寫成旋轉
- [x] 反函數可以用作用說明也行
:::
$Ans:$
函數 $f_A$ 的作用為將 $x$ 座標固定,並將向量的 $y,z$ 座標逆時針旋轉 $45$ 度角。
$$\operatorname{range}(f) = \vspan\left\{ \begin{bmatrix}
1 \\
0 \\
0 \\
\end{bmatrix}
, \begin{bmatrix}
0 \\
\frac{1}{\sqrt{2}} \\
\frac{1}{\sqrt{2}} \\
\end{bmatrix} , \begin{bmatrix}
0 \\
-\frac{1}{\sqrt{2}} \\
\frac{1}{\sqrt{2}} \\
\end{bmatrix}
\right\},
$$
$\operatorname{rank}(f) = 3$。
$\ker(f) = \{\bzero\}$,$\operatorname{null}(f) = 0$。
函數 $f_A$ 為可逆函數,且其反函數作用為,將 $x$ 軸的座標固定,並將向量的 $y,z$ 座標順時針旋轉 $45$ 度角。
##### Exercise 2(e)
$$A = \begin{bmatrix}
0 & 1 & 0 \\
0 & 0 & 1 \\
1 & 0 & 0 \\
\end{bmatrix}.
$$
:::warning
- [x] 反函數不是自己
:::
$Ans:$
函數 $f_A$ 可將 ${\bf e}_1$ 置換為 ${\bf e}_3$,${\bf e}_2$ 換為 ${\bf e}_1$,${\bf e}_3$ 換為 ${\bf e}_2$。
$$\operatorname{range}(f) = \vspan\left\{ \begin{bmatrix}
0 \\
0 \\
1 \\
\end{bmatrix}
, \begin{bmatrix}
1 \\
0 \\
0 \\
\end{bmatrix} , \begin{bmatrix}
0 \\
1 \\
0 \\
\end{bmatrix}
\right\},
$$
$\operatorname{rank}(f) = 3$。
$\ker(f) = \{\bzero\}$,$\operatorname{null}(f) = 0$。
函數 $f_A$ 為可逆函數,且其反函數可將 ${\bf e}_1$ 置換為 ${\bf e}_2$,${\bf e}_2$ 置換為 ${\bf e}_3$,${\bf e}_3$ 置換為 ${\bf e}_1$。
##### Exercise 3
令 $A$ 為一 $m\times n$ 矩陣。
##### Exercise 3(a)
說明若 $m < n$ 則 $f_A$ 不可能是嵌射。
$Ans:$
若 $m < n$,
則化減矩陣 $A$ 至階梯形式後可得知 $\rank(A) = \rank(f_A) \leq m < n$,
因為 $\rank(f_A) \neq n \iff \ker(f_A) \neq \{0\}$,
所以 $f_A$ 不可能是嵌射。
##### Exercise 3(b)
說明若 $m > n$ 則 $f_A$ 不可能是映射。
$Ans:$
若 $m > n$,
則化減矩陣 $A$ 至階梯形式後可得知 $\rank(A) = \rank(f_A) \leq n < m$,
因為 $\rank(f_A) \neq m \iff \range(f_A) \neq \mathbb{R}^m$,
所以 $f_A$ 不可能是映射。
##### Exercise 4
令 $A$ 為一可逆矩陣。
驗證 $f_A^{-1} = f_{A^{-1}}$。
:::warning
- [x] 標點
:::
$Ans:$
因為 $A$ 為可逆矩陣,所以可知 $A$ 為一方陣。
令 $A$ 為一 $n\times n$ 方陣。
$$\begin{aligned}
f_A: \mathbb{R}^n &\rightarrow \mathbb{R}^n \\
{\bf u} &\mapsto A{\bf u}
\end{aligned}
$$
$$\begin{aligned}
f_A^{-1}: \mathbb{R}^n &\rightarrow \mathbb{R}^n \\
A{\bf u} &\mapsto {\bf u}
\end{aligned}
$$
$$\begin{aligned}
f_{A^{-1}}: \mathbb{R}^n &\rightarrow \mathbb{R}^n \\
{\bf u} &\mapsto A^{-1}{\bf u}
\end{aligned}
$$
且已知 $A$ 為可逆,所以在
${\bf u} \mapsto A^{-1}{\bf u}$ 兩邊同乘 $A$ ,
$A{\bf u} \mapsto AA^{-1}{\bf u}$ ,
因此 $A{\bf u} \mapsto {\bf u}$ ,
故 $f_A^{-1} = f_{A^{-1}}$ 。
##### Exercise 5
令 $A$ 為一 $m\times n$ 矩陣。
令 $\mathcal{E}_n = \{ {\bf e}_1,\ldots, {\bf e}_n \}$ 為 $\mathbb{R}^n$ 的標準基底。
:::success
這個題組寫得很好 :slightly_smiling_face:
:::
##### Exercise 5(a)
若 $m = 4$、$n = 3$ 且已知
$$\begin{aligned}
f({\bf e}_1) &= (1,1,1,1), \\
f({\bf e}_2) &= (1,2,3,4), \\
f({\bf e}_3) &= (4,3,2,1). \\
\end{aligned}
$$
求 $A$。
$Ans:$
由於 ${\bf e}_n$ 為 $\mathbb{R}^n$ 的標準基底,
因此我們可知 ${\bf e}_1 = (1,0,0)$、 ${\bf e}_2 = (0,1,0)$、 ${\bf e}_3 = (0,0,1)$。
令
$$A = \begin{bmatrix}
a & e & i \\
b & f & j \\
c & g & k \\
d & h & l
\end{bmatrix}. $$
根據題目, $f({\bf e}_1) = A{\bf e}_1 = (1,1,1,1)$ 經過運算可得
$$a = 1,\\
b = 1,\\
c = 1,\\
d = 1。$$
同理, $f({\bf e}_2) = A{\bf e}_2 = (1,2,3,4)$ 和 $f({\bf e}_3) = A{\bf e}_3 = (4,3,2,1)$ 經過運算可得
$$e = 1,\\
f = 2,\\
g = 3,\\
h = 4,\\
i = 4,\\
j = 3,\\
k = 2,\\
l = 1。 $$
最後將數字代回 $A$ 中可得
$$A = \begin{bmatrix}
1 & 1 & 4 \\
1 & 2 & 3 \\
1 & 3 & 2 \\
1 & 4 & 1
\end{bmatrix}。 $$
##### Exercise 5(b)
說明 $A$ 會是把 $f({\bf e}_1), \ldots, f({\bf e}_n)$ 依序當成行向量的矩陣。
$Ans:$
令$$A = \begin{bmatrix}
| & ~ & | \\
{\bf u}_1 & \cdots & {\bf u}_n \\
| & ~ & |
\end{bmatrix},$$
且 ${\bf u}_1,...,{\bf u}_n$ 屬於 $\mathbb{R}^m$。
而 ${\bf e}_1,...,{\bf e}_n$ 為 $\mathbb{R}^n$ 的標準基底,
經過運算後可得
$${\bf u}_1 = A{\bf e}_1 = f({\bf e}_1), \\
{\bf u}_2 = A{\bf e}_2 = f({\bf e}_2), \\
\vdots \\
{\bf u}_n = A{\bf e}_n = f({\bf e}_n)。$$
因此我們可知
$$A = \begin{bmatrix}
| & ~ & | \\
f({\bf e}_1) & \cdots & f({\bf e}_n) \\
| & ~ & |
\end{bmatrix}。
$$
:::success
目前分數 5.5
:::