Academic
  • Introduction
  • Artificial Intelligence
    • Introduction
    • AI Concepts, Terminology, and Application Areas
    • AI: Issues, Concerns and Ethical Considerations
  • Biology
    • Scientific Method
    • Chemistry of Life
    • Water, Acids, Bases
    • Properties of carbon
    • Macromolecules
    • Energy and Enzymes
    • Structure of a cell
    • Membranes and transport
    • Cellular respiration
    • Cell Signaling
    • Cell Division
    • Classical and molecular genetics
    • DNA as the genetic material
    • Central dogma
    • Gene regulation
  • Bioinformatics
    • Bioinformatics Overview
  • Deep Learning
    • Neural Networks and Deep Learning
      • Introduction
      • Logistic Regression as a Neural Network
      • Python and Vectorization
      • Shallow Neural Network
      • Deep Neural Network
    • Improving Deep Neural Networks
      • Setting up your Machine Learning Application
      • Regularizing your Neural Network
      • Setting up your Optimization Problem
      • Optimization algorithms
      • Hyperparameter, Batch Normalization, Softmax
    • Structuring Machine Learning Projects
    • Convolutional Neural Networks
      • Introduction
    • Sequence Models
      • Recurrent Neural Networks
      • Natural Language Processing & Word Embeddings
      • Sequence models & Attention mechanism
  • Linear Algebra
    • Vectors and Spaces
      • Vectors
      • Linear combinations and spans
      • Linear dependence and independence
      • Subspaces and the basis for a subspace
      • Vector dot and cross products
      • Matrices for solving systems by elimination
      • Null space and column space
    • Matrix transformations
      • Functions and linear transformations
      • Linear transformation examples
      • Transformations and matrix multiplication
      • Inverse functions and transformations
      • Finding inverses and determinants
      • More Determinant Depth
  • Machine Learning
    • Introduction
    • Linear Regression
      • Model and Cost Function
      • Parameter Learning
      • Multivariate Linear Regression
      • Computing Parameters Analytically
      • Octave
    • Logistic Regression
      • Classification and Representation
      • Logistic Regression Model
    • Regularization
      • Solving the Problem of Overfitting
    • Neural Networks
      • Introduction of Neural Networks
      • Neural Networks - Learning
    • Improve Learning Algorithm
      • Advice for Applying Machine Learning
      • Machine Learning System Design
    • Support Vector Machine
      • Large Margin Classification
      • Kernels
      • SVM in Practice
  • NCKU - Artificial Intelligence
    • Introduction
    • Intelligent Agents
    • Solving Problems by Searching
    • Beyond Classical Search
    • Learning from Examples
  • NCKU - Computer Architecture
    • First Week
  • NCKU - Data Mining
    • Introduction
    • Association Analysis
    • FP-growth
    • Other Association Rules
    • Sequence Pattern
    • Classification
    • Evaluation
    • Clustering
    • Link Analysis
  • NCKU - Machine Learning
    • Probability
    • Inference
    • Bayesian Inference
    • Introduction
  • NCKU - Robotic Navigation and Exploration
    • Kinetic Model & Vehicle Control
    • Motion Planning
    • SLAM Back-end (I)
    • SLAM Back-end (II)
    • Computer Vision / Multi-view Geometry
    • Lie group & Lie algebra
    • SLAM Front-end
  • Python
    • Numpy
    • Pandas
    • Scikit-learn
      • Introduction
      • Statistic Learning
  • Statstics
    • Quantitative Data
    • Modeling Data Distribution
    • Bivariate Numerical Data
    • Probability
    • Random Variables
    • Sampling Distribution
    • Confidence Intervals
    • Significance tests
Powered by GitBook
On this page
  • Scaling and reflections
  • Rotation in R2
  • Rotation in R3 around the x-axis
  • Unit Vectors
  • Projections Introduction
  • Projections as matrix vector product

Was this helpful?

  1. Linear Algebra
  2. Matrix transformations

Linear transformation examples

PreviousFunctions and linear transformationsNextTransformations and matrix multiplication

Last updated 5 years ago

Was this helpful?

Scaling and reflections

我們學到 transformation 可以使用 matrix vector product 來表達

matrix 可以更進一步化為 identity matrix 和 transformation 的結合

