# 線性函數
Linear function

This work by Jephian Lin is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).
$\newcommand{\trans}{^\top}
\newcommand{\adj}{^{\rm adj}}
\newcommand{\cof}{^{\rm cof}}
\newcommand{\inp}[2]{\left\langle#1,#2\right\rangle}
\newcommand{\dunion}{\mathbin{\dot\cup}}
\newcommand{\bzero}{\mathbf{0}}
\newcommand{\bone}{\mathbf{1}}
\newcommand{\ba}{\mathbf{a}}
\newcommand{\bb}{\mathbf{b}}
\newcommand{\bc}{\mathbf{c}}
\newcommand{\bd}{\mathbf{d}}
\newcommand{\be}{\mathbf{e}}
\newcommand{\bh}{\mathbf{h}}
\newcommand{\bp}{\mathbf{p}}
\newcommand{\bq}{\mathbf{q}}
\newcommand{\br}{\mathbf{r}}
\newcommand{\bx}{\mathbf{x}}
\newcommand{\by}{\mathbf{y}}
\newcommand{\bz}{\mathbf{z}}
\newcommand{\bu}{\mathbf{u}}
\newcommand{\bv}{\mathbf{v}}
\newcommand{\bw}{\mathbf{w}}
\newcommand{\tr}{\operatorname{tr}}
\newcommand{\nul}{\operatorname{null}}
\newcommand{\rank}{\operatorname{rank}}
%\newcommand{\ker}{\operatorname{ker}}
\newcommand{\range}{\operatorname{range}}
\newcommand{\Col}{\operatorname{Col}}
\newcommand{\Row}{\operatorname{Row}}
\newcommand{\spec}{\operatorname{spec}}
\newcommand{\vspan}{\operatorname{span}}
\newcommand{\Vol}{\operatorname{Vol}}
\newcommand{\sgn}{\operatorname{sgn}}
\newcommand{\idmap}{\operatorname{id}}
\newcommand{\am}{\operatorname{am}}
\newcommand{\gm}{\operatorname{gm}}
\newcommand{\mult}{\operatorname{mult}}
\newcommand{\iner}{\operatorname{iner}}$
```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(\bu_1 + \bu_2) &= f(\bu_1) + f(\bu_2) \\
f(k\bu) &= kf(\bu) \\
\end{aligned}
$$
for any vectors $\bu, \bu_1, \bu_2\in U$ and scalar $k\in\mathbb{R}$.
Let $f : U \rightarrow V$ be a linear function.
The **kernel** of $f$ is $\ker(f) = \{\bu\in U: f(\bu) = \bzero\}$.
Recall that $\range(f) = \{ f(\bu) : \bu\in U \}$.
Indeed, $\ker(f)$ is a subspace of $U$ and $\range(f)$ is a subspace of $V$.
Thus, we define the **rank** of $f$ as $\rank(f) = \dim(\range(f))$ and
the **nullity** of $f$ as $\nul(f) = \dim(\ker(f))$.
From the definition, $f$ is surjective if and only if $\range(f) = V$, or, equivalently, $\rank(f) = \dim(V)$.
On the other hand, it is also known that $f$ is injective if and only if $\ker(f) = \{\bzero\}$, or, equivalently, $\nul(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 = \{\bu_1, \ldots, \bu_n\}$ be a basis of $U$ and $f : U\rightarrow V$ a linear function.
If $f(\bu_1) = \bv_1$, $\ldots$, $f(\bu_n) = \bv_n$, then
$$
f(c_1\bu_1 + \cdots + c_n\bu_n) = c_1\bv_1 + \cdots + c_n\bv_n
$$
is uniquely determined, since every vector $\bu$ can be written as a linear combinatoin $c_1\bu_1 + \cdots + c_m\bu_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 = \{\be_1, \be_2, \be_3\}$ 為 $I_3$ 的行向量集合﹐其為 $\mathbb{R}^3$ 的基底。
<!-- eng start -->
Run the code below. Suppose $f: \mathbb{R}^3 \rightarrow \mathbb{R}^4$ is a linear function. Let $\beta = \{\be_1, \be_2, \be_3\}$ be the columns of $I_3$, which is a basis of $\mathbb{R}^3$.
<!-- eng end -->
```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\be_1 + 2\be_2)$。
<!-- eng start -->
Find $f(3\be_1 + 2\be_2)$.
<!-- eng end -->
:::warning
- [x] linear function --> linear functions
:::
##### Exercise 1(a) -- answer here:
Let `seed = 1`, we get
$f(\be_1) = (1, 1, 3, -1)$,
$f(\be_2) = (4, 4, 12, -4)$,
$f(\be_3) = (-3, -2, -8, 7)$.
According to the properties of linear functions:
$f(3\be_1 + 2\be_2) = 3f(\be_1) + 2f(\be_2) = (11, 11, 33, -11).$
##### Exercise 1(b)
求 $\mathbb{R}^3$ 中的一個非零向量 $\bu$ 使得 $f(\bu) = \bzero$。
<!-- eng start -->
Find a nonzero vector $\bu\in\mathbb{R}^3$ such that $f(\bu) = \bzero$.
<!-- eng end -->
:::info
Your approach is correct. Basically, if you found $c_1,c_2,c_3$ such that
$$
c_1(1,1,3,-1) + c_2(4,4,12,-4) + c_3(-3,-2,-8,7) = \bzero,
$$
then you can conclude that $f(c_1\be_1 + c_2\be_2 + c_3\be_3) = \bzero$.
:::
##### Exercise 1(b) -- answer here:
By setting
$$
A = \begin{bmatrix}
| & | & | \\
f(\be_1) & f(\be_2) & f(\be_3) \\
| & | & | \\
\end{bmatrix} =
\begin{bmatrix}
1 & 4 & -3\\
1 & 4 & -2\\
3 & 12 & -8\\
-1 & -4 & 7
\end{bmatrix},
$$
we have $f(\bx) = A\bx$ for all $\bx\in\mathbb{R}^3$.
<!-- We set $f({\bf x}) = A{\bf x}$. -->
Thus, finding a vector $\bu$ with $f(\bu) = \bzero$ is equivalent to finding a vector $\bu\in\ker(A)$.
<!-- Accroding to the question, $f({\bf u}) = {\bf 0} = A{\bf u}$, it means $\ker({A}) = {\bf 0}$. -->
<!-- We know that $\beta = \{\be_1, \be_2, \be_3\}$ be the columns of $I_3$.
By running the code above, we obtain that
$f(\be_1) = (1, 1, 3, -1)$,
$f(\be_2) = (4, 4, 12, -4)$,
$f(\be_3) = (-3, -2, -8, 7)$. -->
After calculating by Gaussian elimination, we get the reduced echelon form $R = \begin{bmatrix}
1 & 4 & -3\\
0 & 0 & 1\\
0 & 0 & 0\\
0 & 0 & 0
\end{bmatrix}$.
By setting the free variable as $1$, we can find a solution to $A{\bf u} = 0$, which is ${\bf u} = (-4,1,0).$
##### Exercise 1(c)
找一個矩陣 $A$ 使得對所有向量 $\bu\in\mathbb{R}^3$ 都有 $f(\bu) = A\bu$。
<!-- eng start -->
Find a matrix $A$ such that $f(\bu) = A\bu$ for any vector $\bu\in\mathbb{R}^3$.
<!-- eng end -->
:::warning
Check grammar.
:::
##### Exercise 1(c) -- answer here:
Let `seed = 1`, we have
$f(\be_1) = (1, 1, 3, -1)$
$f(\be_2) = (4, 4, 12, -4)$
$f(\be_3) = (-3, -2, -8, 7)$
Because $\beta = \{\be_1, \be_2, \be_3\}$ are the columns of $I_3$, which is a basis of $\mathbb{R}^3$.
So,
$$
AI_3= \begin{bmatrix}
1 & 4 & -3\\
1 & 4 & -2\\
3 & 12 & -8\\
-1 & -4 & 7 \\
\end{bmatrix}=A.
$$
## Exercises
##### Exercise 2
判斷以下函數是否線性。
<!-- eng start -->
Determine if each of the following functions is linear.
<!-- eng end -->
##### Exercise 2(a)
判斷 $f: \mathbb{R}\rightarrow\mathbb{R}$ 且 $f(x) = 3x + 5$ 是否線性。
<!-- eng start -->
Let $f: \mathbb{R}\rightarrow\mathbb{R}$ be a function defined by $f(x) = 3x + 5$. Is it linear?
<!-- eng end -->
:::warning
- [x] boldface for vectors.
Since a function is linear when it meets the two conditions for any possible vectors and scalar, it is not linear whenever ==one== of the two conditions fails for ==some particular vectors and scalar== .
:::
##### Exercise 2(a) -- answer here:
We say that $f:U\rightarrow\ V$ is linear if
$$
\begin{aligned}
f(\bu_1 + \bu_2) &= f(\bu_1) + f(\bu_2) \\
f(k\bu) &= kf(\bu) \\
\end{aligned}
$$
for any vectors $\bu, \bu_1, \bu_2\in U$ and scalar $k\in\mathbb{R}$.
Suppose $x=\bv_1+\bv_2$ ,
$$
f( \bv_1+\bv_2)=3(\bv_1+\bv_2)+5 \neq3\bv_1+3\bv_2+10=f(\bv_1)+f(\bv_2).
$$
So $f(x)=3x+5$ is not linear.
OR
Let $k\in\mathbb{R}$ ,
$$
f(k\bv)= 3k\bv+5\neq3k\bv+5k=kf(\bv).
$$
So $f(x)=3x+5$ is not linear.
##### Exercise 2(b)
判斷 $f: \mathbb{R}\rightarrow\mathbb{R}$ 且 $f(x) = 3x$ 是否線性。
<!-- eng start -->
Let $f: \mathbb{R}\rightarrow\mathbb{R}$ be a function defined by $f(x) = 3x$. Is it linear?
<!-- eng end -->
:::warning
- [x] And --> and
- [x] fulfill --> fulfills
:::
##### Exercise 2(b) -- answer here:
Because $f(kx) = 3kx = kf(x)$ and $f(x_1+x_2) = 3x_1 + 3x_2 = f(x_1) + f(x_2)$.
It fulfills the definition,
that's why $f$ is linear.
##### Exercise 2(c)
判斷 $f: \mathbb{R}\rightarrow\mathbb{R}$ 且 $f(x) = x^2$ 是否線性。
<!-- eng start -->
Let $f: \mathbb{R}\rightarrow\mathbb{R}$ be a function defined by $f(x) = x^2$. Is it linear?
<!-- eng end -->
##### Exercise 2(c) -- answer here:
Because of $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$,
we get that $f(x_1+x_2)\neq f(x_1) + f(x_2)$.
So $f(x) = x^2$ is not linear.
##### Exercise 2(d)
判斷 $f: \mathbb{R}^2\rightarrow\mathbb{R}$ 且 $f(x,y) = x^2 + y^2$ 是否線性。
<!-- eng start -->
Let $f: \mathbb{R}^2\rightarrow\mathbb{R}$ be a function defined by $f(x,y) = x^2 + y^2$. Is it linear?
<!-- eng end -->
**[由吳愷杰提供]**
**Answer**
Because $f(kx,ky) = k^2x^2 + k^2y^2$ and $kf(x,y) = kx^2 + ky^2$, we get $kf(x,y) \neq f(kx,ky)$,
Thus, $f$ is not linear.
##### Exercise 2(e)
判斷 $f: \mathbb{R}^2\rightarrow\mathbb{R}$ 且 $f(x,y) = 3x + 2y$ 是否線性。
<!-- eng start -->
Let $f: \mathbb{R}^2\rightarrow\mathbb{R}$ be a function defined by $f(x,y) = 3x + 2y$. Is it linear?
<!-- eng end -->
**[由吳愷杰提供]**
**Answer**
Because $kf(x,y) = 3kx + 2ky = f(kx,ky)$ and
$$\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}
$$
It fulfills the definition, so $f$ is linear.
##### Exercise 2(f)
判斷 $f: \mathbb{R}^2\rightarrow\mathbb{R}$ 且 $f(x,y) = 3x + 2y + 1$ 是否線性。
<!-- eng start -->
Let $f: \mathbb{R}^2\rightarrow\mathbb{R}$ be a function defined by $f(x,y) = 3x + 2y + 1$. Is it linear?
<!-- eng end -->
**[由吳愷杰提供]**
**Answer**
Beacuse $kf(x,y) = 3kx + 2ky + k \neq f(kx,ky)$, $f$ is not linear.
##### Exercise 3
令 $\bu_1, \bu_2, \bu_3$ 為 $U$ 中的向量﹐
已知 $f$ 為從 $U$ 到 $\mathbb{R}^4$ 的線性函數且
$$
\begin{aligned}
f(\bu_1) &= (1,1,1,1) \\
f(\bu_2) &= (1,2,3,4) \\
f(\bu_3) &= (4,3,2,1) \\
\end{aligned}
$$
求 $f(3\bu_1 + 2\bu_2 + 2\bu_3)$。
<!-- eng start -->
Let $\bu_1, \bu_2, \bu_3$ be vectors in the space $U$. Suppose $f$ is a linear function from $U$ to $\mathbb{R}^4$ such that
$$
\begin{aligned}
f(\bu_1) &= (1,1,1,1) \\
f(\bu_2) &= (1,2,3,4) \\
f(\bu_3) &= (4,3,2,1) \\
\end{aligned}
$$
Find $f(3\bu_1 + 2\bu_2 + 2\bu_3)$.
<!-- eng end -->
##### Exercise 3 -- answer here:
Because $f$ is a linear function,
$$\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. $\ker(f) = \{ \bzero \}$.
3. $\nul(f) = 0$.
<!-- eng start -->
Let $f: U\rightarrow V$ be a linear function. Show that the following are equivalent:
1. $f$ is injective.
2. $\ker(f) = \{ \bzero \}$.
3. $\nul(f) = 0$.
<!-- eng end -->
##### Exercise 4 -- answer here:
We want to proof $(1. \leftrightarrow 2.)$.
So we have to proof $(1.\rightarrow2.)$ and $(1.\leftarrow2.)$ are both corret.
$(\Rightarrow)$:
We know $\bzero\in\ker(f)$ since $f$ is linear.
Suppose $\bx\in\ker(f)$ with $\bx\neq\bzero$.
Since $f$ is injective,
we know $f(\bx)\ne f(\bzero)=\bzero$, and $\bx$ is not in the $\ker(f)$. It is a contradiction.
$(\Leftarrow)$:
Suppose $\bx\ne\by\in U$. Then $\bx - \by \ne \bzero$.
This means $f(\bx - \by) \ne \bzero$ since $\bx - \by \ne \bzero$ and $\ker(f) = \{ \bzero \}$.
According to the properties of linear function, $f(\bx) - f(\by) \ne \bzero$.
Thus $f(\bx) \ne f(\by)$.
$1.$ and $2.$ are equivalent.
Because $\nul(f)=\dim(\ker(f))$ by the properties of linear function, and $\ker(f) = \{ \bzero \}$.
Thus $\dim(\ker(f))=\nul(f)=0$.
$2.$ and $3.$ are equivalent.
Because $1.$ and $2.$ are equivalent and $2.$ and $3.$ are equivalent.
Therefore $1.$ $2.$ $3.$are equivalent.
##### Exercise 5
嵌射顧名思義有點像是把定義域嵌入到對應域之中﹐所以很多性質都會被保留下來。
<!-- eng start -->
The name "injection" indicates that the domain is injected, or embedded, into the codomain, so many properties of the domain preserve.
<!-- eng end -->
##### Exercise 5(a)
令 $f: U\rightarrow V$ 為一線性函數。
證明若 $f$ 是嵌射且
$\alpha = \{\bu_1,\ldots,\bu_k\}$ 為 $U$ 中的一線性獨立集﹐
則 $f(\alpha)$ 是 $V$ 中的一線性獨立集。
<!-- eng start -->
Let $f: U\rightarrow V$ be a linear function. Show that if $f$ is injective and $\alpha = \{\bu_1,\ldots,\bu_k\}$ is linearly independent in $U$, then $f(\alpha)$ is linearly independent in $V$.
<!-- eng end -->
**[由孫心提供]**
**Answer**
We set $c_1f({\bf u}_1) + \cdots +c_kf({\bf u}_k) = \bf0$.
Because the function $f$ is linear, $f(c_1{\bf u}_1 + \cdots + c_k\bu_k) = \bf0$.
Accroding to Exercise 4, we know that $\ker(f) = \{ \bzero \}$, because function $f$ is injective.
And so, we know $c_1\bu_1 + \cdots + c_k{\bf u}_k = \bf0$.
Also, $\alpha$ is linearly independent, so $c_1 = \cdots = c_k = 0$.
Therefore, $f(\alpha)$ is a linearly independent set in $V$.
##### Exercise 5(b)
令 $f: U\rightarrow V$ 為一線性函數。
證明若 $f$ 是嵌射且
$\alpha = \{\bu_1,\ldots,\bu_k\}$ 為 $U$ 的一組基底﹐
則 $f(\alpha)$ 是 $\range(f)$ 的一組基底。
<!-- eng start -->
Let $f: U\rightarrow V$ be a linear function. Show that if $f$ is injective and $\alpha = \{\bu_1,\ldots,\bu_k\}$ is a basis of $U$, then $f(\alpha)$ is a basis of $\range(f)$.
<!-- eng end -->
##### Exercise 6
依照步驟確認線性擴充出來的函數符合我們要的性質。
令 $U$ 和 $V$ 為兩向量空間
且 $\beta = \{ \bu_1, \ldots, \bu_n \}$ 為 $U$ 的一組基底。
若 $f : U \rightarrow V$ 是一個線性函數
且已知 $f(\bu_1) = \bv_1$, $\ldots$, $f(\bu_n) = \bv_n$。
<!-- eng start -->
Use the given instructions to verify the linear extension has the desired properties. Let $U$ and $V$ be vector spaces and $\beta = \{ \bu_1, \ldots, \bu_n \}$ a basis of $U$. Suppose $f: U\rightarrow V$ is a linear function and $f(\bu_1) = \bv_1$, $\ldots$, $f(\bu_n) = \bv_n$.
<!-- eng end -->
##### Exercise 6(a)
說明對任何 $\beta$ 的線性組合﹐$f(c_1\bu_1 + \cdots + c_n\bu_n)$ 必須是 $c_1\bv_1 + \cdots + c_n\bv_n$。
<!-- eng start -->
Explain why $f(c_1\bu_1 + \cdots + c_n\bu_n)$ has to be $c_1\bv_1 + \cdots + c_n\bv_n$.
<!-- eng end -->
##### Exercise 6(b)
說明
$$
f(c_1\bu_1 + \cdots + c_n\bu_n) = c_1\bv_1 + \cdots + c_n\bv_n
$$
這個公式是定義完善的函數。
(每個 $U$ 中的元素都有被定義到、
且線性組合的不同表示法不會造成任何問題。)
<!-- eng start -->
Verify that
$$
f(c_1\bu_1 + \cdots + c_n\bu_n) = c_1\bv_1 + \cdots + c_n\bv_n
$$
is well-defined. That is, check if $f$ is defined for every vector in $U$ and check if different representations of a vector in $U$ do not result in different function values.
<!-- eng end -->
##### Exercise 6(c)
說明
$$
f(c_1\bu_1 + \cdots + c_n\bu_n) = c_1\bv_1 + \cdots + c_n\bv_n
$$
這個公式是定義出來的函數是線性的。
<!-- eng start -->
Verify that the function defined by
$$
f(c_1\bu_1 + \cdots + c_n\bu_n) = c_1\bv_1 + \cdots + c_n\bv_n
$$
is linear.
<!-- eng end -->
:::info
collaboration: 1
4 problems: 4
- done: 2a, 2b, 2c, 3
extra: 0.5
- done: 4
moderator: 1
quality control: 1
:::