Chapter 3 · Foundation第 3 章 · 基礎

Matrix Transformation Lab矩陣即線性變換

A matrix is a function: it sends every vector to a new vector. Watch the whole grid move, read where e₁ and e₂ land, and let the determinant tell you about area and flips.矩陣是一個函數:把每個向量送到新的向量。看整張方格網怎麼變形、讀出 e₁ 和 e₂ 被送到哪裡,再讓行列式(determinant)告訴你面積和翻面的事。

First experiment先做這三步
  1. Press Reset and check that A=I=[1 0; 0 1]: the grid stays put, blue e₁ points to (1,0) and green e₂ to (0,1).按「重設」,確認 A=I=[1 0; 0 1]:方格不動,藍色 e₁ 指向 (1,0),綠色 e₂ 指向 (0,1)。
  2. Predict first: after changing the top-right entry b from 0 to 1, where do e₁ and e₂ go? Record your prediction, then change b.先預測:把右上角 b 從 0 改成 1 之後,e₁ 和 e₂ 各會被送到哪裡?記錄預測後再改 b。
  3. Check the calculation: the image of v=(2,1) is Av=2·(1,0)+1·(1,1)=(3,1). Find the tip of the red arrow, then see why the grid leans: e₂ now goes to (1,1).核對算式:v=(2,1) 的像 Av=2·(1,0)+1·(1,1)=(3,1)。在圖上找到紅色箭頭的終點,再看看方格為什麼變斜:e₂ 被送到 (1,1)。

Predict → change one value → inspect the calculation → read the key idea.先預測 → 改一個值 → 檢查算式 → 看懂重點概念。

A matrix is a function: vector in, vector out.矩陣是一個函數:輸入向量,輸出向量。

The 2×2 matrix A sends each vector v=(x,y) to Av. Instead of moving one arrow, look at the whole grid at once: every grid line moves together.2×2 矩陣 A 把每個向量 v=(x,y) 送到 Av。不要只看一支箭頭,一次看整張方格網:所有格線會一起移動。

Predict, then set the matrix先預測,再設定矩陣
A =
[a b; c d]

Blue frame: column 1 (a,c). Green frame: column 2 (b,d). Entries from −5 to 5; fractions such as 1/2 are accepted.藍框是第 1 欄 (a,c),綠框是第 2 欄 (b,d)。元素範圍 −5 到 5,可輸入分數(例如 1/2)。

The grid before and after變形前後的方格網

Pale grey: the original grid. Pale blue: the image of every grid line. The shaded parallelogram is the image of the unit square; the small flag shows whether the plane has been flipped.淡灰色是原本的方格;淺藍色是每條格線的像。上色的平行四邊形是單位正方形的像;小旗子用來看平面有沒有翻面。

Why does the origin never move?為什麼原點永遠不動?
A(0,0) = (a·0+b·0, c·0+d·0) = (0,0).

This holds for every matrix A, not only the ones you try. Grid lines also stay straight, parallel and evenly spaced, because A(u+v)=Au+Av and A(cv)=c·Av.這對每一個矩陣 A 都成立,不只是你試過的例子。格線也一直保持直線、平行、等距,因為 A(u+v)=Au+Av、A(cv)=c·Av。

Two ways to read AvAv 的兩種讀法
Av = (a·x + b·y, c·x + d·y) = x·(a, c) + y·(b, d).
Row view: each output coordinate uses one row. Column view: Av is a linear combination of the two columns, exactly like au+bv in Chapter 1.列的讀法:每個輸出座標用一列(row)。欄的讀法:Av 是兩欄(column)的線性組合,和第 1 章的 au+bv 一模一樣。
Explore first; the next section explains why the columns decide everything.先動手探索;下一節說明為什麼兩欄就決定了一切。
Drag a tip, change a column拖箭頭就是改一欄Drag the blue tip first and watch a and c change together; then drag the green tip and watch b and d. In the challenge you may drag the tips or type the matrix. Remember: a row runs across, a column runs down.先拖藍色箭頭,看 a、c 兩格一起變;再拖綠色箭頭,看 b、d 一起變。挑戰中可以拖箭頭,也可以直接輸入矩陣。記得:列(row)是橫的,欄(column)是直的。

Ae₁ is column 1; Ae₂ is column 2.Ae₁ 是第 1 欄,Ae₂ 是第 2 欄。