T:Rn→Rm∣T(x⃗)=Ax⃗∣A=[T(e1)T(e2)⋯T(en)]T:\mathbb{R}^n \to \mathbb{R}^m \mid T(\vec{x}) = \mathbf{A}\vec{x} \mid \mathbf{A} = \begin{bmatrix} T(e_1)&T(e_2) & \cdots& T(e_n)\end{bmatrix}T:Rn→Rm∣T(x)=Ax∣A=[T(e1​)​T(e2​)​⋯​T(en​)​]

現在來試著 custom 一個自己的 transformation

假設有三個向量在 R2 上繪製出一個三角形

a⃗=[32],b⃗=[−32],c⃗=[3−2]\vec{a} = \begin{bmatrix}3\\2\end{bmatrix}, \vec{b} = \begin{bmatrix}-3\\2\end{bmatrix}, \vec{c} = \begin{bmatrix}3\\-2\end{bmatrix}a=[32​],b=[−32​],c=[3−2​]

我們想讓他以 y 軸為主軸,翻轉過來,並且不改變底的情況下,讓高拉長兩倍

所以每個向量的 x 應該要乘以負號,然後 y 應該要乘以 2

T([xy])=[−x2y]T\left( \begin{bmatrix} x\\y \end{bmatrix} \right) = \begin{bmatrix} -x\\2y \end{bmatrix}T([xy​])=[−x2y​]

接著我們要怎麼表示 transformation 的 matrix 呢,我們可以拿 identity matrix 當作白紙

寫下每個 e vector 進行 transformation 的結果

I2=[1001]A=[T([10])],[T([01])]A=[−1002]\mathbf{I_2} = \begin{bmatrix} 1&0\\0&1 \end{bmatrix} \\ \mathbf{A} = \begin{bmatrix} T\left(\begin{bmatrix} 1\\0 \end{bmatrix}\right) \end{bmatrix}, \begin{bmatrix} T\left(\begin{bmatrix} 0\\1 \end{bmatrix}\right) \end{bmatrix}\\ \mathbf{A} = \begin{bmatrix} -1&0\\0&2 \end{bmatrix}I2​=[10​01​]A=[T([10​])​],[T([01​])​]A=[−10​02​]

也就是說

T([xy])=[−x2y]=[−1002][xy]=A[xy]T\left( \begin{bmatrix} x\\y \end{bmatrix} \right) = \begin{bmatrix} -x\\2y \end{bmatrix} = \begin{bmatrix} -1&0\\0&2 \end{bmatrix} \begin{bmatrix} x\\y \end{bmatrix} = \mathbf{A}\begin{bmatrix} x\\y \end{bmatrix}T([xy​])=[−x2y​]=[−10​02​][xy​]=A[xy​]

回到原本三個向量,我們將算好的 transformation apply 到他們三個上面

Aa⃗=[−1002][32]=[−34]Ab⃗=[−1002][−32]=[34]Ac⃗=[−1002][3−2]=[−3−4]\mathbf{A}\vec{a} = \begin{bmatrix} -1&0\\0&2 \end{bmatrix} \begin{bmatrix} 3\\2 \end{bmatrix} = \begin{bmatrix} -3\\4 \end{bmatrix}\\ \mathbf{A}\vec{b} = \begin{bmatrix} -1&0\\0&2 \end{bmatrix} \begin{bmatrix} -3\\2 \end{bmatrix} = \begin{bmatrix} 3\\4 \end{bmatrix}\\ \mathbf{A}\vec{c} = \begin{bmatrix} -1&0\\0&2 \end{bmatrix} \begin{bmatrix} 3\\-2 \end{bmatrix} = \begin{bmatrix} -3\\-4 \end{bmatrix}\\Aa=[−10​02​][32​]=[−34​]Ab=[−10​02​][−32​]=[34​]Ac=[−10​02​][3−2​]=[−3−4​]

我們成功將他翻面並且拉長了!

我們學到要自製 transformation 可以先定義好 transformation 再 apply 到 identity matrix

或者,我們可以直接針對 identity matrix 在 diagonal 的第一項 (x) 或第二項 (y),

甚至第三項 (三維的 z),第四項 (四維空間) 來做修改。

Rotation in R2

上面我們學到了 reflection 以及 scaling,現在我們來學 rotation

我們要怎麼找到 T 或者是 matrix A ,讓 vector x 往逆時針方向轉 ɵ 度

