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_good_matrix, kernel_matrix
```
## Main idea
Let $U$ and $V$ be two vector spaces.
A function $f: U\rightarrow V$ is **linear** if
$$\begin{aligned}
f({\bf u}_1 + {\bf u}_2) &= f({\bf u}_1) + f({\bf u}_2) \\
f(k{\bf u}) &= kf({\bf u}) \\
\end{aligned}
$$
for any vectors ${\bf u}, {\bf u}_1, {\bf u}_2\in U$ and scalar $k\in\mathbb{R}$.
Let $f : U \rightarrow V$ be a linear function.
The **kernel** of $f$ is $\operatorname{ker}(f) = \{{\bf u}\in U: f({\bf u}) = {\bf 0}\}$.
Recall that $\operatorname{range}(f) = \{ f({\bf u}) : {\bf u}\in U \}$.
Indeed, $\operatorname{ker}(f)$ is a subspace of $U$ and $\operatorname{range}(f)$ is a subspace of $V$.
Thus, we define the **rank** of $f$ as $\operatorname{rank}(f) = \dim(\operatorname{range}(f))$ and
the **nullity** of $f$ as $\operatorname{null}(f) = \dim(\operatorname{ker}(f))$.
From the definition, $f$ is surjective if and only if $\operatorname{range}(f) = V$, or, equivalently, $\operatorname{rank}(f) = \dim(V)$.
On the other hand, it is also known that $f$ is injective if and only if $\operatorname{ker}(f) = \{{\bf 0}\}$, or, equivalently, $\operatorname{null}(f) = 0$.
Thanks to the structure of a linear function, the function values of a basis of $U$ is enough to determine the function.
Let $\beta = \{{\bf u}_1, \ldots, {\bf u}_n\}$ be a basis of $U$ and $f : U\rightarrow V$ a linear function.
If $f({\bf u}_1) = {\bf v}_1$, $\ldots$, $f({\bf u}_n) = {\bf v}_n$, then
$$f(c_1{\bf u}_1 + \cdots + c_n{\bf u}_n) = c_1{\bf v}_1 + \cdots + c_n{\bf v}_n
$$
is uniquely determined, since every vector ${\bf u}$ can be written as a linear combinatoin $c_1{\bf u}_1 + \cdots + c_m{\bf u}_m$ of $\beta$ for some $c_1,\ldots, c_n\in\mathbb{R}$.
## Side stories
- basis of the range
## Experiments
##### Exercise 1
執行以下程式碼。
假設已知 $f$ 為一從 $\mathbb{R}^3$ 到 $\mathbb{R}^4$ 的線性函數。
令 $\beta = \{{\bf e}_1, {\bf e}_2, {\bf e}_3\}$ 為 $I_3$ 的行向量集合﹐其為 $\mathbb{R}^3$ 的基底。
```python
### code
set_random_seed(0)
print_ans = False
m,n,r = 4,3,2
A = random_good_matrix(m,n,r)
for i in range(n):
print("f(e%s) ="%(i+1), A.column(i))
if print_ans:
print("f(3e1 + 2e2) = 3f(e1) + 2f(e2) =", 3*A.column(0) + 2*A.column(1))
print("To make f(u) = 0 for some nonzero u, one may choose u =", kernel_matrix(A).column(0))
print("A =")
show(A)
```
##### Exercise 1(a)
求 $f(3{\bf e}_1 + 2{\bf e}_2)$。
$Ans:$
因為 $f$ 為線性函數,
所以 $f(3{\bf e}_1 + 2{\bf e}_2)=f(3{\bf e}_1)+f(2{\bf e}_2)=3f({\bf e}_1)+2f ({\bf e}_2)$。
而 $f({\bf e}_1)=(1,-5,15,-12)、f({\bf e}_2)=(-5,26,-78,63)$,
則 $f(3{\bf e}_1 + 2{\bf e}_2)=3f({\bf e}_1)+2f ({\bf e}_2)=(-7,37,-111,90)$。
##### Exercise 1(b)
:::warning
- [x] 所以矩陣 後面的 $A{\bf x}=f({\bf x})$ 拿掉,還有 $f(\beta)$ 拿掉($f$ 代入一個集合出來是一個集合,不會是矩陣。)
- [x] 最後面常數和等號不用粗體
:::
求 $\mathbb{R}^3$ 中的一個非零向量 ${\bf u}$ 使得 $f({\bf u}) = {\bf 0}$。
$Ans:$
令 $f({\bf x}) = A{\bf x}$,
根據題目 $f({\bf u}) = {\bf 0}$ ,所以 $A{\bf u} = {\bf 0}$ ,也就是 $\ker({A}) = {\bf 0}$
因為條件 $\beta = \{{\bf e}_1, {\bf e}_2, {\bf e}_3\}$ 為 $I_3$ 的行向量集合,
且 $f({\bf e}_1)=(1,-5,15,-12)、f({\bf e}_2)=(-5,26,-78,63)、f({\bf e}_3)=(-22,115,-345,279)$,
所以矩陣
$$AI_3 =\begin{bmatrix}
1 & -5 & -22\\
-5 & 26 & 115\\
15 & -78 & -345\\
-12 & 63 & 279
\end{bmatrix} = A。
$$
找到矩陣 $A$ 的最簡階梯形式 $R = \begin{bmatrix}
1 & 0 & 3\\
0 & 1 & 5\\
0 & 0 & 0\\
0 & 0 & 0
\end{bmatrix}$。
將自由變數設為 $1$ 可以找到 $A{\bf u} = 0$ 的其中一個解 ${\bf u} = (-3,-5,1)$。
##### Exercise 1(c)
找一個矩陣 $A$ 使得對所有向量 ${\bf u}\in\mathbb{R}^3$ 都有 $f({\bf u}) = A{\bf u}$。
:::warning
- [x] 同上題
:::
$Ans:$
因為條件 $\beta = \{{\bf e}_1, {\bf e}_2, {\bf e}_3\}$ 為 $I_3$ 的行向量集合,
且 $f({\bf e}_1)=(1,-5,15,-12)、f({\bf e}_2)=(-5,26,-78,63)、f({\bf e}_3)=(-22,115,-345,279)$。
所以矩陣
$AI_3=\begin{bmatrix}
1 & -5 & -22\\
-5 & 26 & 115\\
15 & -78 & -345\\
-12 & 63 & 279
\end{bmatrix} = A$。
## Exercises
##### Exercise 2
判斷以下函數是否線性。
:::warning
- [x] 向量粗體,不要在上面加箭頭
- [x] 實數是 $\mathbb{R}$
- [x] 注意空格
:::
如函數為線性,有以下特性:
For any ${\bf u}_1, {\bf u}_2 \in U$ , $f({\bf u}_1+{\bf u}_2)=f({\bf u}_1)+f({\bf u}_2)$ and for any $k \in \mathbb{R}$ , $f(k{\bf u})=kf({\bf u})$.
##### Exercise 2(a)
判斷 $f: \mathbb{R}\rightarrow\mathbb{R}$ 且 $f(x) = 3x + 5$ 是否線性。
:::warning
- [x] 句子邏輯 因為 ... 所以 ... 請敘述完整
:::
$Ans:$
因為 $f(kx) = 3kx + 5$,而 $kf(x) = 3kx + 5k$,所以 $f(kx) \neq kf(x)$。
故 $f$ 不為線性。
##### Exercise 2(b)
判斷 $f: \mathbb{R}\rightarrow\mathbb{R}$ 且 $f(x) = 3x$ 是否線性。
$Ans:$
因為 $f(kx) = 3kx = kf(x)$ 而且 $f(x_1+x_2) = 3x_1 + 3x_2 = f(x_1) + f(x_2)$,滿足定義,
故 $f$ 為線性。
##### Exercise 2(c)
判斷 $f: \mathbb{R}\rightarrow\mathbb{R}$ 且 $f(x) = x^2$ 是否線性。
:::warning
- [x] 後面加上 $\neq f(x_1) + f(x_2)$
:::
$Ans:$
因為 $f(x_1 + x_2) = (x_1 + x_2)^2 = x_1^2 + x_2^2 + 2x_1x_2 = f(x_1)+f(x_2)+2x_1x_2$,
得到 $f(x_1+x_2)\neq f(x_1) + f(x_2)$,
故 $f$ 不為線性。
##### Exercise 2(d)
判斷 $f: \mathbb{R}^2\rightarrow\mathbb{R}$ 且 $f(x,y) = x^2 + y^2$ 是否線性。
:::warning
- [x] 句子邏輯 因為 ... 所以 ... 請敘述完整
:::
$Ans:$
因為 $f(kx,ky) = k^2x^2 + k^2y^2$ , 而 $kf(x,y) = kx^2 + ky^2$, 得到 $kf(x,y) \neq f(kx,ky)$,
故 $f$ 不為線性。
##### Exercise 2(e)
判斷 $f: \mathbb{R}^2\rightarrow\mathbb{R}$ 且 $f(x,y) = 3x + 2y$ 是否線性。
:::warning
- [x] 式子太長用 `aligned` 整理好
:::
$Ans:$
因為 $kf(x,y) = 3kx + 2ky = f(kx,ky)$ 且
$$\begin{align}
f(x_1 + x_2,y_1 + y_2) & = 3(x_1 + x_2) + 2(y_1 + y_2) \\
& = 3x_1 + 3x_2 + 2y_1 + 2y_2 \\
& = f(x_1,y_1) + f(x_2,y_2),
\end{align}
$$
滿足定義。
故 $f$ 為線性。
##### Exercise 2(f)
判斷 $f: \mathbb{R}^2\rightarrow\mathbb{R}$ 且 $f(x,y) = 3x + 2y + 1$ 是否線性。
$Ans:$
因為 $kf(x,y) = 3kx + 2ky + k \neq f(kx,ky)$,
故 $f$ 不為線性。
##### Exercise 3
令 ${\bf u}_1, {\bf u}_2, {\bf u}_3$ 為 $U$ 中的向量﹐
已知 $f$ 為從 $U$ 到 $\mathbb{R}^4$ 的線性函數且
$$\begin{aligned}
f({\bf u}_1) &= (1,1,1,1) \\
f({\bf u}_2) &= (1,2,3,4) \\
f({\bf u}_3) &= (4,3,2,1) \\
\end{aligned}
$$
求 $f(3{\bf u}_1 + 2{\bf u}_2 + 2{\bf u}_3)$。
:::warning
- [x] 用 `aligned` 整理
:::
$Ans:$
因為 $f$ 為線性函數,
所以
$$\begin{aligned}
f(3{\bf u}_1 + 2{\bf u}_2 + 2{\bf u}_3) &= f(3{\bf u}_1)+f(2{\bf u}_2)+f(2{\bf u}_3) \\
&= 3f({\bf u}_1)+2f({\bf u}_2)+2f({\bf u}_3) \\
&=(13,13,13,13).
\end{aligned}
$$
##### Exercise 4
令 $f: U\rightarrow V$ 為一線性函數。
證明以下敘述等價:
1. $f$ is injective.
2. $\operatorname{ker}(f) = \{ {\bf 0} \}$.
3. $\operatorname{null}(f) = 0$.
:::warning
- [x] $1. \rightarrow 2.$ --> $1. \implies 2.$
- [x] 用句末兩個空格換行,空一行是拿來換段的
- [x] 向量用粗體,不要用箭頭那個
- [x] 把 $\times$ 改成 $\cdot$
- [x] 敘述中不要用 $\implies$,用中文講敘述
:::
$Ans:$
證明 $1.$ 和 $2.$ 等價:
$1. \implies 2.$
若存在 ${\bf v} \in \ker(f)$ 且 ${\bf v} \neq {\bf 0}$,
則 $f({\bf v}) = {\bf 0}$。
同時 $f({\bf 0}) = f(0 \cdot {\bf 0}) = 0 \cdot f({\bf 0}) = {\bf 0}$,
所以 ${\bf v} \neq {\bf 0}$ 且 $f({\bf v}) = f({\bf 0})$,
得到 $f$ 不為嵌射的線性函數。
$2. \implies 1.$
若 ${\bf u_1} \neq {\bf u_2} \in U$,
則 ${\bf u_1} -{\bf u_2} \neq {\bf 0}$。
因為 $\ker(f) = {\bf 0}$,
所以 $f({\bf u_1} - {\bf u_2}) \neq {\bf 0}$。
因此可以知道 $f({\bf u_1}) \neq f({\bf u_2})$,
得到 $f$ 為嵌射的線性函數。
故 $1.$ 和 $2.$ 等價。
而根據線性函數定義 $\operatorname{null}(f) = \operatorname{dim}(\ker(f))$,
所以當 $\ker(f) = {0}$ 時 $\operatorname{null}(f) = 0$,
得到 $2.$ 和 $3.$ 等價。
因為 $1.$ 和 $2.$ 等價且 $2.$ 和 $3.$ 也等價,
故 $1.$, $2.$, $3.$ 互為等價。
##### Exercise 5
嵌射顧名思義有點像是把定義域嵌入到對應域之中﹐所以很多性質都會被保留下來。
##### Exercise 5(a)
令 $f: U\rightarrow V$ 為一線性函數。
證明若 $f$ 是嵌射且
$\alpha = \{{\bf u}_1,\ldots,{\bf u}_k\}$ 為 $U$ 中的一線性獨立集﹐
則 $f(\alpha)$ 是 $V$ 中的一線性獨立集。
:::warning
- [x] 標點
- [x] 向量用粗體,不要箭頭
- [x] 則 ... --> 因為 $f$ 線性,所以 ...
- [x] 所以 $c_1 = \cdots =$...
:::
令 $c_1f({\bf u}_1) + \cdots +c_kf({\bf u}_k) = \bf0$。
因為 $f$ 線性,所以 $f(c_1{\bf u}_1 + \cdots + c_k\bu_k) = \bf0$。
因為 $f$ 為嵌射,由上一題我們知道 $\ker(f) = \{ \bzero \}$,
所以 $c_1\bu_1 + \cdots + c_k{\bf u}_k = \bf0$。
因為 $\alpha$ 獨立,所以 $c_1 = \cdots = c_k = 0$。
因此 $f(\alpha)$ 是 $V$ 中的一線性獨立集。
##### Exercise 5(b)
令 $f: U\rightarrow V$ 為一線性函數。
證明若 $f$ 是嵌射且
$\alpha = \{{\bf u}_1,\ldots,{\bf u}_k\}$ 為 $U$ 的一組基底﹐
則 $f(\alpha)$ 是 $\operatorname{range}(f)$ 的一組基底。
:::warning
- [x] $span$ --> $\vspan$
- [x] 標點
- [x] 向量用粗體
- [x] 用敘述取代 $\implies$
:::
1. $f(\alpha)$ 是獨立
2. 檢查 $\vspan(f(\alpha)) = \operatorname{range}(f)$
**Claim:** $\vspan(f(\alpha))\subseteq \operatorname{range}(f)$
因為 $f(\alpha)\subseteq \operatorname{range}(f)$,
所以 $\vspan(f(\alpha))\subseteq \operatorname{range}(f)$。
**Claim:** $\operatorname{range}(f) \subseteq \vspan(f(\alpha))$
令 $\bv \in \operatorname{range}(f)$,則存在 $\bu\in U$ 使得 $f({\bf u}) = \bv$。
因為 $\alpha$ 為基底,所以 $\bu$ 可寫成 $c_1{\bf u}_1 + \cdots + c_k{\bf u}_k = \bu$,
則 $\bv = f({\bf u}) = f(c_1{\bf u}_1 + \cdots + c_k{\bf u}_k)$,
故 $\bv = c_1f({\bf u}_1) + \cdots +c_kf({\bf u}_k)$。
因此 $\bv \in \vspan(f(\alpha))$,
得到 $\operatorname{range}(f) \subseteq \vspan(f(\alpha))$。
##### Exercise 6
依照步驟確認線性擴充出來的函數符合我們要的性質。
令 $U$ 和 $V$ 為兩向量空間
且 $\beta = \{ {\bf u}_1, \ldots, {\bf u}_n \}$ 為 $U$ 的一組基底。
若 $f : U \rightarrow V$ 是一個線性函數
且已知 $f({\bf u}_1) = {\bf v}_1$, $\ldots$, $f({\bf u}_n) = {\bf v}_n$。
##### Exercise 6(a)
說明對任何 $\beta$ 的線性組合﹐$f(c_1{\bf u}_1 + \cdots + c_n{\bf u}_n)$ 必須是 $c_1{\bf v}_1 + \cdots + c_n{\bf v}_n$。
$Ans:$
由 $f : U \rightarrow V$ 是一個線性函數得到
$f(c_1{\bf u}_1 + \cdots + c_n{\bf u}_n) = f(c_1{\bf u}_1) + \cdots + f(c_n{\bf u}_n) = c_1f({\bf u}_1) + \cdots + c_nf({\bf u}_n)$,
又已知 $f({\bf u}_1) = {\bf v}_1$, $\ldots$, $f({\bf u}_n) = {\bf v}_n$,
則 $c_1f({\bf u}_1) + \cdots + c_nf({\bf u}_n) = c_1{\bf v}_1 + \cdots + c_n{\bf v}_n$,
所以 $f(c_1{\bf u}_1 + \cdots + c_n{\bf u}_n)$ 必須是 $c_1{\bf v}_1 + \cdots + c_n{\bf v}_n$。
##### Exercise 6(b)
說明
$$f(c_1{\bf u}_1 + \cdots + c_n{\bf u}_n) = c_1{\bf v}_1 + \cdots + c_n{\bf v}_n
$$
這個公式是定義完善的函數。
(每個 $U$ 中的元素都有被定義到、
且線性組合的不同表示法不會造成任何問題。)
:::warning
- [x] 中英數之間空格
- [x] $\beta = \{ {\bf u}_1, \ldots, {\bf u}_n \}$ 這句應該不用
- [x] 由於$\beta$為$U$之基底且$\beta$中任何元素都有被定義到,故$U$中的所有元素都可被$\beta$做出。--> 由於 $\beta$ 為 $U$ 之基底,所以任何 $U$ 中的元素都可以寫成 $\beta$ 的線性組合,而且係數唯一,一次 $U$ 中的所有元素都可被題目中 $f$ 的公式完善定義出來。
- [x] 最後一句不用
:::
$Ans:$
由於 $\beta$ 為 $U$ 之基底,所以任何 $U$ 中的元素都可以寫成 $\beta$ 的線性組合,而且係數唯一,一次 $U$ 中的所有元素都可被題目中 $f$ 的公式完善定義出來。
##### Exercise 6(c)
說明
$$f(c_1{\bf u}_1 + \cdots + c_n{\bf u}_n) = c_1{\bf v}_1 + \cdots + c_n{\bf v}_n
$$
這個公式是定義出來的函數是線性的。
:::warning
- [x] 適當地把換段改成換行
- [x] 中英數之間空格
- [x] 用 `aligned` 整理數學式
- [x] 第一點要用 $f((c_1\bu_1 + \cdots + c_n\bu_n) + (d_1\bu_1 + \cdots + d_n\bu_n))$ 開頭
- [x] 第二點是要證明 $f(k(c_1\bu_1 + \cdots + c_n\bu_n)) = \cdots = kf(c_1\bu_1 + \cdots + c_n\bu_n)$
:::
$Ans:$
若要說明函數是線性的,則必須滿足以下兩點。
設以下方程式:
對於任何的 $c_1 \cdots c_n$ 及 $d_1 \cdots d_n$ 屬於實數,
已知 $f({\bf u}_1) = {\bf v}_1$, $\ldots$, $f({\bf u}_n) = {\bf v}_n$,
則第一點:
$$\begin{aligned}
f((c_1\bu_1 + \cdots + c_n\bu_n) + (d_1\bu_1 + \cdots + d_n\bu_n)) &=f((c_1+d_1){\bf u}_1 + \cdots + (c_n+d_n){\bf u}_n) \\
&= (c_1+d_1){\bf v}_1 + \cdots + (c_n+d_n){\bf v}_n \\
&=(c_1{\bf v}_1+d_1{\bf v}_1) + \cdots + (c_n{\bf v}_n+d_n{\bf v}_n) \\
&=f(c_1{\bf u}_1 + \cdots + c_n{\bf u}_n)+f(d_1{\bf u}_1 + \cdots + d_n{\bf u}_n).
\end{aligned}
$$
第二點:
對於任何實數 $k$ 都可驗證
$$\begin{aligned}
f(k(c_1\bu_1 + \cdots + c_n\bu_n)) &= kc_1\bv_1+\cdots+kc_n\bv_n \\
&= kf(c_1\bu_1 + \cdots + c_n\bu_n).
\end{aligned}
$$
故此公式$$f(c_1{\bf u}_1 + \cdots + c_n{\bf u}_n) = c_1{\bf v}_1 + \cdots + c_n{\bf v}_n$$
定義的函數為線性。
:::info
目前分數 5.5
:::