The standard basis vectors are e₁=(1,0) and e₂=(0,1). Every vector is a combination of them, so once you know where they land, you know where everything lands.標準基底(standard basis)是 e₁=(1,0) 和 e₂=(0,1)。每個向量都是它們的組合,所以只要知道它們被送到哪裡,就知道所有向量被送到哪裡。

From the definition從定義出發
A e₁ = A(1,0) = (a·1+b·0, c·1+d·0) = (a, c)
A e₂ = A(0,1) = (a·0+b·1, c·0+d·1) = (b, d)
A v = A(x e₁ + y e₂) = x·Ae₁ + y·Ae₂

So the matrix is simply a list of two images written as columns. The last line is Chapter 1’s linear combination au+bv, with u=Ae₁, v=Ae₂, a=x and b=y.所以矩陣就是把兩個像寫成兩欄。最後一行就是第 1 章的線性組合 au+bv,只是 u=Ae₁、v=Ae₂、a=x、b=y。

Common slip常見錯誤Ae₁ is the first column (a,c), not the first row (a,b). A row runs across; a column runs down.Ae₁ 是第 1 欄 (a,c),不是第 1 列 (a,b)。列(row)是橫的,欄(column)是直的。
Looking ahead to Chapter 4預告第 4 章

The Transformer’s W is also a list of columns.Transformer 的 W 也是一排欄。

In Chapter 4, W has 3 rows and 2 columns: it sends a vector in ℝ² to three scores in ℝ³. The same rule holds:第 4 章的 W 有 3 列 2 欄:把 ℝ² 的向量送到 ℝ³ 的三個分數。規則完全一樣:

Wx = x₁·(column 1 of W) + x₂·(column 2 of W).

So if x₂ increases by 1, every score increases by the matching number in column 2. Keep this in mind when you reach the Transformer lab.所以 x₂ 增加 1 時,每個分數都會加上第 2 欄中對應的數。到 Transformer 實驗室時可以用上。

Challenge挑戰

讓方格對上影子Match the shadow

每一關有一個淡紫色的「影子」:某個矩陣把單位正方形和小旗子送到的位置。拖動藍色 Ae₁ 和綠色 Ae₂ 的箭頭尖端,或直接輸入矩陣,讓你的像和影子完全重合。拖箭頭時注意:藍色箭頭只會改變 a、c,綠色只會改變 b、d。Each level shows a pale violet “shadow”: where some matrix sends the unit square and the small flag. Drag the tips of blue Ae₁ and green Ae₂, or type the matrix, until your image matches the shadow exactly. Notice that dragging blue changes only a and c, and green only b and d.

A =
Guess the area first先猜面積再看行列式Estimate how large the image of the unit square is before reading the determinant. A negative det still means a positive area; the sign only says the plane flipped. When det=0, recall Chapter 2: the columns are dependent.先估計單位正方形的像有多大,再看行列式(determinant)。det 是負數時面積仍然是正的,負號只代表翻面。det=0 時,回想第 2 章:兩欄相依。

det A tells you how much area grows, and whether the plane flips.det A 告訴你面積放大幾倍,以及平面有沒有翻面。

The unit square has area 1. Its image is the parallelogram spanned by the two columns. The determinant det A = ad − bc measures that parallelogram with a sign.單位正方形的面積是 1,它的像是兩欄張成的平行四邊形。行列式 det A = ad − bc 用「帶正負號」的方式量這個平行四邊形。

Try a matrix試一個矩陣
A =
Reading the determinant怎麼讀行列式
area of image = |det A| × original area
det > 0: same orientation. det < 0: flipped, like a mirror image. det = 0: the plane is squashed onto a line or a point.det > 0:方向不變。det < 0:翻面,像照鏡子。det = 0:平面被壓成一條線或一個點。
Unit square, flag and turning direction單位正方形、小旗子與旋轉方向

The curved arrow turns from Ae₁ to Ae₂. Counterclockwise means no flip; clockwise means the plane has flipped. The flag turns into its mirror image when det < 0.弧形箭頭從 Ae₁ 轉向 Ae₂:逆時針表示沒有翻面,順時針表示翻面了。det < 0 時,小旗子會變成鏡像。

Back to Chapter 2回到第 2 章

Dependent columns squash the plane.相依的兩欄會把平面壓扁。

In Chapter 2, (1,2) and (2,4) were dependent: 2·(1,2) − 1·(2,4) = (0,0). Use them as the columns of A:第 2 章中,(1,2) 和 (2,4) 相依:2·(1,2) − 1·(2,4) = (0,0)。把它們當成 A 的兩欄:

A = [1 2; 2 4],   det A = 1·4 − 2·2 = 0.
Av = x·(1,2) + y·(2,4) = (x+2y)·(1,2).
A(2,−1) = 2·(1,2) − 1·(2,4) = (0,0).

Every output lies on the line y=2x, the span from Chapter 2. The nonzero vector (2,−1) is sent to 0, just like (0,0). Two different inputs give the same output, so the output cannot tell you which input you started from: A cannot be undone.每個輸出都落在直線 y=2x 上,也就是第 2 章的張成空間。非零向量 (2,−1) 被送到 0,和 (0,0) 一樣。兩個不同輸入得到同一個輸出,所以只看輸出無法知道原本的輸入:A 無法還原。

Surprises worth a pause值得停下來想的例子

Shear [1 1; 0 1]: the square leans over, but det = 1·1 − 1·0 = 1, so the area is unchanged.剪切(shear)[1 1; 0 1]:正方形歪了,但 det = 1·1 − 1·0 = 1,面積沒有變。

Reflection [0 1; 1 0]: e₁ and e₂ swap places. Area is still 1, but det = −1: the flag is mirrored.鏡射(reflection)[0 1; 1 0]:e₁ 和 e₂ 互換位置。面積仍是 1,但 det = −1:小旗子變成鏡像。

Rotation by 90° [0 −1; 1 0]: det = 0·0 − (−1)·1 = 1. Turning is not flipping.旋轉 90° [0 −1; 1 0]:det = 0·0 − (−1)·1 = 1。旋轉不是翻面。

Optional: why is |ad − bc| an area?選讀:為什麼 |ad − bc| 是面積?

Take the case a, b, c, d > 0 with column 1 below column 2. The parallelogram sits in a rectangle of size (a+b)×(c+d). Remove two triangles of area ac/2, two triangles of area bd/2 and two rectangles of area bc:考慮 a、b、c、d > 0 且第 1 欄在第 2 欄下方的情形。平行四邊形放在 (a+b)×(c+d) 的長方形裡,扣掉兩個面積 ac/2 的三角形、兩個面積 bd/2 的三角形和兩個面積 bc 的長方形:

(a+b)(c+d) − ac − bd − 2bc = ad − bc.

This is one case, not a general proof; the general statement needs properties of determinants.這只是一種情形的推導,不是一般證明;一般情形需要行列式的性質。

Predict before checking先自己想,再檢查Do one question at a time. Choose an answer or enter numbers, then press Check. If you are wrong, read the explanation, edit your answer and try again. Nothing is marked against you.一次做一題。選答案或填入數值,再按檢查。答錯時看中文說明,修改後可以再試;沒有扣分。

Predict it. Check it. Learn the key idea.先預測、再核對、看懂重點。

Allow 25–30 minutes for exploration and practice. Every computed answer is checked exactly; feedback names the row, column or determinant step to revisit. Retrying is encouraged.預留 25–30 分鐘探索與練習。所有計算題都用精確分數核對;回饋會指出該回頭看的列、欄或行列式步驟。鼓勵你多試幾次。

07 · Compute Av07 · 矩陣乘向量

Let A = [2 −1; 1 3] and v = (3,2). Find Av.設 A = [2 −1; 1 3]、v = (3,2),求 Av 的兩個座標。

08 · Build a collapsing matrix08 · 造一個壓扁矩陣

Column 1 of A is fixed at (2,−1). Choose column 2 so that A squashes the whole plane onto a line, then give a nonzero v with Av = 0.A 的第 1 欄固定為 (2,−1)。選第 2 欄,讓 A 把整個平面壓成一條線;再給一個非零向量 v,使 Av = 0。

A = [2 b; −1 d]

Many answers are possible.答案不只一種。

