跳至主要内容

線性組合 & 向量乘積 & 特殊矩陣 (Linear Combinations, Matrix–Vector Products, and Special Matrices)

備註

本系列文章內容參考自經典教材 Elementary Linear Algebra (Pearson New International Edition)。本文對應章節:Ch1-2 Linear Combinations, Matrix–Vector Products, and Special Matrices

線性組合 (Linear Combination)

定義

給定向量 u1,u2,,uk\mathbf{u}_1, \mathbf{u}_2, \ldots, \mathbf{u}_k 與純量 c1,c2,,ckc_1, c_2, \ldots, c_k,則向量

c1u1+c2u2++ckukc_1 \mathbf{u}_1 + c_2 \mathbf{u}_2 + \cdots + c_k \mathbf{u}_k

稱為 u1,u2,,uk\mathbf{u}_1, \mathbf{u}_2, \ldots, \mathbf{u}_k 的一個線性組合 (Linear Combination)。其中 c1,c2,,ckc_1, c_2, \ldots, c_k 稱為該線性組合的係數 (Coefficients)

範例

[28]=3[11]+4[13]+1[11]\begin{bmatrix} 2 \\ 8 \end{bmatrix} = \colorbox{yellow}{$-3$} \begin{bmatrix} 1 \\ 1 \end{bmatrix} + \colorbox{yellow}{$4$} \begin{bmatrix} 1 \\ 3 \end{bmatrix} + \colorbox{yellow}{$1$} \begin{bmatrix} 1 \\ -1 \end{bmatrix}

此處係數為 {3,4,1}\{-3, 4, 1\}

線性組合的幾何意義

R2\mathbb{R}^2 中,兩個向量 u\mathbf{u}v\mathbf{v} 的線性組合 au+bva\mathbf{u} + b\mathbf{v} 可透過平行四邊形法則 (Parallelogram Rule) 來理解:

  1. 分別將 u\mathbf{u} 縮放 aa 倍得到 aua\mathbf{u},將 v\mathbf{v} 縮放 bb 倍得到 bvb\mathbf{v}
  2. aua\mathbf{u}bvb\mathbf{v} 為鄰邊構成平行四邊形
  3. 從原點指向平行四邊形對角頂點的向量,即為線性組合 au+bva\mathbf{u} + b\mathbf{v}

線性組合的平行四邊形法則

如何求解線性組合的係數?

給定係數,計算線性組合的結果是容易的。但反過來——給定目標向量,求解對應的係數——則需要解一個線性方程組 (System of Linear Equations)

範例:判斷 [41]\begin{bmatrix} 4 \\ -1 \end{bmatrix} 是否為 [23]\begin{bmatrix} 2 \\ 3 \end{bmatrix}[31]\begin{bmatrix} 3 \\ 1 \end{bmatrix} 的線性組合。

x1[23]+x2[31]=[41]x_1 \begin{bmatrix} 2 \\ 3 \end{bmatrix} + x_2 \begin{bmatrix} 3 \\ 1 \end{bmatrix} = \begin{bmatrix} 4 \\ -1 \end{bmatrix},展開得:

