# 基底轉換
Change of basis

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_good_matrix
```
## Main idea
Let $V$ be a vector space.
Let $\alpha = \{\bv_1, \ldots, \bv_n\}$ and $\beta = \{\bu_1, \ldots, \bu_n\}$ be two bases of $V$.
Each vector $\bb$ can have different representations $[\bb]_\alpha$ and $[\bb]_\beta$ depending on the bases used.
Let $[\idmap]_\alpha^\beta$ be the $n \times n$ matrix
$$
\begin{bmatrix}
| & ~ & | \\
[\bv_1]_\beta & \cdots & [\bv_n]_\beta \\
| & ~ & | \\
\end{bmatrix}.
$$
Then $[\idmap]_\alpha^\beta [\bb]_\alpha = [\bb]_\beta$ for any $\bb\in V$.
Therefore, we call $[\idmap]_\alpha^\beta$ the **change of basis matrix** from $\alpha$ to $\beta$.
(The notation $[\idmap]_\alpha^\beta$ means it is an identity map from $V$ to $V$ but we are observing the domain and the codomain from the points of view of $\alpha$ and $\beta$.
This notation will be more clear when we introduce the matrix representation of a linear function.)
The change of basis matrix $[\idmap]_\alpha^\beta$ can be viewed as a function taking the representation in $\alpha$ and output the representation in $\beta$.
Therefore, if we have another basis $\gamma$, then we have
- $[\idmap]_\alpha^\alpha = I_n$,
- $[\idmap]_\beta^\gamma[\idmap]_\alpha^\beta = [\idmap]_\alpha^\gamma$,
- $[\idmap]_\beta^\alpha[\idmap]_\alpha^\beta = I_n$.
Note that a matrix takes its input vector from the right, so we should read a product of matrices from right to left.
## Side stories
- inverse of a change of basis matrix
## Experiments
##### Exercise 1
執行以下程式碼。
<!-- eng start -->
Run the code below.
<!-- eng end -->
```python
### code
set_random_seed(0)
print_ans = False
A = random_good_matrix(3,3,3, bound=3)
B = random_good_matrix(3,3,3, bound=3)
e1,e2,e3 = identity_matrix(3).transpose()
u1,u2,u3 = A.transpose()
v1,v2,v3 = B.transpose()
print("alpha has three vectors:")
print("e1 =", e1)
print("e2 =", e2)
print("e3 =", e3)
print("beta has three vectors:")
print("u1 =", u1)
print("u2 =", u2)
print("u3 =", u3)
print("gamma has three vectors:")
print("v1 =", v1)
print("v2 =", v2)
print("v3 =", v3)
if print_ans:
print("[id]_alpha^beta =")
show(A.inverse())
print("[id]_beta^alpha =")
show(A)
print("[id]_beta^gamma =")
show(B.inverse() * A)
print("[id]_alpha^gamma =")
show(B.inverse())
```
:::warning
- [x] Missing period.
:::
By setting `seed = 0` , we get
$$\alpha = \{
\begin{bmatrix} 1 \\ 0 \\ 0 \\\end{bmatrix},
\begin{bmatrix} 0 \\ 1 \\ 0 \\\end{bmatrix},
\begin{bmatrix} 0 \\ 0 \\ 1 \\\end{bmatrix}
\}
$$
,
$$\beta = \{
\begin{bmatrix} 1 \\-3 \\ 0 \\\end{bmatrix},
\begin{bmatrix} 3 \\-8 \\-1 \\\end{bmatrix},
\begin{bmatrix} 1 \\-1 \\-1 \\\end{bmatrix}
\}
$$
and
$$\gamma = \{
\begin{bmatrix} 1 \\-3 \\-2 \\\end{bmatrix},
\begin{bmatrix} 1 \\-2 \\-2 \\\end{bmatrix},
\begin{bmatrix} 2 \\-5 \\-3 \\\end{bmatrix}
\}.
$$
##### Exercise 1(a)
計算 $[\idmap]_\alpha^\beta$ 及 $[\idmap]_\beta^\alpha$,
並確認 $[\idmap]_\beta^\alpha [\idmap]_\alpha^\beta = I_3$。
<!-- eng start -->
Find $[\idmap]_\alpha^\beta$ and $[\idmap]_\beta^\alpha$. Then verify $[\idmap]_\beta^\alpha [\idmap]_\alpha^\beta = I_3$.
<!-- eng end -->
:::warning
- [x] Make your notation consistent: $\bc_i$ --> $c_i$
:::
Answer:
$$
[\idmap]_\beta^\alpha =
\left[
\begin{array}{ccc}
1 & 3 & 1 \\
-3 & -8 & -1 \\
0 & -1 & -1 \\
\end{array}
\right].
$$
Let $\alpha = \{\be_1, \be_2, \be_3\}$ , $\beta = \{\bv_1, \bv_2, \bv_3\}$ and $\be_1 = c_1\bv_1 + c_2\bv_2 + c_3\bv_3$ , $c_1,c_2,c_3 \in \mathbb R$.
The vector representation of $\be_1$ is $\begin{bmatrix} c_1 \\c_2 \\ c_3 \\\end{bmatrix}$
with respect to $\beta$,
so we know
$\begin{bmatrix} c_1 \\c_2 \\ c_3 \\\end{bmatrix}$
is the first column of $[\idmap]_\alpha^\beta$.
By solving $$
\left[
\begin{array}{ccc}
1 & 3 & 1 \\
-3 & -8 & -1 \\
0 & -1 & -1 \\
\end{array}
\right]
\begin{bmatrix}
c_1 \\c_2 \\ c_3 \\
\end{bmatrix} =
\begin{bmatrix}
1 \\0 \\ 0 \\
\end{bmatrix},$$
we get
$$\begin{bmatrix}
c_1 \\c_2 \\ c_3 \\
\end{bmatrix} =
\begin{bmatrix}
7 \\-3 \\ 3 \\
\end{bmatrix}.$$
Repeat the above steps and replace $\be_1$ with $\be_2$ and $\be_3$, we know $$
[\idmap]_\alpha^\beta =
\left[
\begin{array}{ccc}
7 & 2 & 5 \\
-3 & -1 & -2 \\
3 & 1 & 1 \\
\end{array}
\right].$$
Finally, $$
\left[
\begin{array}{ccc}
1 & 3 & 1 \\
-3 & -8 & -1 \\
0 & -1 & -1 \\
\end{array}
\right]
\left[
\begin{array}{ccc}
7 & 2 & 5 \\
-3 & -1 & -2 \\
3 & 1 & 1 \\
\end{array}
\right] =
I_3.
$$
##### Exercise 1(b)
計算 $[\idmap]_\beta^\gamma$ 及 $[\idmap]_\alpha^\gamma$,
並確認 $[\idmap]_\beta^\gamma [\idmap]_\alpha^\beta = [\idmap]_\alpha^\gamma$。
<!-- eng start -->
Find $[\idmap]_\beta^\gamma$ and $[\idmap]_\alpha^\gamma$. Then verify $[\idmap]_\beta^\gamma [\idmap]_\alpha^\beta = [\idmap]_\alpha^\gamma$.
<!-- eng end -->
:::warning
- [x] Make your notation consistent: $\bc_i$ --> $c_i$
:::
Answer:
Let $\beta = \{\bv_1, \bv_2, \bv_3\}$ , $\gamma = \{\bu_1, \bu_2, \bu_3\}$ and $\bv_1 = c_1\bu_1 + c_2\bu_2 + c_3\bu_3$ , $c_1,c_2,c_3 \in \mathbb R$.
The vector representation of $\bv_1$ is $\begin{bmatrix} c_1 \\c_2 \\ c_3 \\\end{bmatrix}$
with respect to $\gamma$,
so we know
$\begin{bmatrix} c_1 \\c_2 \\ c_3 \\\end{bmatrix}$
is the first column of $[\idmap]_\beta^\gamma$.
By solving $$
\left[
\begin{array}{ccc}
1 & 1 & 2 \\
-3 & -2 & -5 \\
-2 & -2 & -3 \\
\end{array}
\right]
\begin{bmatrix}
c_1 \\c_2 \\ c_3 \\
\end{bmatrix} =
\begin{bmatrix}
1 \\-3 \\ 0 \\
\end{bmatrix},$$
we get
$$\begin{bmatrix}
c_1 \\c_2 \\ c_3 \\
\end{bmatrix} =
\begin{bmatrix}
-1 \\-2 \\ 2 \\
\end{bmatrix}.$$
Repeat the above steps and replace $\bv_1$ with $\bv_2$ and $\bv_3$, we know $$
[\idmap]_\beta^\gamma =
\left[
\begin{array}{ccc}
-1 & -3 & -2 \\
-2 & -4 & 1 \\
2 & 5 & 1 \\
\end{array}
\right].$$
Using the same method, we get $$ [\idmap]_\alpha^\gamma =
\left[
\begin{array}{ccc}
-4 & -1 & -1 \\
1 & 1 & -1 \\
2 & 0 & 1 \\
\end{array}
\right].$$
Finally, $$
[\idmap]_\beta^\gamma [\idmap]_\alpha^\beta =
\left[
\begin{array}{ccc}
-1 & -3 & -2 \\
-2 & -4 & 1 \\
2 & 5 & 1 \\
\end{array}
\right]
\left[
\begin{array}{ccc}
7 & 2 & 5 \\
-3 & -1 & -2 \\
3 & 1 & 1 \\
\end{array}
\right] =
\left[
\begin{array}{ccc}
-4 & -1 & -1 \\
1 & 1 & -1 \\
2 & 0 & 1 \\
\end{array}
\right] =
[\idmap]_\alpha^\gamma.
$$
## Exercises
##### Exercise 2
對於以下的各向量空間 $V$、
以及兩個基底 $\alpha$ 和 $\beta$﹐
求出 $[\idmap]_\alpha^\beta$ 和 $[\idmap]_\beta^\alpha$。
<!-- eng start -->
For each of the following vector space $V$ and two bases $\alpha$ and $\beta$, find $[\idmap]_\alpha^\beta$ and $[\idmap]_\beta^\alpha$.
<!-- eng end -->
##### Exercise 2(a)
令 $V = \mathbb{R}^3$、
$\alpha = \{\be_1, \be_2, \be_3\}$ 為標準基底、
$$
\beta = \left\{\begin{aligned}
\bu_1 = (0,0,1), \\
\bu_2 = (0,1,1), \\
\bu_3 = (1,1,1)
\end{aligned}\right\}.
$$
<!-- eng start -->
Let $V = \mathbb{R}^3$, $\alpha = \{\be_1, \be_2, \be_3\}$ be the standard basis, and
$$
\beta = \left\{\begin{aligned}
\bu_1 = (0,0,1), \\
\bu_2 = (0,1,1), \\
\bu_3 = (1,1,1)
\end{aligned}\right\}.
$$
<!-- eng end -->
:::warning
- [x] Make your notation consistent: $\bc_i$ --> $c_i$
:::
$Ans:$
$$[\operatorname{id}]_\beta^\alpha =\left[
\begin{array}{ccc}
0 & 0 & 1 \\
0 & 1 & 1 \\
1 & 1 & 1 \\
\end{array}
\right].
$$
Let $\alpha = \{\be_1, \be_2, \be_3\}$ , $\beta = \{\bu_1, \bu_2, \bu_3\}$ and $\be_1 = c_1\bu_1 + c_2\bu_2 + c_3\bu_3$ , $c_1,c_2,c_3 \in \mathbb R$.
The vector representation of $\be_1$ is $\begin{bmatrix} c_1 \\c_2 \\ c_3 \\\end{bmatrix}$
with respect to $\beta$,
so we know
$\begin{bmatrix} c_1 \\c_2 \\ c_3 \\\end{bmatrix}$
is the first column of $[\idmap]_\alpha^\beta$.
By solving $$
\left[
\begin{array}{ccc}
0 & 0 & 1 \\
0 & 1 & 1 \\
1 & 1 & 1 \\
\end{array}
\right]
\begin{bmatrix}
c_1 \\c_2 \\ c_3 \\
\end{bmatrix} =
\begin{bmatrix}
1 \\0 \\ 0 \\
\end{bmatrix},$$
we get
$$\begin{bmatrix}
c_1 \\c_2 \\ c_3 \\
\end{bmatrix} =
\begin{bmatrix}
0 \\-1 \\ 1 \\
\end{bmatrix}.$$
Repeat the above steps and replace $\be_1$ with $\be_2$ and $\be_3$, we know $$
[\idmap]_\alpha^\beta =
\left[
\begin{array}{ccc}
0 & -1 & 1 \\
-1 & 1 & 0 \\
1 & 0 & 0 \\
\end{array}
\right].
$$
##### Exercise 2(b)
令 $V = \mathbb{R}^3$、
$\alpha = \{\be_1, \be_2, \be_3\}$ 為標準基底、
$$
\beta = \left\{\begin{aligned}
\bu_1 = (\frac{1}{\sqrt{3}}, \frac{1}{\sqrt{3}}, \frac{1}{\sqrt{3}}), \\
\bu_2 = (\frac{1}{\sqrt{2}},-\frac{1}{\sqrt{2}},0), \\
\bu_3 = (\frac{1}{\sqrt{6}},\frac{1}{\sqrt{6}},-\frac{2}{\sqrt{6}})
\end{aligned}\right\}.
$$
<!-- eng start -->
Let $V = \mathbb{R}^3$, $\alpha = \{\be_1, \be_2, \be_3\}$ be the standard basis, and
$$
\beta = \left\{\begin{aligned}
\bu_1 = (\frac{1}{\sqrt{3}}, \frac{1}{\sqrt{3}}, \frac{1}{\sqrt{3}}), \\
\bu_2 = (\frac{1}{\sqrt{2}},-\frac{1}{\sqrt{2}},0), \\
\bu_3 = (\frac{1}{\sqrt{6}},\frac{1}{\sqrt{6}},-\frac{2}{\sqrt{6}})
\end{aligned}\right\}.
$$
<!-- eng end -->
:::warning
- [x] Make your notation consistent: $\bc_i$ --> $c_i$
Note that the matrix in your answer is an orthogonal matrix, so its inverse is the same as its transpose.
:::
$Ans:$
$$[\operatorname{id}]_\beta^\alpha =\left[
\begin{array}{ccc}
\frac{1}{\sqrt{3}} & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{6}} \\
\frac{1}{\sqrt{3}} & -\frac{1}{\sqrt{2}} & \frac{1}{\sqrt{6}} \\
\frac{1}{\sqrt{3}} & 0 & -\frac{2}{\sqrt{6}} \\
\end{array}
\right].$$
Let $\alpha = \{\be_1, \be_2, \be_3\}$ , $\beta = \{\bu_1, \bu_2, \bu_3\}$ and $\be_1 = c_1\bu_1 + c_2\bu_2 + c_3\bu_3$ , $c_1,c_2,c_3 \in \mathbb R$.
The vector representation of $\be_1$ is $\begin{bmatrix} c_1 \\c_2 \\ c_3 \\\end{bmatrix}$
with respect to $\beta$,
so we know
$\begin{bmatrix} c_1 \\c_2 \\ c_3 \\\end{bmatrix}$
is the first column of $[\idmap]_\alpha^\beta$.
By solving $$
\left[
\begin{array}{ccc}
\frac{1}{\sqrt{3}} & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{6}} \\
\frac{1}{\sqrt{3}} & -\frac{1}{\sqrt{2}} & \frac{1}{\sqrt{6}} \\
\frac{1}{\sqrt{3}} & 0 & -\frac{2}{\sqrt{6}} \\
\end{array}
\right]
\begin{bmatrix}
c_1 \\c_2 \\ c_3 \\
\end{bmatrix} =
\begin{bmatrix}
1 \\0 \\ 0 \\
\end{bmatrix},$$
we get
$$\begin{bmatrix}
c_1 \\c_2 \\ c_3 \\
\end{bmatrix} =
\begin{bmatrix}
\frac{1}{\sqrt{3}} \\\frac{1}{\sqrt{2}} \\ -\frac{1}{\sqrt{6}} \\
\end{bmatrix}.$$
Repeat the above steps and replace $\be_1$ with $\be_2$ and $\be_3$, we know $$
[\idmap]_\alpha^\beta =
\left[
\begin{array}{ccc}
\frac{1}{\sqrt{3}} & \frac{1}{\sqrt{3}} & \frac{1}{\sqrt{3}} \\
\frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} & 0 \\
\frac{1}{\sqrt{6}} & \frac{1}{\sqrt{6}} & -\frac{2}{\sqrt{6}} \\
\end{array}
\right].
$$
##### Exercise 2(c)
令 $V = \mathcal{P}_2$、
$\alpha = \{1, x, x^2\}$ 為標準基底、
$\beta = \{1, 1-x, (1-x)^2\}$。
<!-- eng start -->
Let $V = \mathcal{P}_2$, $\alpha = \{1, x, x^2\}$ be the standard basis, and $\beta = \{1, 1-x, (1-x)^2\}$.
<!-- eng end -->
:::warning
- [x] Space after any punctuation mark.
- [x] Typo: vectoers
Technically, $\beta$ does not contain any vectors in $\mathbb{R}^2$.
:::
**Answer**
Since the vector representation of a polynomial with respect to the standard basis $\alpha$ is simply recording the coefficients, we have
$$
[\operatorname{id}]_\beta^\alpha =\left[
\begin{array}{ccc}
1 & 1 & 1 \\
0 & -1 & -2 \\
0 & 0 & 1 \\
\end{array}
\right].
$$
Then, we may compute
$$
[\operatorname{id}]_\alpha^\beta =
([\idmap]_\beta^\alpha)^{-1} =
\begin{bmatrix}
1 & 1 & 1 \\
0 & -1 & -2 \\
0 & 0 & 1 \\
\end{bmatrix}.
$$
<!-- Let the vectors in $\beta$ be $\bu_1 , \bu_2 , \bu_3$, then the vector $(1 , 0 , 0)$ expressed by $\alpha$ notation can be written to $c_1\bu_1 + c_2\bu_2 + c_3\bu_3$, $c_1,c_2,c_3 \in \mathbb R$.
Thus, $c_1,c_2,c_3$ is the first row of $[\operatorname{id}]_\alpha^\beta$ that we want to evaluate . In the same way , we can substitute
$(0 , 1 , 0),(0 , 0 , 1)$ to evaluate the second and the third row.
We get
$$[\operatorname{id}]_\alpha^\beta =\left[
\begin{array}{ccc}
1 & 1 & 1 \\
0 & -1 & -2 \\
0 & 0 & 1 \\
\end{array}
\right].
$$ -->
##### 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}
$$
令 $V = \mathcal{P}_2$、
$\alpha = \{1, x, x^2\}$ 為標準基底、
$\beta = \{p_1, p_2, p_3\}$。
<!-- eng start -->
Let
$$
\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}
$$
Let $V = \mathcal{P}_2$, $\alpha = \{1, x, x^2\}$ be the standard basis, and $\beta = \{p_1, p_2, p_3\}$.
<!-- eng end -->
##### Exercise 3
說明以下三個等式的直觀解釋:
- $[\idmap]_\alpha^\alpha = I_n$,
- $[\idmap]_\beta^\gamma[\idmap]_\alpha^\beta = [\idmap]_\alpha^\gamma$,
- $[\idmap]_\beta^\alpha[\idmap]_\alpha^\beta = I_n$.
<!-- eng start -->
Give some intuition to the following identities:
- $[\idmap]_\alpha^\alpha = I_n$,
- $[\idmap]_\beta^\gamma[\idmap]_\alpha^\beta = [\idmap]_\alpha^\gamma$,
- $[\idmap]_\beta^\alpha[\idmap]_\alpha^\beta = I_n$.
<!-- eng end -->
##### Exercise 4
我們已經看到每個基底轉換矩陣 $[\idmap]_\alpha^\beta$ 都是可逆的﹐而且其逆矩陣就是 $[\idmap]_\beta^\alpha$。
證明每個 $n\times n$ 的可逆矩陣也可以寫成 $\mathbb{R}^n$ 中的兩組基底 $\alpha$ 和 $\beta$ 所建構出來的基底轉移矩陣。
(把 $\alpha$ 取為 $A$ 的各行向量、
$\beta$ 取為標準基底。)
<!-- eng start -->
We have seen that every change of basis matrix $[\idmap]_\alpha^\beta$ is invertible and its inverse is $[\idmap]_\beta^\alpha$. Show that every $n\times n$ matrix can be written as the change of basis matrix in $\mathbb{R}^n$ for some basis $\alpha$ and $\beta$.
Hint: You may choose $\alpha$ as the columns of $A$ and $\beta$ as the standard basis of $\mathbb{R}^n$.
<!-- eng end -->
:::info
collaboration: 2
3 problems: 3
- done: 2a, 2b, 2c
extra: 1
moderator: 1
quality control: 1
:::