首先要先確認這個 rotation 運算是否為 linear transformation 才可以繼續下去

Rotθ(x⃗+y⃗)=Rotθ(x⃗)+θ(y⃗)Rotθ(cx⃗)=c⋅Rotθ(x⃗)\text{Rot}_\theta(\vec{x}+\vec{y}) = \text{Rot}_\theta(\vec{x})+\theta(\vec{y}) \\ \text{Rot}_\theta(c\vec{x}) = c\cdot\text{Rot}_\theta(\vec{x})Rotθ​(x+y​)=Rotθ​(x)+θ(y​)Rotθ​(cx)=c⋅Rotθ​(x)

影片中有畫圖證明,這兩項都是通過的,所以所有的 rotation 皆為 linear transformation

接著我們來找出 rotation 所表達的 transformation matrix 為何

A=[Rotθ([10]),Rotθ([01])]\mathbf{A} = \begin{bmatrix} \text{Rot}_\theta\left(\begin{bmatrix}1\\0\end{bmatrix}\right), \text{Rot}_\theta\left(\begin{bmatrix}0\\1\end{bmatrix}\right) \end{bmatrix}A=[Rotθ​([10​]),Rotθ​([01​])​]

先從 [1, 0] 轉換成 [a, b] 開始看起

可以發現 a 為這個正三角形的鄰邊,剛好 cos 等於鄰邊除以斜邊

而 b 等於新 vector 投影到舊 vector 的高,為這個三角形的對邊,剛好 sin 等於對邊除以斜邊

cos⁡(θ)=a1⇒a=cos⁡(θ)sin⁡(θ)=b1⇒b=sin⁡(θ)Rotθ([10])=[cos⁡(θ)sin⁡(θ)]\cos(\theta) = \frac{a}{1} \Rightarrow \color{red}{a = \cos(\theta)}\\ \sin(\theta) = \frac{b}{1} \Rightarrow \color{red}{b = \sin(\theta)}\\ \text{Rot}_\theta\left(\begin{bmatrix}1\\0\end{bmatrix}\right) = \begin{bmatrix}\cos(\theta)\\\sin(\theta)\end{bmatrix}cos(θ)=1a​⇒a=cos(θ)sin(θ)=1b​⇒b=sin(θ)Rotθ​([10​])=[cos(θ)sin(θ)​]

再來我們看 [0, 1] 轉換成 [c, d]

此時 c 可以為正三角形的對邊, 用 sin 等於對邊除以斜邊得到 c 值,而且因為是在第二象限,所以要加上負值

d 為鄰邊,用 cos 等於鄰邊除以斜邊得到 d 值

sin⁡(θ)=c1⇒c=sin⁡(θ)⇒−sin⁡(θ)cos⁡(θ)=d1⇒d=cos⁡(θ)Rotθ([01])=[−sin⁡(θ)cos⁡(θ)]\sin(\theta) = \frac{c}{1} \Rightarrow \color{red}{c = \sin(\theta)} \Rightarrow -\sin(\theta) \\ \cos(\theta) = \frac{d}{1} \Rightarrow \color{red}{d = \cos(\theta)}\\ \text{Rot}_\theta\left(\begin{bmatrix}0\\1\end{bmatrix}\right) = \begin{bmatrix}-\sin(\theta)\\\cos(\theta)\end{bmatrix}sin(θ)=1c​⇒c=sin(θ)⇒−sin(θ)cos(θ)=1d​⇒d=cos(θ)Rotθ​([01​])=[−sin(θ)cos(θ)​]

於是我們得到了 rotation matrix A 為

A=[cos⁡θ−sin⁡θsin⁡θcos⁡θ]\mathbf{A} = \begin{bmatrix} \cos\theta & -\sin\theta\\ \sin\theta& \cos\theta\end{bmatrix}A=[cosθsinθ​−sinθcosθ​]

以後任何向量,想要 rotate ɵ 度時,只要把角度帶入 ɵ 即可

例如我想讓 vector 逆時針旋轉 45 度角:

[cos⁡45∘−sin⁡45∘sin⁡45∘cos⁡45∘][xy]=[22−222222][xy]\begin{bmatrix} \cos45^\circ & -\sin45^\circ\\ \sin45^\circ& \cos45^\circ\end{bmatrix} \begin{bmatrix} x\\y\end{bmatrix} = \begin{bmatrix} \frac{\sqrt{2}}{2}&-\frac{\sqrt{2}}{2}\\\frac{\sqrt{2}}{2}&\frac{\sqrt{2}}{2}\end{bmatrix} \begin{bmatrix} x\\y\end{bmatrix}[cos45∘sin45∘​−sin45∘cos45∘​][xy​]=[22​​22​​​−22​​22​​​][xy​]

Rotation in R3 around the x-axis

接下來我們試著將 rotation 擴充到 R3 空間,但是只以 x-axis 為主軸逆時針旋轉

我們知道要找出 rotation matrix 就是把 rotation apply 到 identity matrix 上

A=(3rdRotθ[100],3rdRotθ[010],3rdRotθ[001])\mathbf{A} = \left( 3^{rd}\text{Rot}_\theta\begin{bmatrix} 1\\0\\0 \end{bmatrix}, 3^{rd}\text{Rot}_\theta\begin{bmatrix} 0\\1\\0 \end{bmatrix}, 3^{rd}\text{Rot}_\theta\begin{bmatrix} 0\\0\\1 \end{bmatrix} \right)A=​3rdRotθ​​100​​,3rdRotθ​​010​​,3rdRotθ​​001​​​

可以觀察到,因為是圍著 x-axis 旋轉,所以代表在 x 軸的第一個 vector 是不會變的

3rdRotθ[100]=[100]3^{rd}\text{Rot}_\theta\begin{bmatrix} 1\\0\\0 \end{bmatrix} = \begin{bmatrix} 1\\0\\0 \end{bmatrix}3rdRotθ​​100​​=​100​​

而第二個代表在 y 軸的 vector 則會除了 x 不變以外,(y, z) 會像 R2 的 (1, 0) 一樣旋轉

3rdRotθ[010]=[0cos⁡θsin⁡θ]3^{rd}\text{Rot}_\theta\begin{bmatrix} 0\\1\\0 \end{bmatrix} = \begin{bmatrix} 0\\\cos\theta\\\sin\theta \end{bmatrix}3rdRotθ​​010​​=​0cosθsinθ​​

第三個代表在 z 軸的 vector ,就是像 R2 的 (0, 1) 一樣旋轉

3rdRotθ[001]=[0−sin⁡θcos⁡θ]3^{rd}\text{Rot}_\theta\begin{bmatrix} 0\\0\\1 \end{bmatrix} = \begin{bmatrix} 0\\-\sin\theta\\\cos\theta \end{bmatrix}3rdRotθ​​001​​=​0−sinθcosθ​​

所以我們可以得到 matrix A 為

A=[1000cos⁡θ−sin⁡θ0sin⁡θcos⁡θ]\mathbf{A} = \begin{bmatrix} 1&0&0\\0&\cos\theta&-\sin\theta\\0&\sin\theta&\cos\theta \end{bmatrix}A=​100​0cosθsinθ​0−sinθcosθ​​

Unit Vectors

我們都知道 vector 的 length 怎麼算,像是擴充版的 pythagorean theorem

v⃗=[v1v2⋮vn]∈Rn,∥v⃗∥=v1⃗2+v2⃗2+⋯+vn⃗2\vec{v} = \begin{bmatrix}v_1\\v_2\\\vdots\\v_n \end{bmatrix} \in \mathbb{R}^n, \lVert \vec{v} \rVert = \sqrt{\vec{v_1}^2+\vec{v_2}^2+\cdots+\vec{v_n}^2}v=​v1​v2​⋮vn​​​∈Rn,∥v∥=v1​​2+v2​​2+⋯+vn​​2​

而 unit vector 其實就是指 length 等於 1 的 vector

∥u⃗∥=1\lVert \vec{u} \rVert = 1∥u∥=1

今天我們有辦法把一個不為 unit vector 的 vector 變為 unit vector

只要將他的 length 求出,並且讓每一個 element 除以 length 即可

u⃗=1∥v⃗∥⋅v⃗\vec{u} = \frac{1}{\lVert \vec{v} \rVert} \cdot \vec{v}u=∥v∥1​⋅v

這時可以驗證得到新的 unit vector u 的 length 等於 1