Keep evidence: one Av computed both by rows and by columns, one determinant with its area and orientation, and a sentence linking det = 0 to dependent columns from Chapter 2.留下學習紀錄:一個分別用「列」和「欄」算出的 Av、一個行列式與它代表的面積和方向,以及一句話說明 det = 0 和第 2 章「兩欄相依」的關係。
Continue to the Transformer lab →繼續學習 Transformer →
Glossary: each term in one sentence術語表:用一句話理解
Vector向量(Vector)
可做加法與純量乘法的物件。例:(2,1) 有兩個座標;多項式也可以是向量。
An object you can add and multiply by a scalar. (2,1) has two coordinates; a polynomial can also be a vector.
Scalar純量(Scalar)
拿來乘向量的數。例如 3(1,2)=(3,6),其中 3 是純量。
A number that multiplies a vector. In 3(1,2)=(3,6), the scalar is 3.
Coordinate座標(Coordinate)
描述向量的一個數值。(2,1) 的第一座標是 2,第二座標是 1。
One of the numbers describing a vector. For (2,1), the first coordinate is 2 and the second is 1.
Coefficient係數(Coefficient)
線性組合中乘在向量前面的純量。2u−v 的係數是 2 和 −1。
The scalar in front of each vector in a linear combination. In 2u−v the coefficients are 2 and −1.
Linear combination線性組合(Linear combination)
先把向量各自乘上純量,再相加:au+bv。
Multiply each vector by a scalar, then add the results: au+bv.
Symbols符號怎麼讀(Symbols)
∈:屬於;∉:不屬於;∀:每一個;∃:至少存在一個;⇒:如果前者成立,則後者成立。ℝ 是實數集合,ℂ 是複數集合。
∈: is in; ∉: is not in; ∀: for every; ∃: there is at least one; ⇒: if the first part holds, so does the second. ℝ is the set of real numbers and ℂ the set of complex numbers.
Linear transformation線性變換(Linear transformation)
把向量送到向量的函數,而且保留加法與純量乘法:A(u+v)=Au+Av、A(cv)=cAv。2×2 矩陣就是一個例子。
A function from vectors to vectors that preserves addition and scaling: A(u+v)=Au+Av and A(cv)=cAv. Every 2×2 matrix gives one.
Matrix / row / column矩陣/列/欄(Matrix / row / column)
數字排成的長方形表格。列(row)是橫的一排,欄(column)是直的一排。[a b; c d] 的第 1 欄是 (a,c)。
A rectangular table of numbers. A row runs across; a column runs down. The first column of [a b; c d] is (a,c).
Standard basis標準基底(Standard basis)
e₁=(1,0) 與 e₂=(0,1)。每個向量都能寫成 (x,y)=x e₁+y e₂。
e₁=(1,0) and e₂=(0,1). Every vector can be written as (x,y)=x e₁+y e₂.
Image像(Image)
輸入經過函數後的輸出。Ae₁ 是 e₁ 的像,也就是 A 的第 1 欄。
The output a function gives for an input. Ae₁ is the image of e₁, which is the first column of A.
Determinant行列式(Determinant)
det [a b; c d]=ad−bc。絕對值是面積放大的倍率,正負號表示方向有沒有翻轉。
det [a b; c d]=ad−bc. Its absolute value is the area scale factor; its sign tells whether orientation flips.
Orientation方向(定向)(Orientation)
從 e₁ 轉到 e₂ 是逆時針。若像 Ae₁ 轉到 Ae₂ 變成順時針,就是翻面(det<0),像照鏡子一樣。
Turning from e₁ to e₂ is counterclockwise. If turning from Ae₁ to Ae₂ is clockwise, the plane has flipped (det<0), like a mirror image.
Shear剪切(Shear)
把方格往一側推斜,例如 [1 1; 0 1]。形狀改變,但面積不變(det=1)。
Pushes the grid sideways, as in [1 1; 0 1]. The shape changes but the area does not (det=1).
Reflection / rotation鏡射/旋轉(Reflection / rotation)
鏡射像照鏡子,det=−1,例如 [0 1; 1 0]。旋轉 90° 是 [0 −1; 1 0],det=1。
A reflection mirrors the plane (det=−1), e.g. [0 1; 1 0]. A 90° rotation is [0 −1; 1 0], with det=1.
Collapse壓扁(Collapse)
兩欄相依時 det=0,整個平面被壓到一條直線(或一點)上,有非零向量被送到 0。
When the columns are dependent, det=0: the whole plane is squashed onto a line (or a point), and some nonzero vector is sent to 0.
Invertible可逆(Invertible)
能從輸出唯一找回輸入。2×2 矩陣可逆的條件是 det≠0。
The input can be recovered uniquely from the output. A 2×2 matrix is invertible exactly when det≠0.

Some terms are advanced; you do not need to memorise them all at once. Experiment first, then use examples to understand the definitions.有些名詞屬於進階內容,不必一次全部背起來。先操作,再用例子理解定義。