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/).
$\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}}$
```python
from lingeo import random_int_list, row_operation_process
```
## Main idea
When $A$ and $B$ are both $n\times n$ matrices, then $\det(AB) = \det(A) \det(B)$.
Intuitively, this follows from the fact that
_the determinants are the scaling factors_!
A formal proof can be done by the elementary matrices.
If both $A$ and $B$ are invertible,
then they can be written as the products of elementary matrices
$$
A = F_1\cdots F_k \text{ and } B = E_1\cdots E_h,
$$
so $AB$ can be written as the product of elementary matrices
$$
AB = F_1\cdots F_k E_1\cdots E_h.
$$
Therefore,
$$
\begin{aligned}
\det(AB) &= \det(F_1)\cdots\det(F_k)\det(E_1)\cdots\det(E_h) \\
&= \big(\det(F_1)\cdots\det(F_k)\big)\big(\det(E_1)\cdots\det(E_h)\big) \\
&= \det(A)\det(B).
\end{aligned}
$$
On the other hand, it is known that $AB$ is invertible if and only if both $A$ and $B$ are invertible.
Thanks to this nice property, we may derive the following facts.
- If $Q$ is invertible, then $\det(Q^{-1})\det(Q) = \det(I_n) = 1$.
- If $B = Q^{-1}AQ$ for some invertible $Q$, then $\det(B) = \det(A)$.
As a consequence, we may define the **determinant** of linear function $f: V\rightarrow V$ by
$$
\det(f) = \det([f]_\beta^\beta),
$$
where $\beta$ can be any basis of $V$.
For matrix transpose, $\det(A\trans) = \det(A)$.
Intuitively, this follows from the fact that
$$
\det(A\trans) = \Vol_C(A\trans) = \Vol_R(A) = \det(A),
$$
since we have shown that the column parallelotope and the row parallelotop (surprisingly) have the same signed volumn.
Again, formally we may prove by the elementary matrices.
Let's make some observations first.
- If $E$ is the elementary matrix for $\rho_i\leftrightarrow\rho_j$, then $E\trans = E$, so $\det(E\trans) = \det(E) = -1$.
- If $E$ is the elementary matrix for $\rho_i: \times k$, then $E\trans = E$, so $\det(E\trans) = \det(E) = k$.
- If $E$ is the elementary matrix for $\rho_i: +k\rho_j$, then $E\trans$ is the elementary matrix for $\rho_j: +k\rho_i$, so $\det(E\trans) = \det(E) = 1$.
If $A$ is invertible, then we may write $A$ as the product of elementary matrices
$$
A = F_1 \cdots F_k,
$$
so
$$
A\trans = F_k\trans \cdots F_1\trans
$$
and
$$
\begin{aligned}
\det(A\trans) &= \det(F_k\trans)\cdots\det(F_1\trans) \\
&= \det(F_k) \cdots \det(F_1) \\
&= \det(F_1) \cdots \det(F_k) \\
&= \det(A).
\end{aligned}
$$
## Side stories
- inverse matrix
- orthogonal matrix
## Experiments
##### Exercise 1
執行以下程式碼。
已知 $A = F_1\cdots F_k$ 及 $B = E_1\cdots E_h$ 都是一群單位矩陣的乘積。
```python
### code
set_random_seed(0)
print_ans = False
n = 2
while True:
A = matrix(n, random_int_list(n^2, 3))
B = matrix(n, random_int_list(n^2, 3))
if A.det() != 0 and B.det() != 0:
break
elems_A = row_operation_process(A, inv=True)
elems_B = row_operation_process(B, inv=True)
print("A = F1 ... Fk")
pretty_print(A, LatexExpr("="), *elems_A)
print("B = E1 ... Eh")
pretty_print(B, LatexExpr("="), *elems_B)
if print_ans:
print("AB = F1 ... Fk E1 ... Eh")
pretty_print(A * B, LatexExpr("="), *(elems_A + elems_B))
print("det(AB) =", (A*B).det())
elems_AT = [elems.transpose() for elems in elems_A[::-1]]
print("A trans = Fk trans ... F1 trans")
pretty_print(A.transpose(), LatexExpr("="), *elems_AT)
print("det(A trans) =", A.transpose().det())
```
##### Exercise 1(a)
將 $AB$ 寫成基本矩陣的乘積,並求出 $\det(AB)$。
**[由汪駿佑同學提供]**
藉由 `seed 10` 可以得到
$$
A = \begin{bmatrix}
2 & -3 \\
2 & −1
\end{bmatrix},
B = \begin{bmatrix}
0 & -1 \\
3 & 2
\end{bmatrix}.
$$
並且
$$
\begin{array}{l}
A = \begin{bmatrix}
2 & 0 \\
0 & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 \\
2 & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 \\
0 & 2
\end{bmatrix}
\begin{bmatrix}
1 & \frac{-3}{2} \\
0 & 1
\end{bmatrix}, \\
B = \begin{bmatrix}
0 & 1 \\
1 & 0
\end{bmatrix}
\begin{bmatrix}
3 & 0 \\
0 & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 \\
0 & -1
\end{bmatrix}
\begin{bmatrix}
1 & \frac{2}{3} \\
0 & 1
\end{bmatrix}.
\end{array}
$$
那我們就能寫出
$$
AB = \begin{bmatrix}
2 & 0 \\
0 & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 \\
2 & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 \\
0 & 2
\end{bmatrix}
\begin{bmatrix}
1 & \frac{-3}{2} \\
0 & 1
\end{bmatrix}
\begin{bmatrix}
0 & 1 \\
1 & 0
\end{bmatrix}
\begin{bmatrix}
3 & 0 \\
0 & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 \\
0 & -1
\end{bmatrix}
\begin{bmatrix}
1 & \frac{2}{3} \\
0 & 1
\end{bmatrix}.
$$
並且 $\det(AB)$ 可以寫成這些基本矩陣的行列式值乘積,即
$$
\det(AB) = 2 \cdot 1 \cdot 2 \cdot 1 \cdot (-1) \cdot 3 \cdot (-1) \cdot 1 = 12.
$$
**[由張書鳴同學提供]**
藉由 `seed 3`
可得 $$A=F_1\cdots F_k.$$
$\begin{bmatrix}
-3 & 3 \\
3 & 1\end{bmatrix}=\begin{bmatrix}
-3 & 0 \\
0 & 1\end{bmatrix}\begin{bmatrix}
1 & 0 \\
3 & 1\end{bmatrix}\begin{bmatrix}
1 & 0 \\
0 & 4\end{bmatrix}\begin{bmatrix}
1 & -1 \\
0 & 1\end{bmatrix}$,
以及 $$B=E_1\cdots E_h.$$
$\begin{bmatrix}
-1 & -2 \\
3 & -3\end{bmatrix}=\begin{bmatrix}
-1 & 0 \\
0 & 1\end{bmatrix}\begin{bmatrix}
1 & 0 \\
3 & 1\end{bmatrix}\begin{bmatrix}
1 & 0 \\
0 & -9\end{bmatrix}\begin{bmatrix}
1 & 2 \\
0 & 1\end{bmatrix}$,
因此 $$AB=F_1\cdots F_k E_1\cdots E_0.$$
故
$\begin{bmatrix}
-3 & 3 \\
3 & 1\end{bmatrix}\begin{bmatrix}
-1 & -2 \\
3 & -3\end{bmatrix}$
$=\begin{bmatrix}
-3 & 0 \\
0 & 1\end{bmatrix}\begin{bmatrix}
1 & 0 \\
3 & 1\end{bmatrix}\begin{bmatrix}
1 & 0 \\
0 & 4\end{bmatrix}\begin{bmatrix}
1 & -1 \\
0 & 1\end{bmatrix}\begin{bmatrix}
-1 & 0 \\
0 & 1\end{bmatrix}\begin{bmatrix}
1 & 0 \\
3 & 1\end{bmatrix}\begin{bmatrix}
1 & 0 \\
0 & -9\end{bmatrix}\begin{bmatrix}
1 & 2 \\
0 & 1\end{bmatrix}$
$=\begin{bmatrix}
12 & -3 \\
0 & -9\end{bmatrix}.$
所以
$$
\det(AB)=12 \times (-9)-0 \times (-3)=-108.
$$
##### Exercise 1(b)
將 $A\trans$ 寫成基本矩陣的乘積,並求出 $\det(A\trans)$。
**[由汪駿佑同學提供]**
因為
$$
A = \begin{bmatrix}
2 & 0 \\
0 & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 \\
2 & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 \\
0 & 2
\end{bmatrix}
\begin{bmatrix}
1 & \frac{-3}{2} \\
0 & 1
\end{bmatrix}.
$$
那我們就能知道
$$
\begin{array}{l}
A\trans &= \left(\begin{bmatrix}
2 & 0 \\
0 & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 \\
2 & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 \\
0 & 2
\end{bmatrix}
\begin{bmatrix}
1 & \frac{-3}{2} \\
0 & 1
\end{bmatrix}\right)\trans \\
&= \begin{bmatrix}
1 & \frac{-3}{2} \\
0 & 1
\end{bmatrix}\trans
\begin{bmatrix}
1 & 0 \\
0 & 2
\end{bmatrix}\trans
\begin{bmatrix}
1 & 0 \\
2 & 1
\end{bmatrix}\trans
\begin{bmatrix}
2 & 0 \\
0 & 1
\end{bmatrix}\trans \\
&= \begin{bmatrix}
1 & 0 \\
\frac{-3}{2} & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 \\
0 & 2
\end{bmatrix}
\begin{bmatrix}
1 & 2 \\
0 & 1
\end{bmatrix}
\begin{bmatrix}
2 & 0 \\
0 & 1
\end{bmatrix}.
\end{array}
$$
那我們也能按照上面的方法求出
$$
\det(A\trans) = 1 \cdot 2 \cdot 1 \cdot 2 = 4.
$$
**[由張書鳴同學提供]**
藉由 `seed 3`以及矩陣轉置後會等於其基本矩陣轉置後乘積的性質
可得
$$A\trans=F_1\trans\cdots F_k\trans
$$
$\begin{bmatrix}
-3 & 3 \\
3 & 1\end{bmatrix}=\begin{bmatrix}
-3 & 0 \\
0 & 1\end{bmatrix}\begin{bmatrix}
1 & 3 \\
0 & 1\end{bmatrix}\begin{bmatrix}
1 & 0 \\
0 & 4\end{bmatrix}\begin{bmatrix}
1 & 0 \\
-1 & 1\end{bmatrix}$,
因此
$\det(A\trans)=\det(\begin{bmatrix}
-3 & 3 \\
3 & 1\end{bmatrix})=\det(\begin{bmatrix}
-3 & 0 \\
0 & 1\end{bmatrix}\begin{bmatrix}
1 & 3 \\
0 & 1\end{bmatrix}\begin{bmatrix}
1 & 0 \\
0 & 4\end{bmatrix}\begin{bmatrix}
1 & 0 \\
-1 & 1\end{bmatrix})=-12$。
## Exercises
##### Exercise 2
在總列數為 $3$ 的情況下,
寫下以下列運算的基本矩陣 $E$,
並解釋 $E\trans$ 所對應的列運算是什麼。
##### Exercise 2(a)
列運算 $\rho_i\leftrightarrow\rho_j$。
$Ans:$
$E= \begin{bmatrix}
1 & 0 & 0 \\
0 & 0 & 1 \\
0 & 1 & 0\end{bmatrix}$ ,
$E\trans= \begin{bmatrix}
1 & 0 & 0 \\
0 & 0 & 1 \\
0 & 1 & 0\end{bmatrix}=E$ ,
$E\trans$ 所對應的列運算為 $\rho_i\leftrightarrow\rho_j$ 。
##### Exercise 2(b)
列運算 $\rho_i: \times k$。
$Ans:$
$E= \begin{bmatrix}
1 & 0 & 0 \\
0 & k & 0 \\
0 & 0 & 1\end{bmatrix}$ ,
$E\trans= \begin{bmatrix}
1 & 0 & 0 \\
0 & k & 0 \\
0 & 0 & 1\end{bmatrix}=E$ ,
$E\trans$ 所對應的列運算為 $\rho_i: \times k$ 。
##### Exercise 2(c)
列運算 $\rho_i: +k\rho_j$。
$Ans:$
$E= \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & k \\
0 & 0 & 1\end{bmatrix}$ ,
$E\trans= \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & k & 1\end{bmatrix}$ ,
$E\trans$ 所對應的列運算為 $\rho_j: +k\rho_i$ 。
##### Exercise 3
若 $A$ 為一可逆矩陣。
證明 $\det(A^{-1}) = \det(A)^{-1}$。
:::warning
- [x] 標點盡量用全型
:::
$Ans:$
因為 $\det(AA^{-1})=\det(I)=1$ ,
所以 $\det(A)\det(A^{-1})=1$ , $\frac{1}{\det(A)}=[\det(A)]^{-1}=\det(A^{-1})$,故得證。
##### Exercise 4
若 $A$ 為一垂直矩陣($A\trans A = AA\trans = I_n$)。
證明 $\det(A) = \pm 1$。
:::warning
- [x] 可得到 $[\det(A)]^{2}=1$,$\det(A)=\pm 1$ -> 可得到 $[\det(A)]^{2}=1$,所以 $\det(A)=\pm 1$
:::
$Ans:$
因為 $\det(A A\trans)=1=\det(A\trans A),$
所以 $\det(A\trans)\times\det(A)=1.$
且因為 $\det(A\trans)=\det(A),$
可得到 $[\det(A)]^{2}=1$,所以 $\det(A)=\pm 1$,故得證。
##### Exercise 5
令 $V$ 為 $\mathbb{R}^3$ 中的一個二維空間,
而 $f:\mathbb{R}^3 \rightarrow \mathbb{R}^3$ 將向量 $\bv\in\mathbb{R}^3$ 投影到 $V$ 上。
求 $\det(f)$。
***Ans:***
由於 $f$ 為多對一的函數,
可知其不可逆,
因此 $\det(f) = 0$ 。
:::warning
下面這部份待更新。
:::
另解:
令 $V = \vspan{\{\bu_1,\bu_2}\}$,並且 $\bu_1,\bu_2$ 長度為 $1$ 且互相垂直。
令
$$
A = \begin{bmatrix}
| & | & 0 \\
\bu_1 & \bu_2 & 0 \\
| & | & 0\end{bmatrix}.
$$
按照投影公式,$f$ 可表示成 $A(A\trans A)^{-1} A\trans$。
則
$$
\begin{array}{l}
\det(f) &= \det( A(A\trans A)^{-1} A\trans ) \\
&= \det(A) \cdot \det(A\trans) \cdot \det( (A\trans A)^{-1} ) \\
& = 0\cdot \det( (A\trans A)^{-1} ) \\
& = 0.
\end{array}
$$
##### Exercise 6
令 $V$ 為 $\mathbb{R}^3$ 中的一個二維空間,
而 $f:\mathbb{R}^3 \rightarrow \mathbb{R}^3$ 將向量 $\bv\in\mathbb{R}^3$ 鏡射到 $V$ 的對面。
求 $\det(f)$。
***Ans:***
設 $\{ {\bf u}_1 , {\bf u}_2 \}$ 為 $V$ 的其中一組基底,
另取一垂直 $V$ 的向量 ${\bf u}_3$ ,
令 $Q = \begin{bmatrix}
| & | & | \\
{\bf u}_1 & {\bf u}_2 & {\bf u}_3 \\
| & | & |
\end{bmatrix}$ ,
($Q$ 為從 $\{ {\bf u}_1 , {\bf u}_2 ,{\bf u}_3 \}$ 到標準基底的基底變換矩陣) ,
則可將此鏡射矩陣改寫為 $Q \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & -1
\end{bmatrix} Q^{-1}$ 。
已知基底改變不會影響行列式值,
故可得 $\det(f) = -1$ 。
##### Exercise 7
令 $A$ 和 $B$ 皆為 $n\times n$ 矩陣。
依照以下步驟證明以下敘述等價。
- $AB$ 可逆。
- $A$ 和 $B$ 皆可逆。
(這題為證明 $\det(AB) = \det(A)\det(B)$ 的必要過程,
所以請不要用行列式值來證明。)
##### Exercise 7(a)
證明:
若 $\ker(B) \neq \{\bzero\}$,則 $\ker(AB) \neq \{\bzero\}$。
***Ans:***
已知 $A \bzero = \bzero$ ,
則可知任何 ${\bf x} \in \ker(B)$ ,會使 $AB {\bf x} = A {\bf 0} = {\bf 0}$ 。
所以 $\ker(B) \subseteq \ker(AB)$ ,
可得若 $\ker(B) \neq \{\bzero\}$,則 $\ker(AB) \neq \{\bzero\}$。
##### Exercise 7(b)
證明:
若 $\Col(A) \neq \mathbb{R}^n$,則 $\Col(AB) \neq \mathbb{R}^n$。
:::warning
- [x] 集合的建構法中間用冒號,像是 $\Col(A) = \{A {\bf x} : {\bf x} \in \mathbb{R}^n \}$
:::
***Ans:***
已知 $\Col(A) = \{A {\bf x} : {\bf x} \in \mathbb{R}^n \}$ ,
同理 $\Col(AB) = \{AB {\bf x} : {\bf x} \in \mathbb{R}^n \}$ ,
又 $\Col(B) = \{B {\bf x} : {\bf x} \in \mathbb{R}^n \}$ 。
則 $\Col(AB)$ 可改寫為 $\{A {\bf x} : {\bf x} \in \Col(B) \}$ 。
已知 $\Col(B) \subseteq \mathbb{R}^n$,
可推得 $\Col(AB) \subseteq \Col(A)$ 。
因此若 $\Col(A) \neq \mathbb{R}^n$,則 $\Col(AB) \neq \mathbb{R}^n$ 。
##### Exercise 7(c)
證明:
若 $A$ 和 $B$ 皆可逆,則 $AB$ 可逆。
:::warning
- [x] :astonished: :astonished: :astonished: 第二行是不是有打錯字
:::
***Ans:***
由於 $A$ 和 $B$ 皆可逆,
則存在 $A^{-1}$ 和 $B^{-1}$ ,使 $A^{-1}A = AA^{-1} = I$ , $B^{-1}B = BB^{-1} = I$ 。
則可知 $AB$ 必有 $(AB)^{-1} = B^{-1}A^{-1}$ ,使 $ABB^{-1}A^{-1} = AA^{-1} = I$ ,且 $B^{-1}A^{-1}AB = BB^{-1} = I$ 。
得證 $AB$ 可逆。
:::info
目前分數 = 5 ± 檢討 = 6
:::