owned this note
owned this note
Published
Linked with GitHub
# 矩陣乘積與轉置
Matrix multiplication and transpose

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, 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$ 都是一群單位矩陣的乘積。
<!-- eng start -->
Run the code below. Suppose we know $A = F_1\cdots F_k$ and $B = E_1\cdots E_h$ are the product of some elementary matrices.
<!-- eng end -->
```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)$。
<!-- eng start -->
Write $AB$ as the product of some elementary matrices and find $\det(AB)$.
<!-- eng end -->
---
##### Exercise 1(a) - answer here
By running the code above, we obtain that
$$
A = F_1\cdots F_k .
$$
$$
\begin{bmatrix}
-3 & 3 \\
1 & 2
\end{bmatrix}=\begin{bmatrix}
-3 & 0 \\
0 & 1
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
1 & 1
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
0 & 3
\end{bmatrix}\begin{bmatrix}
1 & -1 \\
0 & 1
\end{bmatrix}.
$$
$$
B = E_1\cdots E_h.
$$
$$
\begin{bmatrix}
-3 & -3 \\
-1 & 3
\end{bmatrix}=\begin{bmatrix}
-3 & 0 \\
0 & 1
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
-1 & 1
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
0 & 4
\end{bmatrix}\begin{bmatrix}
1 & 1 \\
0 & 1
\end{bmatrix}.
$$
So, $$AB = F_1\cdots F_k E_1\cdots E_h
=\begin{bmatrix}
-3 & 0 \\
0 & 1
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
1 & 1
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
0 & 3
\end{bmatrix}\begin{bmatrix}
1 & -1 \\
0 & 1
\end{bmatrix}\begin{bmatrix}
-3 & 0 \\
0 & 1
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
-1 & 1
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
0 & 4
\end{bmatrix}\begin{bmatrix}
1 & 1 \\
0 & 1
\end{bmatrix}.
$$
By calculation,
$\det(A) = (-3)\times2-1\times3 = -9.$
$\det(B) = (-3)\times3-(-1)\times(-3) = -12.$
Therefore,
$$
\det(AB) = \det(A)\det(B)=(-9)\times(-12)=108.
$$
:::warning
The question asks you to write $AB$ as the product of some elementary matrices.
:::
---
##### Exercise 1(b)
將 $A\trans$ 寫成基本矩陣的乘積,並求出 $\det(A\trans)$。
<!-- eng start -->
Write $A\trans$ as the product of some elementary matrices and find $\det(A\trans)$.
<!-- eng end -->
---
##### Exercise 1(b) - answer here
By running the code above, we obtain that
$$A=\begin{bmatrix}
-3 & 3 \\
1 & 2
\end{bmatrix}=\begin{bmatrix}
-3 & 0 \\
0 & 1
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
1 & 1
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
0 & 3
\end{bmatrix}\begin{bmatrix}
1 & -1 \\
0 & 1
\end{bmatrix}.$$
Thus, we know that
$$A\trans=\begin{bmatrix}
-3 & 1 \\
3 & 2
\end{bmatrix}=\begin{bmatrix}
-3 & 0 \\
0 & 1
\end{bmatrix}\begin{bmatrix}
1 & 1 \\
0 & 1
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
0 & 3
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
-1 & 1
\end{bmatrix}.
$$
Therefore,
$\det(A\trans) = (-3)\times2-3\times1 = -9.$
---
:::info
What do the experiments try to tell you? (open answer)
If $A$ is an invertible matrix,
$\det(A)=\det(A\trans).$
$\det(AB) = \det(A)\det(B).$
:::
:::success
Jephian:
How about $\det(AB)$?
:::
## Exercises
##### Exercise 2
在總列數為 $3$ 的情況下,
寫下以下列運算的基本矩陣 $E$,
並解釋 $E\trans$ 所對應的列運算是什麼。
<!-- eng start -->
Consider matrices with $3$ rows. Find the elementary matrix corresponding to each of the following properties. Then explain what is the corresponding row operation for $E\trans$.
<!-- eng end -->
##### Exercise 2(a)
列運算 $\rho_i\rightarrow\rho_j$。
<!-- eng start -->
The row operation $\rho_i\rightarrow\rho_j$.
<!-- eng end -->
---
##### Exercise 2(a) - answer here
Let $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.$
The corresponding row operation of $E\trans$ is $\rho_i\leftrightarrow\rho_j.$
:::warning
Write the complete sentences. For example:
The correspondiing row operation of $E\trans$ is ... .
:::
---
##### Exercise 2(b)
列運算 $\rho_i: \times k$。
<!-- eng start -->
The row operation $\rho_i: \times k$.
<!-- eng end -->
---
##### Exercise 2(b) - answer here
Let $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.$
The correspondiing row operation of $E\trans$ is $\rho_i: \times k.$
:::warning
Write the complete sentences.
:::
---
##### Exercise 2(c)
列運算 $\rho_i: +k\rho_j$。
<!-- eng start -->
The row operation $\rho_i: +k\rho_j$.
<!-- eng end -->
---
##### Exercise 2(c) - answer here
Let $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}.$
The correspondiing row operation of $E\trans$ is $\rho_j: +k\rho_i.$
:::warning
Write the complete sentences.
:::
---
##### Exercise 3
若 $A$ 為一可逆矩陣。
證明 $\det(A^{-1}) = \det(A)^{-1}$。
<!-- eng start -->
Suppose $A$ is an invertible matrix. Show that $\det(A^{-1}) = \det(A)^{-1}$.
<!-- eng end -->
---
##### Exercise 3 - answer here
Since $\det(AA^{-1})=\det(I)=1,$
by matrix multiplication, $\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$。
<!-- eng start -->
Suppose $A$ is an orthogonal matrix. Show that $\det(A) = \pm 1$.
<!-- eng end -->
---
##### Exercise 4 - answer here
Since $\det(A A\trans)=1=\det(A\trans A),$
by matrix multiplication, $\det(A\trans)\times\det(A)=1.$
Thus, by matrix transpose, $\det(A\trans)=\det(A).$
We get $[\det(A)]^{2}=1.$
Therefore, $\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)$。
<!-- eng start -->
Let $V$ be a $2$-dimensional subspace in $\mathbb{R}^3$ and $f:\mathbb{R}^3 \rightarrow \mathbb{R}^3$ is the projection sending any vector $\bv\in\mathbb{R}^3$ onto $V$. Find $\det(f)$.
<!-- eng end -->
---
##### Exercise 5 - answer here
$f$ is irreversible since it is a many-to-one function.
Thus, $\det(f) = 0$ .
:::warning
For the solution below, $A\trans A$ is not invertible.
:::
Another Explanation:
Let $V = \vspan{\{\bu_1,\bu_2}\}$, and $\bu_1,\bu_2$ is perpendicular to each other, and their length are both $1$.\
Let
$$
A = \begin{bmatrix}
| & | & 0 \\
\bu_1 & \bu_2 & 0 \\
| & | & 0\end{bmatrix}.
$$
According to the projection formula, $f$ can be written as $A(A\trans A)^{-1} A\trans$.\
Therefore,
$$
\begin{array}{l}
\det(f) &= \det( A(A\trans A)^{-1} A\trans ) \\
&= \det(A) \times \det(A\trans) \times \det( (A\trans A)^{-1} ) \\
& = 0\times \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)$。
<!-- eng start -->
Let $V$ be a $2$-dimensional subspace in $\mathbb{R}^3$ and $f:\mathbb{R}^3 \rightarrow \mathbb{R}^3$ is the reflection sending any vector $\bv\in\mathbb{R}^3$ to the other side of $V$. Find $\det(f)$.
<!-- eng end -->
##### Exercise 7
令 $A$ 和 $B$ 皆為 $n\times n$ 矩陣。
依照以下步驟證明以下敘述等價。
- $AB$ 可逆。
- $A$ 和 $B$ 皆可逆。
(這題為證明 $\det(AB) = \det(A)\det(B)$ 的必要過程,
所以請不要用行列式值來證明。)
<!-- eng start -->
Let $A$ and $B$ be $n\times n$ matrix. Follow the given steps to show the two statements below are equivalent.
- $AB$ is invertible.
- $A$ and $B$ are both invertible.
(This problem is a necessary step for proving $\det(AB) = \det(A)\det(B)$, so please do not use the previous equality to prove it.
<!-- eng end -->
##### Exercise 7(a)
證明:
若 $\ker(B) \neq \{\bzero\}$,則 $\ker(AB) \neq \{\bzero\}$。
<!-- eng start -->
Show that if $\ker(B) \neq \{\bzero\}$, then $\ker(AB) \neq \{\bzero\}$.
<!-- eng end -->
**[由蔡睿丞提供]**
We know that :
If ${\bf x} \in \ker(B)$, then $B {\bf x} = {\bf 0}$.
Therefore, when ${\bf x} \in \ker(B)$,
$AB {\bf x} = A {\bf 0} = {\bf 0}$.
So we can conclude that:
$\ker(B) \subseteq \ker(AB)$.
This proves that :
If $\ker(B) \neq \{\bzero\}$, then $\ker(AB) \neq \{\bzero\}$.
##### Exercise 7(b)
證明:
若 $\Col(A) \neq \mathbb{R}^n$,則 $\Col(AB) \neq \mathbb{R}^n$。
<!-- eng start -->
Show that if $\Col(A) \neq \mathbb{R}^n$, then $\Col(AB) \neq \mathbb{R}^n$.
<!-- eng end -->
**[由蔡睿丞提供]**
We know that:
$\Col(A) = \{A {\bf x} : {\bf x} \in \mathbb{R}^n \}$ .
and
$\Col(AB) = \{AB {\bf x} : {\bf x} \in \mathbb{R}^n \}$ .
Because $\Col(B) = \{B {\bf x} : {\bf x} \in \mathbb{R}^n \}$ .
we can write $\Col(AB)$ as $\{A {\bf x} : {\bf x} \in \Col(B) \}$ .
This implies $\Col(AB) \subseteq \Col(A)$.
Therefore, if $\Col(A) \neq \mathbb{R}^n$, then $\Col(AB) \neq \mathbb{R}^n$ .
##### Exercise 7(c)
證明:
若 $A$ 和 $B$ 皆可逆,則 $AB$ 可逆。
<!-- eng start -->
Show that if both $A$ and $B$ are invertible, then $AB$ is also invertible.
<!-- eng end -->
---
##### Exercise 7(c) - answer here
We know that $A$, $B$ are invertible, which means $A^{-1}$, $B^{-1}$ exists.
$E=AA^{-1}=AEA^{-1}=ABB^{-1}A^{-1}=AB(B^{-1}A^{-1}).$
Therefore, $AB$ is invertible and $(AB)^{-1}=B^{-1}A^{-1}.$
---
:::info
collaboration: 2
3 problems: 3
* 2a~c
extra: 2
* 3,4,5,7(c)
moderator: 1
<!-- qc: 1 -->
:::