∥u⃗∥=∥1∥v⃗∥⋅v⃗∥=∥v⃗∥⋅1∥v⃗∥=1\begin{aligned} \lVert\vec{u}\rVert &= \lVert\frac{1}{\lVert \vec{v} \rVert} \cdot \vec{v}\rVert\\ &= \lVert \vec{v} \rVert\cdot\frac{1}{\lVert \vec{v} \rVert}\\ &= 1 \end{aligned}∥u∥​=∥∥v∥1​⋅v∥=∥v∥⋅∥v∥1​=1​

因為 1/length 為 constant 所以可以 apply

∥c⋅v⃗∥=∣c∣⋅∥v⃗∥\lVert c\cdot \vec{v} \rVert = \lvert c\rvert \cdot \lVert \vec{v}\rVert∥c⋅v∥=∣c∣⋅∥v∥

而且我們通常會將 unit vector 頭上的 vector sign 轉為 hat sign

if ∥u⃗∥=1then we can write it as u^\text{if } \lVert \vec{u} \rVert = 1 \\ \text{then we can write it as } \hat{u}if ∥u∥=1then we can write it as u^

舉個例子

v⃗=[12−1],∥v⃗∥=12+22+(−1)2=6\vec{v} = \begin{bmatrix} 1\\2\\-1 \end{bmatrix}, \lVert \vec{v} \rVert = \sqrt{1^2+2^2+(-1)^2}= \sqrt{6}v=​12−1​​,∥v∥=12+22+(−1)2​=6​

現在求對應 v 的 unit vector u

u^=16⋅[12−1]=[1626−16]\hat{u} = \frac{1}{\sqrt{6}}\cdot \begin{bmatrix} 1\\2\\-1 \end{bmatrix} = \begin{bmatrix} \frac{1}{\sqrt{6}}\\\frac{2}{\sqrt{6}}\\\frac{-1}{\sqrt{6}} \end{bmatrix}u^=6​1​⋅​12−1​​=​6​1​6​2​6​−1​​​

Projections Introduction

現在我們要討論的是,任一個 vector 他投影到任一個由 vector 所 span 而成的直線時,他的 影子 的長度為何

我們用這個寫法表示 vector x 投影到 line L 的影子長度 (projection)

ProjL(x⃗)Proj_L(\vec{x})ProjL​(x)

而從 vector x 垂直射下到 L 的垂直線我們表示為

x⃗−ProjL(x⃗)\vec{x}-Proj_L(\vec{x})x−ProjL​(x)

也就是上圖淺藍色的直線!

那要怎麼找出 projection 呢?我們發現, projection 其實只是 c 在特定數字時的表現而已

我們只要找出這個 c 就可以找出 projection 的公式

ProjL(x⃗)=cv⃗Proj_L(\vec{x}) = c\vec{v}ProjL​(x)=cv

而我們發現不管是 cv 還是 v 都會跟淺藍色的直線 (x - cv) 垂直,也就是 Dot product 為 0

v⃗⋅(x⃗−cv⃗)=0v⃗⋅x⃗−cv⃗⋅v⃗=0v⃗⋅x⃗=cv⃗⋅v⃗c=v⃗⋅x⃗v⃗⋅v⃗\begin{aligned} &\vec{v} \cdot (\vec{x}-c\vec{v}) = 0\\ &\vec{v}\cdot\vec{x}-c\vec{v}\cdot\vec{v}=0\\ &\vec{v}\cdot\vec{x}=c\vec{v}\cdot\vec{v}\\ &c = \frac{\vec{v}\cdot\vec{x}}{\vec{v}\cdot\vec{v}} \end{aligned}​v⋅(x−cv)=0v⋅x−cv⋅v=0v⋅x=cv⋅vc=v⋅vv⋅x​​

所以我們的 projection 公式為

ProjL(x⃗)=cv⃗=x⃗⋅v⃗v⃗⋅v⃗v⃗Proj_L(\vec{x}) = c\vec{v} = \frac{\vec{x}\cdot\vec{v}}{\vec{v}\cdot\vec{v}} \vec{v}ProjL​(x)=cv=v⋅vx⋅v​v

這邊來舉個例子,我們有 line L 為 v = (2, 1) span 而成,還有 vector x = (2, 3)

