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/).
{%hackmd 5xqeIJ7VRCGBfLtfMi0_IQ %}
```python
from lingeo import random_int_list
from linspace import ptov, vtop
```
## Main idea
Let $V$ be a vector space.
Let $\beta = \{ {\bf u}_1, \ldots, {\bf u}_n \}$ be a basis of $V$.
Every vector ${\bf v}\in V$ has a unique way to be written as a linear combination
$${\bf v} = c_1{\bf u}_1 + \cdots + c_n{\bf u}_n.
$$
We call the vector $(c_1,\ldots, c_n)\in\mathbb{R}^n$ the **vector representation** of ${\bf v}$ with respect to the basis $\beta$, denoted as $[{\bf v}]_\beta$.
Let $\mathcal{P}_d$ be the vector space of all polynomials of degree at most $d$.
Let $\beta = \{1, x, \ldots, x^d\}$ be the standard basis of $\mathcal{P}_d$.
Then $[p]_\beta = \operatorname{ptov}(p)$ is simply writing down the coefficients of $p$ into a vector in $\mathbb{R}^{d+1}$.
Let $\mathcal{M}_{m.n}$ be the vector space of all $m\times n$ matrices.
Let $\beta = \{E_{11}, \ldots, E_{1n}, \ldots, E_{m1}, \ldots, E_{mn}\}$ be the standard basis of $\mathcal{M}_{m,n}$.
Then $[A]_\beta = \operatorname{mtov}(A)$ is simply writing down the entries of $A$ into a vector in $\mathbb{R}^{mn}$ in the row-major order.
## Side stories
- use the standard basis to solve the vector representation
- new inner product
## Experiments
##### Exercise 1
執行以下程式碼。
令 $\mathcal{P}_2$ 為所有次數小於等於 $2$ 的多項式所形成的向量空間。
令 $\alpha = \{1, x, x^2\}$ 為 $\mathcal{P}_2$ 的標準基底。
令 $\beta = \{1, (1+x), (1+x)^2\}$ 為 $\mathcal{P}_2$ 的另一組基底。
令```seed``` $=69$,得 $p = 2 + 3x + 2x^2$。
```python
### code
set_random_seed(0)
print_ans = False
d = 2
p1,p2,p3 = 1, 1+x, (1+x)^2
p = vtop(vector(random_int_list(d+1)))
print("p =", p)
if print_ans:
A = matrix([ptov(p1, d), ptov(p2, d), ptov(p3, d)]).transpose()
p_alpha = ptov(p, d)
p_beta = A.inverse() * p_alpha
print("[p]_alpha =", ptov(p, d))
print("[p]_beta =", p_beta)
print("A =")
show(A)
```
##### Exercise 1(a)
求出 $[p]_\alpha$。
$Ans:$
根據觀察,$p = 2 \cdot 1 + 3 \cdot x + 2 \cdot x^2$,所以 $[p]_\alpha = \begin{bmatrix}
2\\3\\2
\end{bmatrix}$。
##### Exercise 1(b)
求出 $[p]_\beta$。
$Ans:$
令 $p = c_1 + c_2(1+x) + c_3(1+x)^2$,其中 $c_1,c_2,c_3 \in \mathbb{R}$。
則
$$
\begin{aligned}
p &= c_1 + c_2(1+x) + c_3(1+x)^2\\
&= (c_1 + c_2 + c_3) + (c_2 + 2c_3)x + c_3x^2\\
&= 2 + 3x + 2x^2
\end{aligned}
$$
觀察 $x^2$ 項得 $c_3 = 2$,再看 $x$ 項得 $c_2 + 4 = 3$,$c_2 = -1$,最後常數項 $c_1 + 1 = 2$,$c_1 = 1$。
所以 $p = 1 \cdot 1 + (-1) \cdot (1+x) + 2 \cdot x^2$,
$[p]_\beta = \begin{bmatrix}
1\\-1\\2
\end{bmatrix}$。
##### Exercise 1(c)
令 $p_1, \ldots, p_3$ 為 $\beta$ 中的各多項式。
寫出 $3\times 3$ 矩陣 $A$
其各行向量為 $[p_1]_\alpha, \ldots, [p_3]_\alpha$。
$Ans:$
根據題目 $p_1 = 1$,$p_2 = 1 + x$,$p_3 = 1 + 2x + x^2$
稍微改寫一下,可以得
$$
p_1 = 1 \cdot 1 + 0 \cdot x + 0 \cdot x^2\\
p_2 = 1 \cdot 1 + 1 \cdot x + 0 \cdot x^2\\
p_3 = 1 \cdot 1 + 2 \cdot x + 1 \cdot x^2\\
A =
\begin{bmatrix}
1 & 1 & 1\\
0 & 1 & 2\\
0 & 0 & 1
\end{bmatrix}
$$
##### Exercise 1(d)
驗證並說明為什麼 $A[p]_\beta = [p]_\alpha$。
:::warning
- [x] 以下證明所有的 $p \in \mathcal{P}_2$,$[p]_\beta = \begin{bmatrix}
c_1 \\ c_2 \\ c_3
\end{bmatrix}$
-->
以下證明所有的 $p \in \mathcal{P}_2$ 等式都成立。
假設 $[p]_\beta = \begin{bmatrix}
c_1 \\ c_2 \\ c_3
\end{bmatrix}$,則 $p = c_1p_1 + c_2p_2 + c_3p_3$。
:::
$Ans:$
先驗證例子
$$
\begin{aligned}
A[p]_\beta &=
\begin{bmatrix}
1 & 1 & 1\\
0 & 1 & 2\\
0 & 0 & 1
\end{bmatrix}
\begin{bmatrix}
1\\
-1\\
2\\
\end{bmatrix}\\&=
\begin{bmatrix}
1 \cdot 1 + 1 \cdot (-1) + 1 \cdot 2\\
0 \cdot 1 + 1\cdot (-1) + 2 \cdot 2\\
0 \cdot 1 + 0 \cdot (-1) + 1 \cdot 2
\end{bmatrix}\\
&=\begin{bmatrix}
2\\
3\\
2
\end{bmatrix}\\
&= [p]_\alpha
\end{aligned}
$$
以下證明所有的 $p \in \mathcal{P}_2$ 等式都成立。
假設 $[p]_\beta = \begin{bmatrix}
c_1 \\ c_2 \\ c_3
\end{bmatrix}$,則 $p = c_1p_1 + c_2p_2 + c_3p_3$。
$$
\begin{aligned}
A[p]_\beta &= A\begin{bmatrix}c_1 \\ c_2 \\ c_3\end{bmatrix}\\
&=A\begin{bmatrix}c_1 \\ 0 \\ 0\end{bmatrix} + A\begin{bmatrix}0 \\ c_2 \\ 0\end{bmatrix} + A\begin{bmatrix}0 \\ 0 \\ c_3\end{bmatrix}\\
&= c_1[p_1]_\alpha + c_2[p_2]_\alpha + c_3[p_3]_\alpha\\
&= [p]_\alpha
\end{aligned}
$$
## Exercises
##### Exercise 2
令 $\mathcal{P}_2$ 為所有次數小於等於 $2$ 的多項式所形成的向量空間。
令 $p = 2 + 3x + 4x^2$。
##### Exercise 2(a)
令 $\beta = \{1,x,x^2\}$ 為 $\mathcal{P}_2$ 的一組基底。
求 $[p]_\beta$。
$Ans:$
根據觀察 $p = 2 \cdot 1 + 3 \cdot x + 4 \cdot x^2$,所以 $[p]_\beta = \begin{bmatrix}
2\\3\\4
\end{bmatrix}$。
##### Exercise 2(b)
令 $\beta = \{1,(1-x),(1-x)^2\}$ 為 $\mathcal{P}_2$ 的一組基底。
求 $[p]_\beta$。
$Ans:$
應用1(d),取 $A = \begin{bmatrix} 1 & 1 & 1\\ 0 & -1 & -2\\ 0 & 0 & 1 \end{bmatrix}$,$A[p]_\beta = [p]_\alpha$。
先求出 $A^{-1} = \begin{bmatrix} 1 & 1 & 1\\ 0 & -1 & -2\\ 0 & 0 & 1 \end{bmatrix}$,所以
$$
[p]_\beta = A^{-1}[p]_\alpha = \begin{bmatrix}
9\\-11\\4
\end{bmatrix}.
$$
##### Exercise 2(c)
令 $\beta = \{1,x,x(x-1)\}$ 為 $\mathcal{P}_2$ 的一組基底。
求 $[p]_\beta$。
:::warning
- [x] $\begin{bmatrix} 1 & x & x(x-1) \end{bmatrix} \cdot \begin{bmatrix} C_1 \\ C_2 \\ C_3 \end{bmatrix} =$ 這部份好像不用?
:::
$Ans:$
令 $[p]_\beta = \begin{bmatrix} C_1 \\ C_2 \\ C_3 \end{bmatrix}$ ,
滿足
$$
C_1 \cdot 1 + C_2 \cdot x + C_3 \cdot x(x-1) = 2 + 3x + 4x^2,
$$
解得 $C_1 = 2,C_2 = 7,C_3 = 4$ ,
故 $[p]_\beta = \begin{bmatrix} 2 \\ 7 \\ 4 \end{bmatrix}$。
##### Exercise 2(d)
令
$$\begin{aligned}
p_1(x) &= \frac{(x-2)(x-3)}{(1-2)(1-3)}, \\
p_2(x) &= \frac{(x-1)(x-3)}{(2-1)(2-3)}, \\
p_3(x) &= \frac{(x-1)(x-2)}{(3-1)(3-2)}. \\
\end{aligned}
$$
令 $\beta = \{p_1, p_2, p_3\}$ 為 $\mathcal{P}_2$ 的一組基底。
求 $[p]_\beta$。
:::warning
- [x] 一樣,好像沒必要寫 "$\begin{bmatrix} p_1 & p_2 & p_3 \end{bmatrix} \cdot \begin{bmatrix} C_1 \\ C_2 \\ C_3 \end{bmatrix} =$"
:::
$Ans:$
令 $[p]_\beta = \begin{bmatrix} C_1 \\ C_2 \\ C_3 \end{bmatrix}$ ,
滿足
$$
C_1 \cdot \frac{(x-2)(x-3)}{(1-2)(1-3)} + C_2 \cdot \frac{(x-1)(x-3)}{(2-1)(2-3)} + C_3 \cdot \frac{(x-1)(x-2)}{(3-1)(3-2)} = 2 + 3x + 4x^2,
$$
將 $x=1,x=2,x=3$ 分別帶入解得 $C_1 = 9,C_2 = 24,C_3 = 47$,
故 $[p]_\beta = \begin{bmatrix} 9 \\ 24 \\ 47 \end{bmatrix}$。
:::success
good :slightly_smiling_face:
:::
**另解:**
可以觀察到,$\{ p_1, p_2, p_3 \}$ 是一組 Lagrange basis 對應到 $1, 2, 3$,所以 $p$ 可以寫成
$$
\begin{aligned}
p &= 2 + 3x + 4x^2\\
&= p(1)p_1 + p(2)p_2 + p(3)p_3
\end{aligned}
$$
所以
$$
\begin{aligned}{[p]}_\beta
&=
\begin{bmatrix}
p(1)\\p(2)\\p(3)
\end{bmatrix}\\
&=\begin{bmatrix}9\\24\\47\end{bmatrix}.\end{aligned}
$$
##### Exercise 3
令 $\mathcal{M}_{2,3}$ 為所有 $2\times 3$ 矩陣所形成的向量空間。
令
$$A = \begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
\end{bmatrix}.
$$
##### Exercise 3(a)
令 $\beta = \{E_{11}, E_{12}, E_{13}, E_{21}, E_{22}, E_{23}\}$ 為 $\mathcal{M}_{2,3}$ 的標準基底。
求 $[A]_\beta$。
$Ans:$
明顯地,$A=E_{11}+2E_{12}+3E_{13}+4E_{21}+5E_{22}+6E_{23}$。
因此,$[A]_\beta=\begin{bmatrix} 1\\2\\3\\4\\5\\6 \end{bmatrix}$。
##### Exercise 3(b)
令
$$
M_1 = \begin{bmatrix}
1 & 1 & 1 \\
1 & 1 & 1 \\
\end{bmatrix},
M_2 = \begin{bmatrix}
0 & 1 & 1 \\
1 & 1 & 1 \\
\end{bmatrix},
M_3 = \begin{bmatrix}
0 & 0 & 1 \\
1 & 1 & 1 \\
\end{bmatrix},
$$
$$
M_4 = \begin{bmatrix}
0 & 0 & 0 \\
1 & 1 & 1 \\
\end{bmatrix},
M_5 = \begin{bmatrix}
0 & 0 & 0 \\
0 & 1 & 1 \\
\end{bmatrix},
M_6 = \begin{bmatrix}
0 & 0 & 0 \\
0 & 0 & 1 \\
\end{bmatrix},
$$
求 $[A]_\beta$。
$Ans:$
令 $[A]_\beta=\begin{bmatrix} a\\b\\c\\d\\e\\f \end{bmatrix}$ ,則 $A=aM_1+bM_2+cM_3+dM_4+eM_5+fM_6$。
因此 $\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
\end{bmatrix}=\begin{bmatrix}
a & a+b & a+b+c\\
a+b+c+d & a+b+c+d+e & a+b+c+d+e+f &
\end{bmatrix}$。
可簡單解得 $a=b=c=d=e=f=1$,因此, $[A]_\beta=\begin{bmatrix} 1\\1\\1\\1\\1\\1 \end{bmatrix}$。
##### Exercise 4
以下例子說明一些向量空間的內積
其實就是某個表示法下的 $\mathbb{R}^n$ 標準內積。
(實際上所有有限維度空間中的內積
都可以寫成某個表示法下的 $\mathbb{R}^n$ 標準內積。
但證明須要用到一些對角化的工具。)
##### Exercise 4(a)
令 $\mathcal{M}_{m,n}$ 為所有 $m\times n$ 矩陣所形成的向量空間。
我們曾經驗證過 $\langle A, B\rangle = \operatorname{tr}(B^\top A)$ 是一種合法的內積。
說明其實 $\operatorname{tr}(B^\top A) = \langle [A]_\beta, [B]_\beta \rangle$﹐
其中 $\beta$ 是 $\mathcal{M}_{m,n}$ 的標準基底。
:::warning
- [x] 寫 $B\trans$ 就好,不用寫 $B^{\trans}$
:::
$Ans:$
令 $A = \begin{bmatrix}
| && |\\
\ba_1 & \cdots & \ba_n\\
| && |
\end{bmatrix},B \trans = \begin{bmatrix}- & \bb_1 & -\\
& \vdots &\\- & \bb_n & -
\end{bmatrix},B \trans A$ 的第 $i$ 列第 $j$ 行元素寫作 $(B\trans A)_{ij}$,
$A$ 的第 $i$ 列第 $j$ 行元素寫作 $a_{ij}$,$B \trans$ 的第 $i$ 列第 $j$ 行元素寫作 $b_{ij}$。
可以看出 $(B \trans A)_{ij} = \langle \bb_i,\ba_j \rangle$,所以
$$
\begin{aligned}
\operatorname{tr}(B \trans A) &= \langle \bb_1,\ba_1 \rangle + \cdots + \langle \bb_n,\ba_n \rangle\\
&= \sum_{j=1}^{n}\sum_{i=1}^{n}b_{ij}a_{ij}.
\end{aligned}
$$
因為 $[A]_\beta = (a_{11},\cdots,a_{mn}),[B]_\beta = (b_{11},\cdots,b_{mn})$,
$\langle [A]_\beta, [B]_\beta \rangle = \sum_{j=1}^{n}\sum_{i=1}^{n}b_{ij}a_{ij}$
所以 $\operatorname{tr}(B^{\trans}A) = \langle [A]_\beta, [B]_\beta \rangle$。
##### Exercise 4(b)
令 $\mathcal{P}_3$ 為所有次數小於等於 $3$ 的多項式所形成的向量空間。
我們曾經驗證過 $\langle p_1, p_2 \rangle = a_0b_0 + a_1b_1 + a_2b_2 + a_3b_3$ 是一種合法的內積﹐其中
$$\begin{aligned}
p_1 &= a_0 + a_1x + a_2x^2 + a_3x^3, \\
p_2 &= b_0 + b_1x + b_2x^2 + b_3x^3. \\
\end{aligned}
$$
說明其實 $\langle p_1, p_2 \rangle = \langle [p_1]_\beta, [p_2]_\beta \rangle$﹐
其中 $\beta$ 是 $\mathcal{P}_3$ 的標準基底。
:::warning
- [x] 標點
:::
$Ans:$
因為 $[p_1]_\beta = (a_0,a_1,a_2,a_3),[p_2]_\beta = (b_0,b_1,b_2,b_3)$,
所以
$$
\begin{aligned}
\langle [p_1]_\beta, [p_2]_\beta \rangle &= a_0b_0 + a_1b_1 + a_2b_2 + a_3b_3\\
&= \langle p_1, p_2 \rangle.
\end{aligned}
$$
##### Exercise 4(c)
令 $\mathcal{P}_3$ 為所有次數小於等於 $3$ 的多項式所形成的向量空間。
我們曾經驗證過 $\langle p_1, p_2 \rangle = p_1(1)p_2(1) + p_1(2)p_2(2) + p_1(3)p_2(3) + p_1(4)p_2(4)$ 是一種合法的內積。
令
$$\begin{aligned}
f_1(x) &= \frac{(x-2)(x-3)(x-4)}{(1-2)(1-3)(1-4)}, \\
f_2(x) &= \frac{(x-1)(x-3)(x-4)}{(2-1)(2-3)(2-4)}, \\
f_3(x) &= \frac{(x-1)(x-2)(x-4)}{(3-1)(3-2)(3-4)}, \\
f_4(x) &= \frac{(x-1)(x-2)(x-3)}{(4-1)(4-2)(4-3)}. \\
\end{aligned}
$$
說明其實 $\langle p_1, p_2 \rangle = \langle [p_1]_\beta, [p_2]_\beta \rangle$﹐
其中 $\beta = \{f_1, f_2, f_3, f_4\}$ 是 $\mathcal{P}_3$ 的一組基底。
$Ans:$
觀察可以知道 $\beta$ 是一組 Lagrange basis 對應到 $1,2,3,4$,因此
$$
[p]_\beta = (p(1),p(2),p(3),p(4))
$$
代入 $\langle [p_1]_\beta, [p_2]_\beta \rangle$,得
$$
\begin{aligned}
\langle [p_1]_\beta, [p_2]_\beta \rangle &=
p_1(1)p_2(1) + p_1(2)p_2(2) + p_1(3)p_2(3) + p_1(4)p_2(4)\\
&= \langle p_1, p_2 \rangle.
\end{aligned}
$$
:::info
目前分數 6.5
:::