owned this note
owned this note
Published
Linked with GitHub
# 投影與鏡射
Projection and reflection

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
```
## Main idea
##### Matrix-matrix multiplication (by entry)
Let
$$ A = \begin{bmatrix}
a_{11} & \cdots & a_{1n} \\
\vdots & ~ & \vdots \\
a_{m1} & \cdots & a_{mn} \\
\end{bmatrix} \text{ and }
B = \begin{bmatrix}
b_{11} & \cdots & b_{1\ell} \\
\vdots & ~ & \vdots \\
b_{n1} & \cdots & b_{n\ell} \\
\end{bmatrix}$$
be $m\times n$ and $n\times \ell$ matrices, respectively.
Then the $ij$-entry of $AB$ is
$$(AB)_{ij} = \sum_{k = 1}^n a_{ik}b_{kj}.$$
Let $A$ be an $m\times n$ matrix.
The **transpose** of $A$ is the $n\times m$ matrix $A\trans$ whose $ij$-entry is the $ji$-entry of $A$.
The $n\times n$ **identity matrix** is the matrix whose diagonal entries are one and other entries are zero, usually denoted as $I_n$.
The $m\times n$ **zero matrix** is the matrix whose entries are zero, usually denoted as $O_{m,n}$.
If $A$ is an $n\times n$ matrix and there is a matrix $B$ such that $AB = BA = I_n$,
then $B$ is called the **inverse** of $A$, denoted as $A^{-1} = B$.
A matrix with an inverse is **invertible**.
Suppose $A$ is an $n\times k$ matrix with $\ker(A) = \{\bzero\}$.
Then every vector $\bb\in\mathbb{R}^n$ can be written as
$$\bb = \bw + \bh$$
where $\bw\in\Col(A)$ and $\bh\in\Col(A)^\perp$.
Moreover,
$$\begin{aligned}
\bw &= A(A\trans A)^{-1}A\trans \bb, \\
\bh &= \bb - \bw.
\end{aligned}$$
We say $\bw$ is the **projection** of $\bb$ onto the subspace $\Col(A)$, and
$\bw - \bh$ the **reflection** of $\bb$ along the subspace $\Col(A)$.
Both action can be done by matrices.
That is,
$$\begin{aligned}
\bw &= A(A\trans A)^{-1}A\trans \bb, \\
\bw - \bh &= 2\bw - \bb = (2A(A\trans A)^{-1}A\trans - I_n)\bb.
\end{aligned}
$$
## Side stories
- $\inp{\bx}{\by} = \by\trans\bx$
- matrix algbra
## Experiments
##### Exercise 1
執行下方程式碼。
依照步驟求出 $\bb$ 在 $\Col(A)$ 上的投影。
<!-- eng start -->
Run the code below. Use the given instructions to find the projection of $\bb$ onto $\Col(A)$.
<!-- eng end -->
```python
### code
set_random_seed(0)
print_ans = False
while True:
A = matrix(2, random_int_list(8)).transpose()
if (A.transpose() * A).is_invertible():
break
b = vector(random_int_list(4))
print("A =")
print(A)
print("b =", b)
if print_ans:
AT = A.transpose()
ATA = AT * A
w = A * ATA.inverse() * AT * b
print("The projection is %s."%w)
```
##### Exercise 1(a)
假設 $\bb = \bw + \bh$ 使得
$\bw\in\Col(A)$(也就是有某一個 $\bv$ 使得 $\bw = A\bv$)、
$\bh\in\Col(A)^\perp = \Row(A\trans)^\perp = \ker(A\trans)$(也就是 $A\trans\bh = \bzero$)。
將 $\bb = \bw + \bh$ 兩邊前乘 $A\trans$﹐
並用 $A$、$\bb$、和 $\bv$ 表示出來。
<!-- eng start -->
Assume $\bb = \bw + \bh$ such that $\bw\in\Col(A)$ (meaning $\bw = A\bv$ for some $\bv$) and $\bh\in\Col(A)^\perp = \Row(A\trans)^\perp = \ker(A\trans)$ (meaning $A\trans\bh = \bzero$).
Multiply the both sides of $\bb = \bw + \bh$ by $A\trans$. Then rewrite the equation by $A$, $\bb$, and $\bv$.
<!-- eng end -->
---
:::warning
- [x] Multiplying the both sides (ing)
- [x] It seems not necessary to multiply the both sides by $A$.
- [x] The problem statement is not so clear (my bad). What I am thinking is $A\trans \bb = A\trans A\bv$.
:::
---
##### Exercise 1(a) - answer here
Multiplying the both sides of $\bb = \bw + \bh$ by $A\trans$, we get $A\trans\bb = A\trans\bw + A\trans\bh$.
Because $A\trans\bh = \bzero$ and $\bw=A\bv$, we obtain that $A\trans\bb = A\trans A\bv$.
---
##### Exercise 1(b)
將 $A$ 和 $\bb$ 的數字代入並解方程式求出 $\bv$。
(如果 $A\trans A$ 可逆﹐
則可以把上一題的式子寫成 $\bv = (A\trans A)^{-1} A\trans \bb$。)
<!-- eng start -->
Plug in the numbers for $A$ and $\bb$ to find $\bv$.
(Note that if $A\trans A$ is invertible, then the equation from the previous problem can be written as $\bv = (A\trans A)^{-1} A\trans \bb$.)
<!-- eng end -->
---
:::warning
- [x] Then calculating --> By calculating ..., ~~threfore~~ we have $\bv = ...$.
:::
##### Exercise 1(b) - answer here
If $A\trans A$ is invertible, we can transform the equation $A\trans\bb = A\trans A\bv$ into $\bv=(A\trans A)^{-1}A\trans \bb$.
By running the code above, we obtain that
$$A = \begin{bmatrix}
0 & 0 \\
-1 & 0 \\
0 & 0 \\
-3 & -1
\end{bmatrix}
$$
and
$$
\bb =\begin{bmatrix}
-1 \\
-2 \\
-3 \\
2
\end{bmatrix} .
$$
So we can get that $A\trans=\begin{bmatrix}
0 & -1 & 0 & -3\\
0 & 0 & 0 & -1
\end{bmatrix}$.
By calculating …, $(A\trans A)^{-1}=\begin{bmatrix}
1 & -3\\
-3 & 10
\end{bmatrix}$,
we have $\bv=(A\trans A)^{-1}A\trans \bb=\begin{bmatrix}
1 & -3\\
-3 & 10
\end{bmatrix}\begin{bmatrix}
0 & -1 & 0 & -3\\
0 & 0 & 0 & -1
\end{bmatrix}\begin{bmatrix}
-1 \\
-2 \\
-3 \\
2
\end{bmatrix}$
$\ \ =\begin{bmatrix}
0 & -1 & 0 & 0\\
0 & 3 & 0 & 1
\end{bmatrix}\begin{bmatrix}
-1 \\
-2 \\
-3 \\
2
\end{bmatrix}=\begin{bmatrix}
2 \\
-8
\end{bmatrix}$.
---
##### Exercise 1(c)
因此我們知道
$$
\begin{aligned}
\bw &= A\bv, \\
\bh &= \bb - \bw.
\end{aligned}
$$
以題目給的 $A$ 和 $\bb$ 將 $\bw$ 和 $\bh$ 求出來﹐
並確認 $A\trans\bh = \bzero$。
<!-- eng start -->
Therefore, we know
$$
\begin{aligned}
\bw &= A\bv, \\
\bh &= \bb - \bw.
\end{aligned}
$$
Use the $A$ and $\bb$ given in the problem to find $\bw$ and $\bh$. Then verify $A\trans\bh = \bzero$.
<!-- eng end -->
---
:::warning
- [x] Add periods after math expressions if necessary.
- [x] Through calculating --> By calculation:
- [x] We gain --> We get
:::
##### Exercise 1(c) -- answer here
Accroding to exercise 1(a) 1(b), we understand that
$$A = \begin{bmatrix}
0 & 0 \\
-1 & 0 \\
0 & 0 \\
-3 & -1
\end{bmatrix}
$$
and
$$
\bv =\begin{bmatrix}
2 \\
-8
\end{bmatrix}.
$$
By calculation:
$$
\begin{aligned}
\bw &= A\bv =\begin{bmatrix}
0 & 0\\
-1 & 0\\
0 & 0\\
-3 &-1
\end{bmatrix}\begin{bmatrix}
2\\
-8
\end{bmatrix}\ =\begin{bmatrix}
0 \\
-2 \\
0 \\
2
\end{bmatrix}\
\end{aligned}.
$$
Also based on the calculation results of the previous questions, we have the matrix as
$$
\bb = \begin{bmatrix}
-1 \\
-2 \\
-3 \\
2
\end{bmatrix}
$$
and
$$
\bw = \begin{bmatrix}
0 \\
-2 \\
0 \\
2
\end{bmatrix}.
$$
After calculation, we get the answer of matrix $\bh$
$$
\begin{aligned}
\bh &= \bb - \bw=\begin{bmatrix}
-1 \\
-2 \\
-3 \\
2
\end{bmatrix}-\begin{bmatrix}
0 \\
-2 \\
0 \\
2
\end{bmatrix}\ =\begin{bmatrix}
-1 \\
0 \\
-3\\
0
\end{bmatrix}\
\end{aligned}.
$$
By using the calculation results of the previous questions
$A\trans\bh=\begin{bmatrix}
0 & -1 & 0 & 3\\
0 & 0 & 0 & -1
\end{bmatrix} \ \begin{bmatrix}
-1 \\
0 \\
-3\\
0
\end{bmatrix}\ = \begin{bmatrix}
0 \\
0
\end{bmatrix}\ = \bzero$.
Now, we can verify that $A\trans\bh = \bzero$.
---
## Exercises
##### Exercise 2
以下小題說明為何 $A\trans A$ 可逆。
<!-- eng start -->
The following problems explain why $A\trans A$ is invertible.
<!-- eng end -->
##### Exercise 2(a)
若 $\bx$ 和 $\by$ 為 $\mathbb{R}^n$ 中的兩向量。
驗證 $\inp{\bx}{\by} = \by\trans\bx$。
(這裡的右式把 $\bx$ 和 $\by$ 都當成 $n\times 1$ 的矩陣
而算出來的 $1\times 1$ 的矩陣 $\by\trans\bx$ 被當成一個數字。)
<!-- eng start -->
Let $\bx$ and $\by$ be vectors in $\mathbb{R}^n$. Verify $\inp{\bx}{\by} = \by\trans\bx$. (Here on the right hand side of the equation, we view $\bx$ and $\by$ as $n\times 1$ matrices, while the output $\by\trans\bx$ is an $1\times 1$ matrix and is viewed as a number.)
<!-- eng end -->
---
##### Exercise 2(a) -- answer here
Supose $\bx$ and $\by$ are both $n\times 1$ matrices, then ${\by\trans}$ is an $\times 1$ matrix.
Because $\langle \bx,\by \rangle$ is the inner product of vector $\bx$ and $\by$, we know that $\langle \bx,\by \rangle= x_1y_1+x_2y_2+...+x_ny_n$.
Then we calculate $\by\trans\bx:$
$$\by\trans\bx=\begin{bmatrix}
y_1 & y_2 & ... & y_n
\end{bmatrix}\begin{bmatrix}
x_1 \\
x_2 \\
:\\
x_n
\end{bmatrix} = x_1y_1+x_2y_2+...+x_ny_n.
$$
Hence, we prove that $\inp{\bx}{\by} = \by\trans\bx$.
:::success
Nice :thumbsup:
:::
---
##### Exercise 2(b)
若 $A$ 和 $B$ 分別為 $m\times n$ 和 $n\times \ell$ 的兩矩陣。
驗證 $(AB)\trans = B\trans A\trans$。
<!-- eng start -->
Let $A$ and $B$ be $m\times n$ and $n\times m$ matrices, respectively. Verify $(AB)\trans = B\trans A\trans$.
<!-- eng end -->
---
:::warning
- [x] $\trans$ but not $^{\trans}$
- [x] At the beginning, add: We may assume $A = \begin{bmatrix} a_{ik} \end{bmatrix}$ and $B = \begin{bmatrix} b_{kj} \end{bmatrix}$.
- [x] $(AB)\trans = \begin{bmatrix}\sum_{k=1}^na_{ik}b_{kj}\end{bmatrix}^{\trans}_{m\times \ell} = \begin{bmatrix}\sum_{k=1}^na_{ki}b_{jk}\end{bmatrix}_{\ell\times m}$
- [x] $B\trans A\trans=[\;b_{kj}\;]_{\ell\times n}[\;a_{ki}\;]_{n\times m}=\begin{bmatrix}\sum_{k=1}^na_{ki}b_{jk}\end{bmatrix}_{\ell\times m}$.
:::
##### Exercise 2(b) -- answer here
We may assume $A$ = $[\;a_{ik}\;]$ and $B$ = $[\;b_{kj}\;]$.
Because $A$ is an $m\times n$ matrix and $B$ is an $n\times \ell$ matrix,
$(AB)_{ij} = \sum_{k = 1}^n a_{ik}b_{kj}.$
And $A\trans=[\;a_{ik}\;]\trans_{m\times n}=[\;a_{ki}\;]_{n\times m}$,
$B\trans=[\;b_{kj}\;]\trans_{n\times \ell}=[\;b_{jk}\;]_{\ell\times n}$.
So, we have $(AB)\trans=\begin{bmatrix}\sum_{k=1}^na_{ik}b_{kj}\end{bmatrix}^{\trans}_{m\times \ell} = \begin{bmatrix}\sum_{k=1}^na_{ki}b_{jk}\end{bmatrix}_{\ell\times m}$
and $B\trans A\trans=[\;b_{kj}\;]_{\ell\times n}[\;a_{ki}\;]_{n\times m}=\begin{bmatrix}\sum_{k=1}^na_{ki}b_{jk}\end{bmatrix}_{\ell\times m}$.
Therefore, we prove that $(AB)\trans = B\trans A\trans$.
---
##### Exercise 2(c)
驗證 $\inp{A\bx}{\by} = \by\trans A\bx = \inp{\bx}{A\trans\by}$。
<!-- eng start -->
Verify $\inp{A\bx}{\by} = \by\trans A\bx = \inp{\bx}{A\trans\by}$.
<!-- eng end -->
---
##### Exercise 2(c) -- answer here
By exercise 2(a), we know $\inp{A\bx}{\by} =\by\trans A\bx.$
And by exercise 2(b), we also know that $\by\trans A=(A\trans\by)\trans$.
Hence, $\inp{A\bx}{\by} =\by\trans A\bx=(A\trans\by)\trans\bx=\inp{\bx}{A\trans\by}.$
:::success
Good!
:::
---
##### Exercise 2(d)
證明 $\ker(A) = \ker(A\trans A)$。
因為 $A\trans A$ 是一個方陣,
後面會證明一個方陣 $M$ 可逆的等價條件就是 $\ker(M) = \{\bzero\}$。
因此 $\ker(A) = \{\bzero\}$ 足以保證 $A\trans A$ 可逆。
另一方面,
如果 $\ker(A) \neq \{\bzero\}$,
表示 $A$ 中的行向量有一些可以去掉並不會影響到行空間。
重覆這個步驟直到沒有任何多餘的行向量時
(這時行空間都還是同一個)
就保證有 $\ker(A) = \{\bzero\}$。
(參考【矩陣的行向量】中的練習。)
<!-- eng start -->
Prove $\ker(A) = \ker(A\trans A)$.
We will learn that a square matrix $M$ with $\ker(M) = \{\bzero\}$ is always invertible. Since $A\trans A$ is a square matrix, $\ker(A) = \{\bzero\}$ implies $A\trans A$ is invertible.
On the other hand, if $\ker(A) \neq \{\bzero\}$, then there are some redundant columns in $A$, whose removal does not change the column space. Keep removing these volumns while preserving the column space until there is no more redundant column. Therefore, we may always assume $\ker(A) = \{\bzero\}$. (See 103-4.)
<!-- eng end -->
---
##### Exercise 2(d) -- answer here
:::warning
- [x] $O$ --> $\bzero$
I think your argument only shows $\ker(A) \subset \ker(A\trans A)$.
For such questions, you are recommended to use the following template.
**Claim**: $\ker(A) \subset \ker(A\trans A)$.
Suppose $\bv\in\ker(A)$. Then $A\bv = \bzero$.
...
Thus, we have $\bv\in\ker(A\trans A)$.
**Claim**: $\ker(A) \supset \ker(A\trans A)$.
Suppose $\bv\in\ker(A\trans A)$. Then $A\trans A\bv = \bzero$.
... (this one is harder)
Thus, we have $\bv\in\ker(A)$.
By the previous two claims, we know the two sets are the same.
:::
**Claim**: $\ker(A) \subseteq \ker(A\trans A)$.
Suppose $\bv\in\ker(A)$. Then $A\bv = \bzero$.
Multiplying the both sides of $A\bv=\bzero$ by $A\trans$, we get that $A\trans A\bv=A\trans \bzero=\bzero.$
Thus, we have $\bv\in\ker(A\trans A)$.
**Claim**: $\ker(A\trans A) \subseteq \ker(A)$.
Suppose $\bv\in\ker(A\trans A)$. Then $A\trans A\bv = \bzero$.
Multiplying the both sides of $A\trans A\bv=\bzero$ by $\bv\trans$, we get that $\bv\trans A\trans A\bv=(A\bv)\trans A\bv= \inp{A\bv}{A\bv}=\|{A\bf v}\|^2 =0.$
So we prove that $A\bv=\bzero.$
Thus, we have $\bv\in\ker(A)$.
By the previous two claims, we know the two sets are the same, and $\ker(A) = \ker(A\trans A)$ is proven.
---
##### Exercise 3(a)
想像矩陣乘法就是一個動作(像是投影、或是鏡射)
若 $A$ 是一個投影矩陣、
$\bb$ 是一個向量。
猜看看 $A^2\bb$ 會是什麼?
猜看看 $A^2$ 會是什麼?
(下方程式碼中的矩陣是一個投影矩陣。
可以試試看。)
<!-- eng start -->
Imagine that multiplying a matrix is like applying an action, e.g., projection or reflection, to a vector. Let $A$ is a projection matrix and $\bb$ a vector. Guess what is $A^2\bb$ and what is $A^2$? Provide your reasons. (You may run some examples by the code below.)
<!-- eng end -->
```python
### code
set_random_seed(0)
a = vector(random_int_list(3))
A = a.outer_product(a) / a.norm()**2
b = vector(random_int_list(3))
print("A =")
show(A)
print("b =", b)
```
:::warning
- [x] let $A$ be
- [x] When typing $A^2\bb$, put $\bb$ as a column vector.
- [x] the square will return to the original --> its square is itself
- [x] python --> Python
- [x] below --> below.
:::
##### Exercise 3(a) -- answer here
According to the questions, let $A$ be a projection matrix and $\bb$ a vector.
By running the code above, we get the matrix $A$ and vector $\bb$
$$A = \begin{bmatrix}
\frac{8}{25} & \frac{-6}{25} & \frac{-2}{5} \\
\frac{-6}{25} & \frac{9}{50} & \frac{3}{10} \\
\frac{-2}{5} & \frac{3}{10} & \frac{1}{2}
\end{bmatrix}
$$
and
$$
\bb = ( {-5},{-5},{0}).
$$
Vector $\bb$ can be written as a column vector like:
$$
\bb = \begin{bmatrix}
-5\\
-5\\
0
\end{bmatrix}
$$
After calculating through the program, we can find that
$$
A^2\bb = \begin{bmatrix}
\frac{8}{25} & \frac{-6}{25} & \frac{-2}{5} \\
\frac{-6}{25} & \frac{9}{50} & \frac{3}{10} \\
\frac{-2}{5} & \frac{3}{10} & \frac{1}{2}
\end{bmatrix}\ \begin{bmatrix}
-5\\
-5\\
0
\end{bmatrix}= \begin{bmatrix}
−25\\
310\\
12
\end{bmatrix}
$$
$$
A^2 = \begin{bmatrix}
\frac{8}{25} & \frac{-6}{25} & \frac{-2}{5} \\
\frac{-6}{25} & \frac{9}{50} & \frac{3}{10} \\
\frac{-2}{5} & \frac{3}{10} & \frac{1}{2}
\end{bmatrix}.
$$
After the above discussion, it can be concluded that for the projection matrix $A$, its square is itself.
$$
A^2 = A
$$
Attach the Python code for this question below.
```python
### code
set_random_seed(0)
a = vector(random_int_list(3))
A = a.outer_product(a) / a.norm()**2
b = vector(random_int_list(3))
print("A =")
show(A)
print("b =", b)
print() # Blank Line
print() # Blank Line
print("A^2 = ")
show(A**2)
print() # Blank Line
print() # Blank Line
print("A^2 * b =")
show(A**2*b)
```
---
##### Exercise 3(b)
想像矩陣乘法就是一個動作(像是投影、或是鏡射)
若 $A$ 是一個鏡射矩陣、
$\bb$ 是一個向量。
猜看看 $A^2\bb$ 會是什麼?
猜看看 $A^2$ 會是什麼?
(下方程式碼中的矩陣是一個投影矩陣。
可以試試看。)
<!-- eng start -->
Imagine that multiplying a matrix is like applying an action, e.g., projection or reflection, to a vector. Let $A$ is a reflection matrix and $\bb$ a vector. Guess what is $A^2\bb$ and what is $A^2$? Provide your reasons. (You may run some examples by the code below.)
<!-- eng end -->
```python
### code
set_random_seed(0)
a = vector(random_int_list(3))
A = 2*a.outer_product(a) / a.norm()**2 - identity_matrix(3)
b = vector(random_int_list(3))
print("A =")
show(A)
print("b =", b)
```
:::warning
Mathematically correct :smiley:
Revise the writting according to the comments above.
:::
##### Exercise 3(b) -- answer here
According to the questions, let $A$ is a reflection matrix and $\bb$ a vector.
By running the code above, we get the matrix $A$ and vector $\bb$
$$A = \begin{bmatrix}
\frac{-9}{25} & \frac{-12}{25} & \frac{-4}{5} \\
\frac{-12}{25} & \frac{-16}{25} & \frac{3}{5} \\
\frac{-4}{5} & \frac{3}{5} & 0
\end{bmatrix}
$$
and
$$
\bb = ( {-5},{-5},{0}).
$$
After calculating through the program, we get the answer that
$$
A^2\bb = \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}\ \begin{bmatrix}
-5\\
-5\\
0
\end{bmatrix} = \begin{bmatrix}
−5\\
-5\\
0
\end{bmatrix}
$$
$$
A^2 = \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}.
$$
After the above discussion and calculation, we can find that the square of the reflection matrix will be the identity matrix.
$$
A^2 = \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}
$$
Attach the python code for this question here:
```python
### code
set_random_seed(0)
a = vector(random_int_list(3))
A = 2*a.outer_product(a) / a.norm()**2 - identity_matrix(3)
b = vector(random_int_list(3))
print("A =")
show(A)
print("b =", b)
print() # Blank Line
print() # Blank Line
print("A^2 = ")
show(A**2)
print() # Blank Line
print() # Blank Line
print("A^2 * b =")
show(A**2*b)
```
##### Exercise 4
令 $A$、$B$、$C$ 為矩陣
$\bx$ 和 $\by$ 為向量、$k$ 為純量。
驗證以下的矩陣運算等式。
<!-- eng start -->
Let $A$, $B$, and $C$ be matrices. Let $\bx$ and $\by$ be vectors. Let $k$ be a scalar. Verify the following identities.
<!-- eng end -->
##### Exercise 4(a)
1. $(AB)C = A(BC)$.
2. $A(B + C) = AB + AC$.
3. $A(kB) = k(AB)$.
4. $A(\bx + \by) = A\bx + A\by$.
5. $A(k\bx) = k(A\bx)$.
**[Provided by 蔡睿丞]**
Suppose $A$, $B$, $C$ are $i\times s$ , $s\times t$ and $t\times j$ matrices, respectively.
1.$((AB)C)_{ij}=(\sum\limits_{s = 1}^n{A_{is}}{B_{st}})\sum\limits_{t = 1}^\ell{C_{tj}}=\sum\limits_{s = 1}^n{A_{is}}(\sum\limits_{t = 1}^\ell{B_{st}}{C_{tj}})=(A(BC))_{ij}.$
Suppose $A$ is an $i\times s$ matrix and $B$, $C$ be $s\times j$ matrices.
2.$(A(B + C))_{ij} = \sum\limits_{s = 1}^n{A_{is}}(B_{sj}+C_{sj})=\sum\limits_{s = 1}^n{A_{is}}B_{sj}+\sum\limits_{s = 1}^n{A_{is}}C_{sj}=(AB)_{ij}+(AC)_{ij}.$
3.$(A(kB))_{ij}=\sum\limits_{s = 1}^n{A_{is}}(kB_{sj})=k\sum\limits_{s = 1}^n{A_{is}}B_{sj}=k(AB)_{ij}.$
Because we know ${\bf x} , {\bf y}$ are two vectors ,and we can write them as $s\times 1$ matrices.
4.$(A({\bf x} + {\bf y}))_{i1} = \sum\limits_{s = 1}^n{A_{is}}({\bf x}_{s1}+{\bf y}_{s1})=\sum\limits_{s = 1}^n{A_{is}}{\bf x}_{s1}+\sum\limits_{s = 1}^n{A_{is}}{\bf y}_{s1}=(A{\bf x})_{i1}+(A{\bf y})_{i1}.$
5.$(A(k{\bf x}))_{i1}=\sum\limits_{s = 1}^n{A_{is}}(k{\bf x}_{s1})=k\sum\limits_{s = 1}^n{A_{is}}{\bf x}_{s1}=k(A{\bf x})_{i1}.$
##### Exercise 4(b)
給一組例子使得 $AB \neq BA$。
<!-- eng start -->
Find an example where $AB \neq BA$.
<!-- eng end -->
---
##### Exercise 4(b) -- answer here
Let
$$ A = \begin{bmatrix}
1 & 2 \\
3 & 4 \\
\end{bmatrix} \text{ and }
B = \begin{bmatrix}
5 & 6 \\
7 & 8 \\
\end{bmatrix}.$$
Then we get
$$ AB = \begin{bmatrix}
19 & 22 \\
43 & 50 \\
\end{bmatrix} \text{ and }
BA = \begin{bmatrix}
23 & 34 \\
31 & 46 \\
\end{bmatrix}.
$$
Hence, we find an example where $AB \neq BA$.
---
##### Exercise 4(c)
若 $A$ 和 $B$ 皆為可逆矩陣。
則 $(AB)^{-1} = B^{-1}A^{-1}$。
<!-- eng start -->
Show that if both $A$ and $B$ are invertible, then $(AB)^{-1} = B^{-1}A^{-1}$.
<!-- eng end -->
---
##### Exercise 4(c) - answer here
If $X$ and $Y$ are two matrices with $XY=YX=I$,
then, $X^{-1}=Y$.
Multiply $B^{-1}A^{-1}$ by $AB$.
We get $(AB)B^{-1}A^{-1}=A(BB^{-1})A^{}=AIA^{-1}=AA^{-1}=I.$
Multiply $AB$ by $B^{-1}A^{-1}$.
We get $B^{-1}A^{-1}(AB)=B^{-1}(AA^{-1})B=B^{-1}IB=BB^{-1}=I$.
So, we can know that $(AB)( B^{-1}A^{-1})= ( B^{-1}A^{-1})(AB)=I$.
Thus, $(AB)^{-1} = B^{-1}A^{-1}$.
---
##### Exercise 4(d)
定義一個方陣 $M$ 的**跡數**(trace)為其對角線上的所有元素相加,記作 $\tr(M)$。
則 $\tr(A +B) = \tr(A) + \tr(B)$。
<!-- eng start -->
Define the **trace** of a square matrix $M$ as the sum of all its diagonal entries, denoted by $\tr(M)$. Show that $\tr(A +B) = \tr(A) + \tr(B)$.
<!-- eng end -->
##### Exercise 4(e)
若 $A$ 和 $B$ 為 $2\times 2$ 的方陣。
則 $\det(AB) = \det(A) \cdot \det(B)$。
(實際上 $n\times n$ 都對,但我們還沒學到 $n\times n$ 方陣的行列式值怎麼算。)
<!-- eng start -->
Let $A$ and $B$ be $2\times 2$ matrices. Show that $\det(AB) = \det(A) \cdot \det(B)$.
(In fact, this identity is true for any $n\times n$ matrices. However, we have not learned what is the determinant of an $n\times n$ matrix.)
<!-- eng end -->
:::info
Collaboration: 1
4 problems: 4
extra problems: 2
moderator: +1
quality control: +1
:::