L={c[21]∣c∈R}x⃗=[23]\mathbf{L} = \begin{Bmatrix}c\begin{bmatrix}2\\1\end{bmatrix} \mid c\in \mathbb{R}\end{Bmatrix}\\ \vec{x} = \begin{bmatrix}2\\3\end{bmatrix}\\L={c[21​]∣c∈R​}x=[23​]

我們想知道 x 在 L 的投影向量為何,只要帶入剛剛算出來的公式即可

ProjL(x⃗)=[23]⋅[21][21]⋅[21]⋅[21]=75[21]=[14/57/5]=[2.81.4]Proj_L(\vec{x})= \frac{\begin{bmatrix}2\\3\end{bmatrix}\cdot \begin{bmatrix}2\\1\end{bmatrix}} {\begin{bmatrix}2\\1\end{bmatrix}\cdot \begin{bmatrix}2\\1\end{bmatrix}} \cdot \begin{bmatrix}2\\1\end{bmatrix} = \frac{7}{5} \begin{bmatrix}2\\1\end{bmatrix} = \begin{bmatrix}14/5\\7/5\end{bmatrix} = \begin{bmatrix}2.8\\1.4\end{bmatrix}ProjL​(x)=[21​]⋅[21​][23​]⋅[21​]​⋅[21​]=57​[21​]=[14/57/5​]=[2.81.4​]

其實就是上圖的例子!

Projections as matrix vector product

我們有辦法把 projection 的公式更加簡化嗎?

有的,我們發現分母的 dot product 跟 v 的 length 有關

ProjL(x⃗)=cv⃗=x⃗⋅v⃗v⃗⋅v⃗v⃗=x⃗⋅v⃗∥v⃗∥2v⃗Proj_L(\vec{x}) = c\vec{v} = \frac{\vec{x}\cdot\vec{v}}{\vec{v}\cdot\vec{v}} \vec{v} = \frac{\vec{x}\cdot\vec{v}}{\lVert \vec{v} \rVert^2} \vec{v}ProjL​(x)=cv=v⋅vx⋅v​v=∥v∥2x⋅v​v

所以今天若 v 為 unit vector,分母就會變成 1,projection 就會簡化為

ProjL(x⃗)=(x⃗⋅v⃗)v⃗Proj_L(\vec{x}) = (\vec{x}\cdot\vec{v})\vec{v}ProjL​(x)=(x⋅v)v

這就是我們學習過把 vector 變為 unit vector 的好處

接著,我們可以把 projection 變為 matrix 嗎?

我們先檢查 projection 是否為 Linear transformation

  • 第一個條件成立

ProjL(a⃗+b⃗)=((a⃗+b⃗)⋅u^)u^=(a⃗⋅u^+b⃗⋅u^)u^=(a⃗⋅u^)u^+(b⃗⋅u^)u^=ProjL(a⃗)+ProjL(b⃗)\begin{aligned} Proj_L(\vec{a}+\vec{b}) &= ((\vec{a}+\vec{b})\cdot\hat{u})\hat{u} \\ &= (\vec{a}\cdot\hat{u}+\vec{b}\cdot\hat{u})\hat{u}\\ &= (\vec{a}\cdot\hat{u})\hat{u} + (\vec{b}\cdot\hat{u})\hat{u}\\ &= Proj_L(\vec{a})+Proj_L(\vec{b}) \end{aligned}ProjL​(a+b)​=((a+b)⋅u^)u^=(a⋅u^+b⋅u^)u^=(a⋅u^)u^+(b⋅u^)u^=ProjL​(a)+ProjL​(b)​
  • 第二個條件成立

ProjL(ca⃗)=((ca⃗)⋅u^)u^=c(a⃗⋅u^)u^=cProjL(a⃗)\begin{aligned} Proj_L(c\vec{a}) &= ((c\vec{a})\cdot\hat{u})\hat{u} \\ &= c(\vec{a}\cdot\hat{u})\hat{u}\\ &= cProj_L(\vec{a}) \end{aligned}ProjL​(ca)​=((ca)⋅u^)u^=c(a⋅u^)u^=cProjL​(a)​

我們可以開始嘗試將 projection 寫成 matrix

我們以 R2 projection 為例,材料有這些,我們用 u1, u2 代表 unit vector