{2x1+3x2=43x1+x2=1\begin{cases} 2x_1 + 3x_2 = 4 \\ 3x_1 + x_2 = -1 \end{cases}

解得 [x1  x2]T=[1  2]T[x_1 \; x_2]^T = [-1 \; 2]^T,因此該向量可以表示為給定向量的線性組合。


線性方程組的解的情況

根據給定向量的幾何關係,線性方程組可能有三種解的情況:

解的情況幾何意義
唯一解 (Unique Solution)目標向量恰好落在給定向量張成的空間中,且表示方式唯一
無限多解 (Infinitely Many Solutions)給定向量線性相依,目標向量可用多種方式表示
無解 (No Solution)目標向量不在給定向量所能張成的空間中

非平行向量可以表示 R² 中的任意向量

u\mathbf{u}v\mathbf{v}R2\mathbb{R}^2 中的非平行向量 (Nonparallel Vectors)(即 ucv\mathbf{u} \neq c\mathbf{v},且兩者皆非零向量),則 R2\mathbb{R}^2 中的每一個向量都可以被唯一地表示為 u\mathbf{u}v\mathbf{v} 的線性組合。換句話說,兩個非平行向量可以「涵蓋」整個二維平面。

「無解」的幾何意義

當兩個向量 u\mathbf{u}v\mathbf{v} 平行 (Parallel) 時(即 v=cu\mathbf{v} = c\mathbf{u},其中 cc 為某純量),它們的所有線性組合只能產生落在同一條直線上的向量。

若目標向量 w\mathbf{w} 不在這條直線上,則無論如何選擇係數,都無法將 w\mathbf{w} 表示為 u\mathbf{u}v\mathbf{v} 的線性組合——此時方程組無解

平行向量導致無解的情況

在上圖中,u\mathbf{u}v=2u\mathbf{v} = 2\mathbf{u} 平行,它們的所有線性組合只能產生虛線上的向量。目標向量 w\mathbf{w} 不在該直線上,因此無法被表示為 u\mathbf{u}v\mathbf{v} 的線性組合。

範例:判斷 [34]\begin{bmatrix} 3 \\ 4 \end{bmatrix} 是否為 [32]\begin{bmatrix} 3 \\ 2 \end{bmatrix}[64]\begin{bmatrix} 6 \\ 4 \end{bmatrix} 的線性組合。

注意到 [64]=2[32]\begin{bmatrix} 6 \\ 4 \end{bmatrix} = 2 \begin{bmatrix} 3 \\ 2 \end{bmatrix},兩向量平行。設方程組:

{3x1+6x2=32x1+4x2=4\begin{cases} 3x_1 + 6x_2 = 3 \\ 2x_1 + 4x_2 = 4 \end{cases}

第一式除以 3 得 x1+2x2=1x_1 + 2x_2 = 1;第二式除以 2 得 x1+2x2=2x_1 + 2x_2 = 2。兩式矛盾,故無解


標準向量 (Standard Vectors)

定義

Rn\mathbb{R}^n 中,標準向量 (Standard Vectors) e1,e2,,en\mathbf{e}_1, \mathbf{e}_2, \ldots, \mathbf{e}_n 定義為:

e1=[100],e2=[010],,en=[001]\mathbf{e}_1 = \begin{bmatrix} 1 \\ 0 \\ \vdots \\ 0 \end{bmatrix}, \quad \mathbf{e}_2 = \begin{bmatrix} 0 \\ 1 \\ \vdots \\ 0 \end{bmatrix}, \quad \ldots, \quad \mathbf{e}_n = \begin{bmatrix} 0 \\ 0 \\ \vdots \\ 1 \end{bmatrix}

其中 ei\mathbf{e}_i 的第 ii 個分量為 11,其餘分量皆為 00

二維空間中的標準向量

標準向量的重要性質

Rn\mathbb{R}^n 中的任意向量 v\mathbf{v} 都可以唯一地表示為標準向量的線性組合:

v=[v1v2vn]=v1e1+v2e2++vnen\mathbf{v} = \begin{bmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{bmatrix} = v_1 \mathbf{e}_1 + v_2 \mathbf{e}_2 + \cdots + v_n \mathbf{e}_n

換句話說,只要知道一個向量的各個分量,就能用標準向量把它「拼」出來。這也意味著標準向量是 Rn\mathbb{R}^n 中最基本、最自然的一組「建構單元」——在後續章節中,這種能夠表示空間中所有向量的向量組合,會被正式稱為基底 (Basis)


矩陣與向量乘積 (Matrix–Vector Product)

定義

AAm×nm \times n 矩陣,v\mathbf{v}n×1n \times 1 向量。矩陣與向量乘積 (Matrix–Vector Product) AvA\mathbf{v} 定義為 AA 的 column vectors 以 v\mathbf{v} 的分量為係數的線性組合

Av=v1a1+v2a2++vnanA\mathbf{v} = v_1 \mathbf{a}_1 + v_2 \mathbf{a}_2 + \cdots + v_n \mathbf{a}_n

其中 a1,a2,,an\mathbf{a}_1, \mathbf{a}_2, \ldots, \mathbf{a}_nAA 的 column vectors,v1,v2,,vnv_1, v_2, \ldots, v_nv\mathbf{v} 的分量。

等價地,可以寫成:

Av=[a1a2an][v1v2vn]A\mathbf{v} = \begin{bmatrix} \mathbf{a}_1 & \mathbf{a}_2 & \cdots & \mathbf{a}_n \end{bmatrix} \begin{bmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{bmatrix}
矩陣向量乘積的直觀理解

可以將矩陣 AA 想像成 nn 個 column vectors 的集合,向量 v\mathbf{v} 想像成 nn 個係數。則 AvA\mathbf{v} 就是這 nn 個 column vectors 的線性組合,其中第 ii 個 column vector 的係數為 viv_i

這個觀點在理解線性變換、column space 等概念時非常有用。

逐元素計算

矩陣向量乘積的第 ii 個分量等於 AA 的第 ii 個 row 與 v\mathbf{v}內積

(Av)i=ai1v1+ai2v2++ainvn=j=1naijvj(A\mathbf{v})_i = a_{i1}v_1 + a_{i2}v_2 + \cdots + a_{in}v_n = \sum_{j=1}^{n} a_{ij}v_j

範例

Av=[123456][78]=7[135]+8[246]=[72135]+[163248]=[235383]A\mathbf{v} = \begin{bmatrix} 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{bmatrix} \begin{bmatrix} 7 \\ 8 \end{bmatrix} = 7 \begin{bmatrix} 1 \\ 3 \\ 5 \end{bmatrix} + 8 \begin{bmatrix} 2 \\ 4 \\ 6 \end{bmatrix} = \begin{bmatrix} 7 \\ 21 \\ 35 \end{bmatrix} + \begin{bmatrix} 16 \\ 32 \\ 48 \end{bmatrix} = \begin{bmatrix} 23 \\ 53 \\ 83 \end{bmatrix}

基本性質

對於任意矩陣 AA 與向量 v\mathbf{v}

  • A0=0A\mathbf{0} = \mathbf{0}(矩陣乘以零向量得零向量)
  • Ov=0O\mathbf{v} = \mathbf{0}(零矩陣乘以任意向量得零向量)

單位矩陣 (Identity Matrix)

定義

對於每個正整數 nnn×nn \times n 單位矩陣 (Identity Matrix) InI_n 是以標準向量 e1,e2,,en\mathbf{e}_1, \mathbf{e}_2, \ldots, \mathbf{e}_n 為 column vectors 的方陣:

I2=[1001],I3=[100010001]I_2 = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}, \quad I_3 = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}

核心性質

對於任意 vRn\mathbf{v} \in \mathbb{R}^n

Inv=vI_n \mathbf{v} = \mathbf{v}

證明

Inv=v1e1+v2e2++vnen=[v1v2vn]=vI_n \mathbf{v} = v_1 \mathbf{e}_1 + v_2 \mathbf{e}_2 + \cdots + v_n \mathbf{e}_n = \begin{bmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{bmatrix} = \mathbf{v}

單位矩陣在矩陣乘法中扮演的角色,類似於數字 11 在實數乘法中的角色——它是乘法單位元素


隨機矩陣 (Stochastic Matrix)

定義

一個方陣稱為隨機矩陣 (Stochastic Matrix)(或機率矩陣),若:

  1. 所有元素皆為非負數
  2. 每一 column 的元素和為 11

隨機矩陣常用於描述馬可夫鏈 (Markov Chain) 中的狀態轉移機率。

範例:人口遷移模型

A=[0.850.030.150.97]A = \begin{bmatrix} 0.85 & 0.03 \\ 0.15 & 0.97 \end{bmatrix}

此矩陣描述城市與郊區之間的人口遷移機率:

  • a11=0.85a_{11} = 0.85:城市居民留在城市的機率
  • a21=0.15a_{21} = 0.15:城市居民遷往郊區的機率
  • a12=0.03a_{12} = 0.03:郊區居民遷往城市的機率
  • a22=0.97a_{22} = 0.97:郊區居民留在郊區的機率

若當前人口分布為 p=[500700]\mathbf{p} = \begin{bmatrix} 500 \\ 700 \end{bmatrix}(千人),則下一年的人口分布為:

Ap=[0.850.030.150.97][500700]=[446754]A\mathbf{p} = \begin{bmatrix} 0.85 & 0.03 \\ 0.15 & 0.97 \end{bmatrix} \begin{bmatrix} 500 \\ 700 \end{bmatrix} = \begin{bmatrix} 446 \\ 754 \end{bmatrix}

旋轉矩陣 (Rotation Matrix)

定義

θ\theta-旋轉矩陣 (θ-Rotation Matrix) AθA_\theta 定義為:

Aθ=[cosθsinθsinθcosθ]A_\theta = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix}

此矩陣將 R2\mathbb{R}^2 中的向量逆時針旋轉 θ\theta 角度。

推導過程

設原始點 P0=(x0,y0)P_0 = (x_0, y_0) 與原點的距離為 rr,與 xx 軸的夾角為 α\alpha。則:

x0=rcosα,y0=rsinαx_0 = r\cos\alpha, \quad y_0 = r\sin\alpha

P0P_0 逆時針旋轉 θ\theta 角度後得到 P1=(x1,y1)P_1 = (x_1, y_1),其與 xx 軸的夾角為 α+θ\alpha + \theta

x1=rcos(α+θ)=r(cosαcosθsinαsinθ)=(rcosα)cosθ(rsinα)sinθ=x0cosθy0sinθ\begin{aligned} x_1 &= r\cos(\alpha + \theta) = r(\cos\alpha\cos\theta - \sin\alpha\sin\theta) \\ &= (r\cos\alpha)\cos\theta - (r\sin\alpha)\sin\theta \\ &= x_0\cos\theta - y_0\sin\theta \end{aligned} y1=rsin(α+θ)=r(sinαcosθ+cosαsinθ)=(rsinα)cosθ+(rcosα)sinθ=y0cosθ+x0sinθ\begin{aligned} y_1 &= r\sin(\alpha + \theta) = r(\sin\alpha\cos\theta + \cos\alpha\sin\theta) \\ &= (r\sin\alpha)\cos\theta + (r\cos\alpha)\sin\theta \\ &= y_0\cos\theta + x_0\sin\theta \end{aligned}

整理成矩陣形式:

[x1y1]=[cosθsinθsinθcosθ][x0y0]\begin{bmatrix} x_1 \\ y_1 \end{bmatrix} = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} \begin{bmatrix} x_0 \\ y_0 \end{bmatrix}

旋轉矩陣的幾何推導

我的記憶方式

我個人覺得這個公式用以下方式記比較方便:

旋轉矩陣的兩個 column vectors,其實就是標準向量 (1,0)(1, 0)(0,1)(0, 1) 各自旋轉 θ\theta 角度後的結果。

  • 第一個 column(1,0)(1, 0) 旋轉 θ\theta 後變成 (cosθ,sinθ)(\cos\theta, \sin\theta)
  • 第二個 column(0,1)(0, 1) 旋轉 θ\theta 後變成 (sinθ,cosθ)(-\sin\theta, \cos\theta)

把這兩個結果作為 column vectors 排列起來,就是旋轉矩陣:

Aθ=[cosθsinθsinθcosθ]A_\theta = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix}

旋轉矩陣的記憶技巧

特殊角度的旋轉矩陣

角度旋轉矩陣
θ=0°\theta = 0°[1001]=I2\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} = I_2
θ=90°\theta = 90°[0110]\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}
θ=180°\theta = 180°[1001]\begin{bmatrix} -1 & 0 \\ 0 & -1 \end{bmatrix}
θ=270°\theta = 270°[0110]\begin{bmatrix} 0 & 1 \\ -1 & 0 \end{bmatrix}