# $\mathbb{R}^n$ 中的仿射子空間
Affine subspaces in $\mathbb{R}^n$

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, draw_span
```
## Main idea
An **affine subspace** in $\mathbb{R}^n$ is a subset of $\mathbb{R}^n$ of the form
$$\bp + V = \{\bp + \bv: \bv \in V\},
$$
where $\bp$ is a vector and $V$ is a subspace in $\mathbb{R}^n$.
An affine subspace is a subspace if and only if it contains the origin $\bzero$.
Let $U$ be an affine subspace in $\mathbb{R}^n$.
Then $U = \bp + V$ for some vector $\bp$ and some subspace if and only if
$\bp$ is a vector in $U$ and $V = \{\bp_1 - \bp_2: \bp_1,\bp_2\in U\}$.
## Side stories
- element + set
- choice of the representative
## Experiments
##### Exercise 1
執行下方程式碼。
原點為橘色點、$\bp$ 為橘色向量、
從 $\bp$ 的終點延伸出去的紅色向量和淡藍色向量分別為 $\bu_1$ 和 $\bu_2$。
黑色向量為 $\bb$。
問 $\bb$ 是否是落在 $\bp + \vspan(\{\bu_1, \bu_2\})$?
若是,求 $c_1,c_2$ 使得 $\bb = \bp + c_1\bu_1 + c_2\bu_2$。
<!-- eng start -->
Run the code below. Let the origin be the orange point and $\bp$ the orange vector. Let $\bu_1$ and $\bu_2$ be the red and lightblue vectors whose tails at $\bp$. Is $\bb$ in $\bp + \vspan(\{\bu_1, \bu_2\})$? If yes, find $c_1$ and $c_2$ so that $\bb = \bp + c_1\bu_1 + c_2\bu_2$.
<!-- eng end -->
```python
### code
set_random_seed(0)
print_ans = False
while True:
l = random_int_list(9)
A = matrix(3, l)
if A.det() != 0:
break
u1 = vector(A[0])
u2 = vector(A[1])
u3 = vector(A[2])
p = vector(random_int_list(3))
inside = choice([0,1,1])
coefs = random_int_list(2, 2)
if inside:
b = p + coefs[0]*u1 + coefs[1]*u2
else:
b = p + coefs[0]*u1 + coefs[1]*u2 + 3*u3
print("p =", p)
print("u1 =", u1)
print("u2 =", u2)
print("b =", b)
pic = draw_span([u1,u2], p)
pic += arrow((0,0,0), b, width=5, color="black")
show(pic)
if print_ans:
if inside:
print("b is on Col(A) since b = %s u1 + %s u2."%(coefs[0], coefs[1]))
else:
print("b is not on Col(A).")
```
:::info
Paste the result of the program here.
:::
**Answer**
## Exercises
##### Exercise 2
若 $S$ 為一實數的集合、$p$ 為一實數。
我們定義 $p + S = \{p + s: s\in S\}$。
<!-- eng start -->
Let $S$ be a subset in $\mathbb{R}$ and $p$ a real number. Define $p + S = \{p + s: s\in S\}$.
<!-- eng end -->
##### Exercise 2(a)
執行以下程式碼。
算出 $p + S$。
<!-- eng start -->
Run the code below. Find $p + S$.
<!-- eng end -->
```python
### code
set_random_seed(0)
print_ans = False
nums = list(range(-20,21))
p = choice(nums)
while True:
S = [choice(nums) for _ in range(5)]
if len(set(S)) == len(S):
break
print("p =", p)
print("S =", S)
if print_ans:
print("p + S =", [p + s for s in S])
```
##### Exercise 2(b)
令 $3\mathbb{Z} = \{3k: k \in \mathbb{Z}\}$。
寫出 $1 + 3\mathbb{Z}$ 和 $-2 + 3\mathbb{Z}$﹐
並觀察它兩者是否一樣。
:::warning
- [x] Put the period in the end of math, not at the beginning of a new line.
- [x] $! =$ --> $\neq$
- [ ] This is an exercise that you need to prove $A\subseteq B$ and $B\subseteq A$. See [here](https://hackmd.io/@jephianlin/eng-in-math#%E7%B7%B4%E7%BF%92) for an example.
:::
According to the definition $$s+ \mathbb{P}=\{s+p: p
\in \mathbb{P}\}.$$
Therfore, we can realize that if $$3\mathbb{Z}= \{3k: k \in \mathbb{Z}\},$$
then $$1 + 3\mathbb{Z}= \{1+3k: k \in \mathbb{Z}\}$$ and $$-2 + 3\mathbb{Z}= \{-2+3k: k \in \mathbb{Z}\}.$$
<!-- Beacause $$1 + 3\mathbb{Z} \subseteq \mathbb{Z}$$
$$-2 + 3\mathbb{Z} \subseteq \mathbb{Z}$$
and $$-2 + 3\mathbb{Z} \subseteq \mathbb{Z}$$
$$1 + 3\mathbb{Z} \subseteq \mathbb{Z},$$ -->
Now we claim that
$$1 + 3\mathbb{Z} \subseteq -2 + 3\mathbb{Z}.$$
Suppose$$ x \in 1+3\mathbb{Z},$$
according to the definition we assume that
$$x = 1+3k, k \in \mathbb{Z}.$$
Thus, we observe the equation $x = 1+3k = -2+3+3k,$
and we rewrite the equation $$x = -2+3(k+1), k+1 \in \mathbb{Z}.$$
Then we found that $$ x \in -2+3\mathbb{Z},$$
it is enough for us to show that $$1 + 3\mathbb{Z} \subseteq -2 + 3\mathbb{Z}$$ $$-2 + 3\mathbb{Z} \subseteq 1 + 3\mathbb{Z}.$$
Therefore $$1 + 3\mathbb{Z} = -2 + 3\mathbb{Z}.
$$
<!-- eng start -->
Let $3\mathbb{Z} = \{3k: k \in \mathbb{Z}\}$. Examine the sets $1 + 3\mathbb{Z}$ and $-2 + 3\mathbb{Z}$ and check if they are the same.
<!-- eng end -->
##### Exercise 2(c)
若 $U = 1 + 3\mathbb{Z}$。
說明 $\{p_1 - p_2: p_1, p_2 \in U\} = 3\mathbb{Z}$。
<!-- eng start -->
Let $U = 1 + 3\mathbb{Z}$. Show that $\{p_1 - p_2: p_1, p_2 \in U\} = 3\mathbb{Z}$.
<!-- eng end -->
-------------------------------------------------
:::warning
- [x] Therefore, ... $\subseteq 3\mathbb{Z}$.
:::
Answer for Exercise 2(c):
It's given that $U = 1 + 3\mathbb{Z}$. \
And in order to prove that $\{p_1 - p_2: p_1, p_2 \in U\} = 3\mathbb{Z}$, it is sufficient to show that $\{p_1 - p_2: p_1, p_2\in U\} \subseteq 3\mathbb{Z}$ and $\{p_1 - p_2: p_1, p_2\in U\} \supseteq 3\mathbb{Z}$.
Let $p_1, p_2\in 1 + 3\mathbb{Z}$.
Thus, we may assume $p_1 = 1+3s$ and $p_2 = 1+3t$ for some $s,t\in\mathbb{Z}$.
We can get that $(1+3s) - (1+3t) = 3(s-t) \in 3\mathbb{Z}$.
Therefore, $\{p_1 - p_2: p_1, p_2\in U\} \subseteq 3\mathbb{Z}$.
On the other hand: \
Let $3k\in 3\mathbb{Z}$, $k\in\mathbb{Z}$.
We may pick $p_1 = 1+3k$, $p_2 = 1$, $p_1,p_2\in U$.
We can get that $3k = p_1 - p_2 \in \{p_1 - p_2: p_1, p_2\in U\}$.
Therefore, $\{p_1 - p_2: p_1, p_2\in U\} \supseteq 3\mathbb{Z}$.
And since $\{p_1 - p_2: p_1, p_2\in U\} \subseteq 3\mathbb{Z}$ and $\{p_1 - p_2: p_1, p_2\in U\} \supseteq 3\mathbb{Z}$, \
we can prove that $\{p_1 - p_2: p_1, p_2 \in U\} = 3\mathbb{Z}$.
-------------------------------------------------
##### Exercise 3
令 $U = \left\{\begin{bmatrix}x\\y\\z\end{bmatrix} : x + y + z = 3\right\}$。
<!-- eng start -->
Let $U = \left\{\begin{bmatrix}x\\y\\z\end{bmatrix} : x + y + z = 3\right\}$.
<!-- eng end -->
##### Exercise 3(a)
找一群 $\mathbb{R}^3$ 中的向量 $\bp$、$\bu_1$、$\bu_2$﹐
使得 $U = \bp + \vspan(\{\bu_1, \bu_2\})$。
<!-- eng start -->
Find some vectors $\bp$, $\bu_1$, and $\bu_2$ such that $U = \bp + \vspan(\{\bu_1, \bu_2\})$.
<!-- eng end -->
##### Exercise 3(b)
驗證 $V = \{\bp_1 - \bp_2 : \bp_1,\bp_2 \in U\}$ 是一個子空間
(它非空、對純量乘法和向量加法有封閉性)。
因此 $U$ 可以寫成 $U = \bp + V$,
其中 $\bp$ 可以取為 $U$ 中的任一向量。
<!-- eng start -->
Show that $V = \{\bp_1 - \bp_2 : \bp_1,\bp_2 \in U\}$ is a subspace. (That is, verify it is an non-empty set closed under scalar multiplication and addition.) Therefore, $U$ can be written as $U = \bp + V$, where $\bp$ can be any vector in $U$.
<!-- eng end -->
##### Exercise 3(c)
證明任一個超平面
$$
\{ \bv\in\mathbb{R}^n : \inp{\br}{\bv} = b \}
$$
(其中 $\br\in\mathbb{R}^n$、$b\in\mathbb{R}$)
都是一個仿射子空間。
而且 $\bp$ 和 $V = \{\bp_1 - \bp_2 : \bp_1,\bp_2 \in U\}$ 中的所有向量垂直﹐
因此它是 $U$ 的法向量。
<!-- eng start -->
Show that any hyperplane
$$
\{ \bv\in\mathbb{R}^n : \inp{\br}{\bv} = b \},
$$
where $\br\in\mathbb{R}^n$ and $b\in\mathbb{R}$, is an affine subspace. Moreover, $\bp$ is orthogonal to any vector in $V = \{\bp_1 - \bp_2 : \bp_1,\bp_2 \in U\}$. Therefore, $\bp$ is the normal vector of $U$.
<!-- eng end -->
##### Exercise 4
令 $U = \left\{\begin{bmatrix}x\\y\\z\\w\end{bmatrix} :
\begin{array}{ccccc}
x & +y & & +w & = 3 \\
& & z & +w & = 2 \\
\end{array}\right\}$。
找一群 $\mathbb{R}^4$ 中的向量 $\bp$、$\bu_1$、$\bu_2$﹐
使得 $U = \bp + \vspan(\{\bu_1, \bu_2\})$。
(因此這組方程式的解形成一個仿射子空間。)
<!-- eng start -->
Let $U = \left\{\begin{bmatrix}x\\y\\z\\w\end{bmatrix} :
\begin{array}{ccccc}
x & +y & & +w & = 3 \\
& & z & +w & = 2 \\
\end{array}\right\}$. Find some vectors $\bp$, $\bu_1$, and $\bu_2$ in $\mathbb{R}^4$ so that $U = \bp + \vspan(\{\bu_1, \bu_2\})$. (Therefore, the solution set of this system of linear equations is an affine subspace.)
<!-- eng end -->
##### Exercise 5
令 $U$ 為 $\mathbb{R}^n$ 中的仿射子空間。
<!-- eng start -->
Let $U$ be an affine subspace in $\mathbb{R}^n$.
<!-- eng end -->
##### Exercise 5(a)
若 $V$ 為 $\mathbb{R}^n$ 中的一子空間、
$\bp_1$ 和 $\bp_2$ 為 $\mathbb{R}^n$ 中的向量。
證明以下敘述等價:
1. $\bp_1 + V = \bp_2 + V$.
2. $\bp_1 - \bp_2 \in V$.
<!-- eng start -->
Let $V$ be a subspace in $\mathbb{R}^n$. Let $\bp_1$ and $\bp_2$ be vectors in $\mathbb{R}^n$. Show that the following are equivalent:
1. $\bp_1 + V = \bp_2 + V$.
2. $\bp_1 - \bp_2 \in V$.
<!-- eng end -->
##### Exercise 5(b)
若 $U$ 可以寫為 $\bp + V$,
其中 $\bp\in\mathbb{R}^n$ 且 $V$ 為 $\mathbb{R}^n$ 中的一子空間。
證明 $V = \{\bp_1 - \bp_2 : \bp_1,\bp_2 \in U\}$
且 $\bp$ 可以選為 $U$ 中的任一元素。
<!-- eng start -->
Suppose $U$ can be written as $\bp + V$, where $\bp\in\mathbb{R}^n$ and $V$ a subspace in $\mathbb{R}^n$. Show that $V = \{\bp_1 - \bp_2 : \bp_1,\bp_2 \in U\}$. Also, $\bp$ can be chosen as any vector in $U$.
<!-- eng end -->
:::info
林: 5
黃: 4.5
:::