ProjL(x⃗)=(x⃗⋅u^)u^=(A2×2)x⃗ProjL:R2→R2u^=[u1u2],I2=[1001]Proj_L(\vec{x}) = (\vec{x}\cdot\hat{u})\hat{u} = (\mathbf{A}_{2\times2})\vec{x}\\ Proj_L: \mathbb{R}^2 \to \mathbb{R}^2\\ \hat{u} = \begin{bmatrix} u_1\\u_2\end{bmatrix}, \mathbf{I_2} = \begin{bmatrix} 1&0\\0&1\end{bmatrix}ProjL​(x)=(x⋅u^)u^=(A2×2​)xProjL​:R2→R2u^=[u1​u2​​],I2​=[10​01​]

現在將 projection 的 transformation apply 到 I2 裡面

A=[([10]⋅[u1u2])[u1u2]([01]⋅[u1u2])[u1u2]]=[u1[u1u2]u2[u1u2]]=[u12u1u2u1u2u22]\begin{aligned} \mathbf{A} &= \begin{bmatrix} \left( \begin{bmatrix}1\\0\end{bmatrix}\cdot \begin{bmatrix}u_1\\u_2\end{bmatrix} \right) \begin{bmatrix}u_1\\u_2\end{bmatrix} & \left( \begin{bmatrix}0\\1\end{bmatrix}\cdot \begin{bmatrix}u_1\\u_2\end{bmatrix} \right) \begin{bmatrix}u_1\\u_2\end{bmatrix} \end{bmatrix}\\ &= \begin{bmatrix} u_1\begin{bmatrix}u_1\\u_2\end{bmatrix}& u_2\begin{bmatrix}u_1\\u_2\end{bmatrix} \end{bmatrix}\\ &= \begin{bmatrix}u_1^2&u_1u_2\\u_1u_2&u_2^2\end{bmatrix} \end{aligned}A​=[([10​]⋅[u1​u2​​])[u1​u2​​]​([01​]⋅[u1​u2​​])[u1​u2​​]​]=[u1​[u1​u2​​]​u2​[u1​u2​​]​]=[u12​u1​u2​​u1​u2​u22​​]​

太棒了,現在只要有任何 projection,就可以套用 A 和 vector 的 product 來解決

舉個例子吧

L={c[21]∣c∈R}⇒v⃗=[21]⇒u^=[2515]\mathbf{L} = \begin{Bmatrix} c\begin{bmatrix}2\\1\end{bmatrix}\mid c\in \mathbb{R}\end{Bmatrix} \Rightarrow \vec{v} = \begin{bmatrix}2\\1\end{bmatrix} \Rightarrow \color{red}{\hat{u} = \begin{bmatrix}\frac{2}{\sqrt{5}}\\\frac{1}{\sqrt{5}}\end{bmatrix}}L={c[21​]∣c∈R​}⇒v=[21​]⇒u^=[5​2​5​1​​]

得到 u 我們就可以 apply 到 transformation matrix A 裡面了

A=[45252515]\mathbf{A} = \begin{bmatrix}\frac{4}{5}&\frac{2}{5}\\\frac{2}{5}&\frac{1}{5} \end{bmatrix}A=[54​52​​52​51​​]

這樣一來,我們可以求出 R2 平面上,"所有" vector 在 L 的 projection

ProjL(x⃗)=Ax⃗=[45252515]x⃗Proj_L(\vec{x}) = \mathbf{A}\vec{x} = \begin{bmatrix}\frac{4}{5}&\frac{2}{5}\\\frac{2}{5}&\frac{1}{5} \end{bmatrix} \vec{x}ProjL​(x)=Ax=[54​52​​52​51​​]x

我們用上一回 (2, 3) 的例子試看看,It works !

ProjL([23])=[45252515][23]=[2.81.4]Proj_L\left(\begin{bmatrix}2\\3\end{bmatrix}\right) = \begin{bmatrix}\frac{4}{5}&\frac{2}{5}\\\frac{2}{5}&\frac{1}{5} \end{bmatrix} \begin{bmatrix}2\\3\end{bmatrix} = \begin{bmatrix}2.8\\1.4\end{bmatrix}ProjL​([23​])=[54​52​​52​51​​][23​]=[2.81.4​]

https://youtu.be/lPWfIq5DzqI
https://youtu.be/gkyuLPzfDV0
https://youtu.be/lQn7fksaDq0
https://youtu.be/qkfODKmZ-x4