# 將矩陣視為線性函數
Matrix as a 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_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 \\
\bu &\mapsto A\bu
\end{aligned}
$$
defines a linear function.
With this connection,
- $\range(f_A) = \Col(A)$,
- $\ker(f_A) = \ker(A)$,
- $\rank(f_A) = \rank(A)$,
- $\nul(f_A) = \nul(A)$.
By the dimension theorem, the following are equivalent:
1. $f_A$ is injective.
2. $\nul(A) = 0$.
3. $\rank(A) = n$.
On the other hand, $f_A$ is surjective if and only if $\rank(A) = m$.
Therefore, the inverse of $f_A$ exists only when $\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} = \idmap_{\mathbb{R}^n}$.
Let $\mathcal{E}_n = \{ \be_1, \ldots, \be_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}
\be_1 &\mapsto & d_1\be_1, \\
&\vdots & \\
\be_n &\mapsto & d_n\be_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 $\be_i$ to $\be_{\sigma(i)}$.
## Side stories
- build $A$ from $A\be_i$
## Experiments
##### Exercise 1
執行以下程式碼。
已知 $\left[\begin{array}{c|c} R & \br \end{array}\right]$ 為 $\left[\begin{array}{c|c} A & \bb \end{array}\right]$ 的最簡階梯形式矩陣。
令 $f_A$ 為對應到矩陣 $A$ 的線性函數。
<!-- eng start -->
Run the code below. Let $\left[\begin{array}{c|c} R & \br \end{array}\right]$ be the reduced echelon form of $\left[\begin{array}{c|c} A & \bb \end{array}\right]$. Let $f_A$ be the linear function representing $A$.
<!-- eng end -->
```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)
```
##### Exercise 1(a)
判斷 $\bb$ 是否落在 $\range(f_A)$ 中。
<!-- eng start -->
Is $\bb$ in $\range(f_A)$?
<!-- eng end -->
---
:::warning
- [x] end of the reduced echelon form: comma --> period
:::
##### Exercise 1(a) - answer here
By running the code above, we obtain
$$
\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],
$$
and its reduce echelon form is
$$
\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].
$$
Therefore, the solution $\bx$ of equation $R\bx=\br$ exists, which means $f_A(\bx)=\bb$ has solutions, so we prove that $\bb$ is in $\range(f_A)$.
---
##### Exercise 1(b)
判斷 $\bu$ 是否落在 $\ker(f_A)$ 中。
<!-- eng start -->
Is $\bu$ in $\ker(f_A)$?
<!-- eng end -->
---
##### Exercise 1(b) - answer here
By running the code above, we obtain $\bu=(0,3,1,0)$.
Since $R\bu=\begin{bmatrix}1&0&0&3\\0&1&-3&-3\\0&0&0&0\\\end{bmatrix}\begin{bmatrix}0\\3\\1\\0\\\end{bmatrix}=\bzero$, we prove that $\bu$ is in $\ker(f_A)$.
---
## Exercises
##### Exercise 2
對以下各矩陣 $A$:
1. 說明 $f_A$ 的作用。
2. 寫出 $\range(f_A)$ 及 $\rank(f_A)$。
3. 寫出 $\ker(f_A)$ 及 $\nul(f_A)$。
4. 判斷 $f_A$ 是否可逆;若可逆﹐其反函數為何?
<!-- eng start -->
For each of the following matrices:
1. Describe the effect of $f_A$.
2. Find $\range(f_A)$ and $\rank(f_A)$.
3. Find $\ker(f_A)$ and $\nul(f_A)$.
4. Is $f_A$ invertible? If yes, what is the inverse function?
<!-- eng end -->
##### Exercise 2(a)
$$
A = \begin{bmatrix}
1 & 0 & 0 \\
0 & 2 & 0 \\
0 & 0 & 3 \\
\end{bmatrix}.
$$
---
:::warning
- [x] been extended --> being extended
- [x] the inverse function is $f_{A^{-1}}$ with $A^{-1} = ...$.
- [x] Put math in math mode.
:::
##### Exercise 2(a) - answer here
1. $x$-axis maintan the same, $y$-axis being extended to $2y$, and $z$-axis being extended to $3z$.
2. $\range(f_A) = \Col(A)$ $=$ $$\vspan\left\{
\begin{bmatrix}
1 \\
0 \\
0 \\
\end{bmatrix},
\begin{bmatrix}
0\\
2\\
0\\
\end{bmatrix},
\begin{bmatrix}
0\\
0\\
3\\
\end{bmatrix}
\right\}.
$$
$\rank(f_A) = \rank(A) = 3.$
3. $\ker(f_A) = \ker(A) =$
$$\left\{\begin{bmatrix}
0\\
0\\
0\\
\end{bmatrix}\right\}.
$$
$\nul(f_A) = \nul(A) = 0.$
4. Yes, $f_A$ is invertible since $\rank(A) = m = n$, and the inverse function is $f_{A^{-1}}$ with
$$
A^{-1} =
\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] been --> being
- [x] Put math in math mode.
:::
##### Exercise 2(b) - answer here
1. $x$-axis and $y$-axis maintan the same, and $z$-axis being compressed to $0.$
In other words, it becomes the $xy$-plane.
2. $\range(f_A) = \Col(A)$ $=$ $$\vspan\left\{
\begin{bmatrix}
1 \\
0 \\
0 \\
\end{bmatrix},
\begin{bmatrix}
0\\
1\\
0\\
\end{bmatrix}
\right\}.
$$
$\rank(f_A) = \rank(A) = 2.$
3. $\ker(f_A) = \ker(A) =$
$$\left\{\begin{bmatrix}
0\\
0\\
k\\
\end{bmatrix} \mid k\in\mathbb{R}\right\}.
$$
$\nul(f_A) = \nul(A) = 1.$
4. No, $f_A$ is not invertible since the inverse of $f_A$ exists only when $\rank(A) = m = n$.
However, $\rank(A) = 2$, but $m = n = 3.$
---
##### Exercise 2(c)
$$
A = \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & -1 \\
\end{bmatrix}.
$$
---
:::warning
- [x] been --> being
- [x] the inverse function is incorrect.
- [x] Put math in math mode.
:::
##### Exercise 2(c) - answer here
1. $x$-axis and $y$-axis maintan the same, and $z$-axis being reflected.
2. $\range(f_A) = \Col(A)$ $=$ $$\vspan\left\{
\begin{bmatrix}
1 \\
0 \\
0 \\
\end{bmatrix},
\begin{bmatrix}
0\\
1\\
0\\
\end{bmatrix},
\begin{bmatrix}
0\\
0\\
-1\\
\end{bmatrix}
\right\}.
$$
$\rank(f_A) = \rank(A) = 3.$
3. Because matrix $A$ is linear independent.
So $\ker(f_A) = \ker(A) =$
$$\left\{\begin{bmatrix}
0\\
0\\
0\\
\end{bmatrix}\right\}.
$$
$\nul(f_A) = \nul(A) = 0.$
4. Yes, $f_A$ is invertible because $\rank(A) = m = n$, and the inverse function is $f_{A^{-1}}$ with
$$
A^{-1} =
\begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & -1 \\
\end{bmatrix}.
$$
---
##### 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] rotatio --> rotation
- [x] something wrong in item 2
- [x] kernel is a set
- [x] inversable --> invertible
- [x] $f_A^{-1}$ is not a matrix --- see 2(a) for how to fix it
- [x] Put math in math mode.
:::
##### Exercise 2(d) - answer here
The matrix $A$ can be written as
$$
A = \begin{bmatrix}
1 & 0 & 0 \\
0 & \cos45^\circ & -\sin45^\circ \\
0 & \sin45^\circ & \cos45^\circ \\
\end{bmatrix},
$$
which is a rotation matrix rotating around x-axis.
Hence,
1. $f_A$ makes a vector rotated $45$ degrees around x-axis.
2. $$\range(f_A)=\Col(A)=\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\}=\mathbb{R}^3,
$$
and $\rank(f_A)=3$.
3. $\ker(f_A)=\{\bzero\}$ , and $\operatorname{null}(f_A)=0.$
4. $f_A$ is invertible, and the inverse function is $f_{A^{-1}}$ with
$$
A^{-1} = \begin{bmatrix}
1 & 0 & 0 \\
0 & \cos(-45^\circ) & -\sin(-45^\circ) \\
0 & \sin(-45^\circ) & \cos(-45^\circ) \\
\end{bmatrix}=\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}.
$$
---
##### Exercise 2(e)
$$
A = \begin{bmatrix}
0 & 1 & 0 \\
0 & 0 & 1 \\
1 & 0 & 0 \\
\end{bmatrix}.
$$
**[由孫心提供]**
**Answer**
The function $f_A$ will replace ${\be}_1$, ${\be}_2$ and ${\be}_3$ with ${\be}_3$, ${\be}_1$, and ${\be}_2$, respectively.
$$\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\}= \mathbb{R}^3,
$$
$\rank(f) = \dim(\range(f)) = 3$.
Since $\rank(f) = 3$ and $\rank(f) + \nul(f) = 3$, we have $\nul(f) = 0$. Consequently, $\ker(f) = \{\bzero\}$.
The function $f_A$ is invertible.
And the inverse function of $f_A$ will replace ${\be}_3$, ${\be}_1$, and ${\be}_2$ with ${\be}_1$, ${\be}_2$ and ${\be}_3$, respectively.
##### Exercise 3
令 $A$ 為一 $m\times n$ 矩陣。
<!-- eng start -->
Let $A$ be an $m\times n$ matrix.
<!-- eng end -->
##### Exercise 3(a)
說明若 $m < n$ 則 $f_A$ 不可能是嵌射。
<!-- eng start -->
Explain why $f_A$ is not injective whenever $m < n$.
<!-- eng end -->
##### Exercise 3(b)
說明若 $m > n$ 則 $f_A$ 不可能是映射。
<!-- eng start -->
Explain why $f_A$ is not surjective whenever $m > n$.
<!-- eng end -->
##### Exercise 4
令 $A$ 為一可逆矩陣。
驗證 $f_A^{-1} = f_{A^{-1}}$。
<!-- eng start -->
Let $A$ be an invertible matrix. Show that $f_A^{-1} = f_{A^{-1}}$.
<!-- eng end -->
##### Exercise 5
令 $A$ 為一 $m\times n$ 矩陣。
令 $\mathcal{E}_n = \{ \be_1,\ldots, \be_n \}$ 為 $\mathbb{R}^n$ 的標準基底。
<!-- eng start -->
Let $A$ be an $m\times n$ matrix. Let $\mathcal{E}_n = \{ \be_1,\ldots, \be_n \}$ be the standard basis of $\mathbb{R}^n$.
<!-- eng end -->
##### Exercise 5(a)
若 $m = 4$、$n = 3$ 且已知
$$
\begin{aligned}
f_A(\be_1) &= (1,1,1,1), \\
f_A(\be_2) &= (1,2,3,4), \\
f_A(\be_3) &= (4,3,2,1). \\
\end{aligned}
$$
求 $A$。
<!-- eng start -->
Suppose $m = 4$, $n = 3$, and
$$
\begin{aligned}
f_A(\be_1) &= (1,1,1,1), \\
f_A(\be_2) &= (1,2,3,4), \\
f_A(\be_3) &= (4,3,2,1). \\
\end{aligned}
$$
Find $A$.
<!-- eng end -->
##### Exercise 5(b)
說明 $A$ 會是把 $f(\be_1), \ldots, f(\be_n)$ 依序當成行向量的矩陣。
<!-- eng start -->
Explain that $A$ is the matrix whose columns are $f(\be_1), \ldots, f(\be_n)$.
<!-- eng end -->
:::info
collaboration: 1
4 problems: 4
- done: 2(a~d)
moderator: 1
quality control: 1
:::