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
  • Deriving a method for determining inverses
  • Example of finding matrix inverse
  • Formula for 2x2 inverse
  • 3 x 3 determinant
  • n x n determinant
  • Determinants along other rows/cols
  • Rule of Sarrus of determinants

Was this helpful?

  1. Linear Algebra
  2. Matrix transformations

Finding inverses and determinants

PreviousInverse functions and transformationsNextMore Determinant Depth

Last updated 5 years ago

Was this helpful?

Deriving a method for determining inverses

我們在做 matrix 轉為 reduced row echelon form 的過程中

A=[1−1−1−123114]→[1−1−1012025]\mathbf{A} = \begin{bmatrix} 1&-1&-1\\-1&2&3\\1&1&4\end{bmatrix} \rightarrow \begin{bmatrix} 1&-1&-1\\0&1&2\\0&2&5\end{bmatrix}A=​1−11​−121​−134​​→​100​−112​−125​​

其實每個轉換,都是一個 transformation

例如上面消去 row 2 和 row 3 的第一個 element,可以表示成以下的 transformation

T[a1a2a3]→[a1a2+a1a3−a1]T \begin{bmatrix} a_1 \\ a_2\\ a_3\end{bmatrix} \rightarrow \begin{bmatrix} a_1 \\ a_2+a_1\\ a_3-a_1\end{bmatrix}T​a1​a2​a3​​​→​a1​a2​+a1​a3​−a1​​​

而這個 transformation 又可以表示成 matrix,我們知道可以用 identity matrix 當基底來建立

T(x⃗)=S1x⃗S1=[100010001]→[100110−101]T(\vec{x}) = \mathbf{S_1} \vec{x} \\ \mathbf{S_1} = \begin{bmatrix} 1&0&0\\0&1&0\\0&0&1\end{bmatrix} \rightarrow \begin{bmatrix} 1&0&0\\1&1&0\\-1&0&1\end{bmatrix}T(x)=S1​xS1​=​100​010​001​​→​11−1​010​001​​

也就是說,剛剛 A 在消去 row 2 和 row 3 的動作,其實就是

[S[1−11]S[−121]S[−134]]=  S1A=[100110−101][1−1−1−123114]=  [1−1−1012025]\begin{aligned} &\begin{bmatrix} \mathbf{S}\begin{bmatrix} 1\\-1\\1\end{bmatrix}& \mathbf{S}\begin{bmatrix} -1\\2\\1\end{bmatrix}& \mathbf{S}\begin{bmatrix} -1\\3\\4\end{bmatrix} \end{bmatrix}\\ =\,\, &\mathbf{S_1}\mathbf{A} \\ = &\begin{bmatrix} 1&0&0\\1&1&0\\-1&0&1\end{bmatrix} \begin{bmatrix} 1&-1&-1\\-1&2&3\\1&1&4\end{bmatrix} =\,\,\begin{bmatrix} 1&-1&-1\\0&1&2\\0&2&5\end{bmatrix} \end{aligned}==​​S​1−11​​​S​−121​​​S​−134​​​​S1​A​11−1​010​001​​​1−11​−121​−134​​=​100​−112​−125​​​

我們可以繼續對未完成 reduced row echelon form 的 matrix 進行簡化

[1−1−1012025]→[101012001]\begin{bmatrix} 1&-1&-1\\0&1&2\\0&2&5\end{bmatrix} \rightarrow \begin{bmatrix} 1&0&1\\0&1&2\\0&0&1\end{bmatrix}​100​−112​−125​​→​100​010​121​​

這次的簡化等於

T[a1a2a3]→[a1+a2a2a3−2a2]⇒S2=[1100100−21]T \begin{bmatrix} a_1 \\ a_2\\ a_3\end{bmatrix} \rightarrow \begin{bmatrix} a_1+a_2 \\ a_2\\ a_3-2a_2\end{bmatrix} \Rightarrow \mathbf{S_2} = \begin{bmatrix} 1&1&0\\0&1&0\\0&-2&1\end{bmatrix}T​a1​a2​a3​​​→​a1​+a2​a2​a3​−2a2​​​⇒S2​=​100​11−2​001​​

而這個 S2 apply 在 S1*A 上

S2(S1A)=[1100100−21][1−1−1012025]=[101012001]\mathbf{S_2}(\mathbf{S_1}\mathbf{A}) = \begin{bmatrix} 1&1&0\\0&1&0\\0&-2&1\end{bmatrix} \begin{bmatrix} 1&-1&-1\\0&1&2\\0&2&5\end{bmatrix} =\begin{bmatrix} 1&0&1\\0&1&2\\0&0&1\end{bmatrix}S2​(S1​A)=​100​11−2​001​​​100​−112​−125​​=​100​010​121​​

還是可以繼續化簡第三行

[101012001]→[100010001]\begin{bmatrix} 1&0&1\\0&1&2\\0&0&1\end{bmatrix} \rightarrow \begin{bmatrix} 1&0&0\\0&1&0\\0&0&1\end{bmatrix}​100​010​121​​→​100​010​001​​
T[a1a2a3]→[a1−a3a2−2a3a3]⇒S3=[10−101−2001]T \begin{bmatrix} a_1 \\ a_2\\ a_3\end{bmatrix} \rightarrow \begin{bmatrix} a_1-a_3 \\ a_2-2a_3\\ a_3\end{bmatrix} \Rightarrow \mathbf{S_3} = \begin{bmatrix} 1&0&-1\\0&1&-2\\0&0&1\end{bmatrix}T​a1​a2​a3​​​→​a1​−a3​a2​−2a3​a3​​​⇒S3​=​100​010​−1−21​​
S3(S2(S1A))=[10−101−2001][101012001]=[100010001]\mathbf{S_3}(\mathbf{S_2}(\mathbf{S_1}\mathbf{A})) = \begin{bmatrix} 1&0&-1\\0&1&-2\\0&0&1\end{bmatrix} \begin{bmatrix} 1&0&1\\0&1&2\\0&0&1\end{bmatrix} =\begin{bmatrix} 1&0&0\\0&1&0\\0&0&1\end{bmatrix}S3​(S2​(S1​A))=​100​010​−1−21​​​100​010​121​​=​100​010​001​​

可以發現原來 S3 × S2 × S1 的 Product 就是 A 的 inverse matrix

S3S2S1A=IA−1A=I\begin{aligned} \mathbf{S_3S_2S_1A} &= \mathbf{I}\\ \mathbf{A^{-1}A}&= \mathbf{I} \end{aligned}S3​S2​S1​AA−1A​=I=I​

但其實不用每次找 inverse function / inverse matrix 都搞的這麼麻煩

上面這樣做只是為了了解尋找 inverse matrix 的原理而已

AIS1AS1IS2S1AS2S1IS3S2S1AS3S2S1I⇒  IA−1\begin{aligned} &\mathbf{A}&&\mathbf{I}\\ &\mathbf{S_1A}&&\mathbf{S_1I}\\ &\mathbf{S_2S_1A}&&\mathbf{S_2S_1I}\\ &\mathbf{S_3S_2S_1A}&&\mathbf{S_3S_2S_1I}\\ \Rightarrow\,\, &\mathbf{I}&&\mathbf{A^{-1}}\\ \end{aligned}⇒​AS1​AS2​S1​AS3​S2​S1​AI​​IS1​IS2​S1​IS3​S2​S1​IA−1​

我們同時對 matrix A 和 identity matrix 做同樣的 row operation transformation

發現當 A 為 invertible 時 (可以變成 Identity matrix),對 I 做相同的簡化運算,可以得到 inverse matrix

[A∣I]→⋯→[I∣A−1]\begin{bmatrix} \mathbf{A} \mid \mathbf{I}\end{bmatrix} \rightarrow \cdots \rightarrow \begin{bmatrix} \mathbf{I} \mid \mathbf{A^{-1}}\end{bmatrix}[A∣I​]→⋯→[I∣A−1​]

Example of finding matrix inverse

我們實際來運用剛剛發現的方式,尋找 inverse matrix

A=[1−1−1−123114]\mathbf{A} = \begin{bmatrix} 1&-1&-1\\-1&2&3\\1&1&4\end{bmatrix}A=​1−11​−121​−134​​

首先將 A 和 I 畫在一起

[A∣I]=[1−1−1100−123010114001]\begin{bmatrix} \mathbf{A} \mid \mathbf{I}\end{bmatrix} = \begin{bmatrix} \begin{array}{ccc|ccc} 1&-1&-1&1&0&0\\-1&2&3&0&1&0\\1&1&4&0&0&1 \end{array} \end{bmatrix}[A∣I​]=​1−11​−121​−134​100​010​001​​​

先對 A 清空第一行,同樣的運算一樣 apply 到隔壁的 identity matrix

[S1A∣S1]=[1−1−1100012110025−101]\begin{bmatrix} \mathbf{S_1A} \mid \mathbf{S_1}\end{bmatrix} = \begin{bmatrix} \begin{array}{ccc|ccc} 1&-1&-1&1&0&0\\0&1&2&1&1&0\\0&2&5&-1&0&1 \end{array} \end{bmatrix}[S1​A∣S1​​]=​100​−112​−125​11−1​010​001​​​

再來清空第二行

[S2S1A∣S2S1]=[101210012110001−3−21]\begin{bmatrix} \mathbf{S_2S_1A} \mid \mathbf{S_2S_1}\end{bmatrix} = \begin{bmatrix} \begin{array}{ccc|ccc} 1&0&1&2&1&0\\0&1&2&1&1&0\\0&0&1&-3&-2&1 \end{array} \end{bmatrix}[S2​S1​A∣S2​S1​​]=​100​010​121​21−3​11−2​001​​​

最後是第三行

[S3S2S1A∣S3S2S1]=[I∣A−1]=[10053−101075−2001−3−21]\begin{bmatrix} \mathbf{S_3S_2S_1A} \mid \mathbf{S_3S_2S_1}\end{bmatrix} = \begin{bmatrix} \mathbf{I} \mid \mathbf{A^{-1}}\end{bmatrix} = \begin{bmatrix} \begin{array}{ccc|ccc} 1&0&0&5&3&-1\\0&1&0&7&5&-2\\0&0&1&-3&-2&1 \end{array} \end{bmatrix}[S3​S2​S1​A∣S3​S2​S1​​]=[I∣A−1​]=​100​010​001​57−3​35−2​−1−21​​​

如此一來我們就找到 A 的 inverse matrix

A−1=[53−175−2−3−21]\mathbf{A^{-1}} = \begin{bmatrix} 5&3&-1\\7&5&-2\\-3&-2&1 \end{bmatrix}A−1=​57−3​35−2​−1−21​​

Formula for 2x2 inverse

我們來找出所有 2 × 2 matrix 的 inverse matrix

A=[abcd]⇒[ab10cd01]\mathbf{A} = \begin{bmatrix} a&b\\c&d\end{bmatrix} \Rightarrow \begin{bmatrix} \begin{array}{cc|cc} a&b&1&0\\c&d&0&1\end{array}\end{bmatrix}A=[ac​bd​]⇒[ac​bd​10​01​​]

首先我們要讓 c 變為 0,等於要對 row vectors 執行底下這個 transformation

T1([c1c2])=[c1ac2−cc1]T_1\left(\begin{bmatrix} c_1 \\ c_2 \end{bmatrix}\right) = \begin{bmatrix} c_1 \\ ac_2 - cc_1 \end{bmatrix}T1​([c1​c2​​])=[c1​ac2​−cc1​​]

第一列保留不變,第二列試著將 c 消為 0

[ab10cd01]→[ab100ad−bc−ca]\begin{bmatrix} \begin{array}{cc|cc} a&b&1&0\\c&d&0&1\end{array}\end{bmatrix} \rightarrow \begin{bmatrix} \begin{array}{cc|cc} a&b&1&0\\0&ad-bc&-c&a\end{array}\end{bmatrix}[ac​bd​10​01​​]→[a0​bad−bc​1−c​0a​​]

接著我們要讓 b 變為 0

T2([c1c2])=[c1(ad−bc)−c2(b)c2]T_2\left(\begin{bmatrix} c_1 \\ c_2 \end{bmatrix}\right) = \begin{bmatrix} c_1(ad-bc)-c_2(b) \\ c_2 \end{bmatrix}T2​([c1​c2​​])=[c1​(ad−bc)−c2​(b)c2​​]

第二列保留不變,第一列試著將 b 消為 0

[ab100ad−bc−ca]→[a(ad−bc)(b)(ad−bc)−(ad−bc)(b)ad−bc+bc−ab0ad−bc−ca]→[a(ad−bc)0ad−ab0ad−bc−ca]\begin{aligned} \begin{bmatrix} \begin{array}{cc|cc} a&b&1&0\\0&ad-bc&-c&a\end{array}\end{bmatrix} &\rightarrow \begin{bmatrix} \begin{array}{cc|cc} a(ad-bc)&(b)(ad-bc)-(ad-bc)(b)&ad-bc+bc&-ab\\0&ad-bc&-c&a\end{array}\end{bmatrix}\\ &\rightarrow \begin{bmatrix} \begin{array}{cc|cc} a(ad-bc)&0&ad&-ab\\0&ad-bc&-c&a\end{array}\end{bmatrix} \end{aligned}[a0​bad−bc​1−c​0a​​]​→[a(ad−bc)0​(b)(ad−bc)−(ad−bc)(b)ad−bc​ad−bc+bc−c​−aba​​]→[a(ad−bc)0​0ad−bc​ad−c​−aba​​]​

最後我們要讓 A 變為 identity matrix 完成 reduced row echelon form

T3([c1c2])=[c1a(ad−bc)c2ad−bc]T_3\left(\begin{bmatrix} c_1 \\ c_2 \end{bmatrix}\right) = \begin{bmatrix} \frac{c_1}{a(ad-bc)} \\ \frac{c_2}{ad-bc} \end{bmatrix}T3​([c1​c2​​])=[a(ad−bc)c1​​ad−bcc2​​​]

於是我們得到

[a(ad−bc)0ad−ab0ad−bc−ca]→[10ada(ad−bc)−aba(ad−bc)01−cad−bcaad−bc]→[10dad−bc−bad−bc01−cad−bcaad−bc]=[I∣A−1]\begin{aligned} \begin{bmatrix} \begin{array}{cc|cc} a(ad-bc)&0&ad&-ab\\0&ad-bc&-c&a\end{array}\end{bmatrix} &\rightarrow \begin{bmatrix} \begin{array}{cc|cc} 1&0&\frac{ad}{a(ad-bc)}&\frac{-ab}{a(ad-bc)}\\0&1&-\frac{c}{ad-bc}&\frac{a}{ad-bc}\end{array}\end{bmatrix} \\ &\rightarrow \begin{bmatrix} \begin{array}{cc|cc} 1&0&\frac{d}{ad-bc}&\frac{-b}{ad-bc}\\0&1&-\frac{c}{ad-bc}&\frac{a}{ad-bc}\end{array}\end{bmatrix} = \begin{bmatrix} \mathbf{I} \mid \mathbf{A^{-1}} \end{bmatrix} \end{aligned}[a(ad−bc)0​0ad−bc​ad−c​−aba​​]​→[10​01​a(ad−bc)ad​−ad−bcc​​a(ad−bc)−ab​ad−bca​​​]→[10​01​ad−bcd​−ad−bcc​​ad−bc−b​ad−bca​​​]=[I∣A−1​]​

我們可以將 inverse matrix 進一步化簡,每個分母都是 ad - bc ,我們將他提出

A−1=[dad−bc−bad−bc−cad−bcaad−bc]=1ad−bc[d−b−ca]\mathbf{A^{-1}} = \begin{bmatrix} \frac{d}{ad-bc}&\frac{-b}{ad-bc}\\-\frac{c}{ad-bc}&\frac{a}{ad-bc} \end{bmatrix} = \frac{1}{ad-bc} \begin{bmatrix} d&-b\\-c&a \end{bmatrix}A−1=[ad−bcd​−ad−bcc​​ad−bc−b​ad−bca​​]=ad−bc1​[d−c​−ba​]

而這個就是所有 2 × 2 matrix 的 inverse matrix

可以記成 d 和 a 互換, b 和 c 變負

但我們知道,只有 matrix 為 invertible 才會有 inverse function

這個公式剛好可以看出 matrix 是否為 invertible

只要公式得出的結果為 undefined ,則 matrix 即為 non-invertible

而關鍵就在於 ad - bc 等於 0 的時候,公式結果即為 undefined

ad−bc≠0  ⟺  A is invertiblead -bc \neq 0 \iff \mathbf{A} \text{ is invertible}ad−bc=0⟺A is invertible

而這個 ad - bc 有一個名稱,叫作 determinant

det⁡(A)=∣A∣=∣[abcd]∣=∣abcd∣=ad−bc\det(\mathbf{A}) = \left\lvert \mathbf{A} \right\rvert = \left\lvert \begin{bmatrix} a&b\\c&d\end{bmatrix} \right\rvert = \left\lvert \begin{matrix} a&b\\c&d\end{matrix} \right\rvert = ad - bcdet(A)=∣A∣=​[ac​bd​]​=​ac​bd​​=ad−bc

所以公式可以再一次簡化

A−1=1det⁡(A)[d−b−ca]\mathbf{A^{-1}} = \frac{1}{\det(\mathbf{A})} \begin{bmatrix} d&-b\\-c&a\end{bmatrix}A−1=det(A)1​[d−c​−ba​]
  • 舉個可以 invertible 的例子

det⁡(B)=∣1234∣=1×4−3×2=4−6=−2 (invertible)B−1=1−2[4−2−31]=[−21321−2]\det(\mathbf{B}) = \left\lvert \begin{matrix} 1&2\\3&4\end{matrix} \right\rvert = 1 \times4-3\times2 = 4-6=-2 \text{ (invertible)} \\ \mathbf{B^{-1}} = \frac{1}{-2}\begin{bmatrix} 4&-2\\-3&1\end{bmatrix} = \begin{bmatrix} -2&1\\\frac{3}{2}&\frac{1}{-2}\end{bmatrix}det(B)=​13​24​​=1×4−3×2=4−6=−2 (invertible)B−1=−21​[4−3​−21​]=[−223​​1−21​​]
  • 舉個不可以 invertible 的例子

det⁡(C)=∣1236∣=1×6−3×2=6−6=0 (non-invertible)\det(\mathbf{C}) = \left\lvert \begin{matrix} 1&2\\3&6\end{matrix} \right\rvert = 1 \times 6 - 3 \times 2 = 6- 6 = 0 \text{ (non-invertible)}det(C)=​13​26​​=1×6−3×2=6−6=0 (non-invertible)

的確,column 2 可以表示為 column 1 * 2

代表他們是 linear dependence,沒辦法 one-to-one,所以為 non invertible,沒有 inverse matrix

3 x 3 determinant

在 generalize determinant 公式前,我們先來試算 3 by 3 matrix 的 determinant

因為我們知道 determinant 很重要,可以快速看出一個 matrix 是否為 invertible

A=[a11a12a13a21a22a23a31a32a33]\mathbf{A} = \begin{bmatrix} a_{11}&a_{12}&a_{13}\\a_{21}&a_{22}&a_{23}\\a_{31}&a_{32}&a_{33}\end{bmatrix}A=​a11​a21​a31​​a12​a22​a32​​a13​a23​a33​​​
det⁡(A)=a11∣a22a23a32a33∣−a12∣a21a23a31a33∣+a13∣a21a22a31a32∣\det(\mathbf{A}) = a_{11}\left\lvert\begin{matrix}a_{22}&a_{23}\\a_{32}&a_{33}\end{matrix}\right\rvert - a_{12}\left\lvert\begin{matrix}a_{21}&a_{23}\\a_{31}&a_{33}\end{matrix}\right\rvert + a_{13}\left\lvert\begin{matrix}a_{21}&a_{22}\\a_{31}&a_{32}\end{matrix}\right\rvertdet(A)=a11​​a22​a32​​a23​a33​​​−a12​​a21​a31​​a23​a33​​​+a13​​a21​a31​​a22​a32​​​

看起來很抽象,我們實際操作一個 matrix 看看

C=[1242−13401]\mathbf{C} = \begin{bmatrix} 1&2&4\\2&-1&3\\4&0&1\end{bmatrix}C=​124​2−10​431​​
det⁡(C)=1∣−1−301∣−2∣2341∣+4∣2−140∣=1⋅(−1)−2⋅(−10)+4⋅(4)=−1+20+16=35\begin{aligned} \det(\mathbf{C}) &= 1\left\lvert\begin{matrix}-1&-3\\0&1\end{matrix}\right\rvert - 2\left\lvert\begin{matrix}2&3\\4&1\end{matrix}\right\rvert + 4\left\lvert\begin{matrix}2&-1\\4&0\end{matrix}\right\rvert \\ &= 1 \cdot (-1) - 2\cdot(-10)+4\cdot(4) \\ &= -1 +20 + 16 \\ &= 35 \end{aligned}det(C)​=1​−10​−31​​−2​24​31​​+4​24​−10​​=1⋅(−1)−2⋅(−10)+4⋅(4)=−1+20+16=35​

所以 C = invertible

n x n determinant

學會 3 × 3 之後,來試試看 n × n 的格式

An×n=[a11a12⋯a1na21⋯a2n⋮⋱⋮an1⋯⋯ann]\mathbf{A}_{n \times n } = \begin{bmatrix} a_{11} & a_{12} &\cdots &a_{1n}\\ a_{21} &\cdots&&a_{2n} \\ \vdots& &\ddots&\vdots \\ a_{n1}&\cdots&\cdots&a_{nn} \end{bmatrix}An×n​=​a11​a21​⋮an1​​a12​⋯⋯​⋯⋱⋯​a1n​a2n​⋮ann​​​

我們定義一個矩陣 Aij 代表 A 去掉 i row 和 j column 時的樣子

Def: Aij=(n−1)×(n−1) matrix you get if you "ignore" the ith row and the jth column of A\begin{aligned} \text{Def: }\mathbf{A}_{ij}= &(n-1) \times (n-1) \text{ matrix you get}\\ & \text{ if you "ignore" the } i^{th} \text{ row and the } j^{th} \text{ column of }\mathbf{A} \end{aligned}Def: Aij​=​(n−1)×(n−1) matrix you get if you "ignore" the ith row and the jth column of A​

看起來很抽象所以舉個例子

A=[1242−13401]A11=[−1301],A12=[2341],A13=[2−140]det⁡(A)=a11⋅A11−a12⋅A12+a13⋅A13\begin{aligned} \mathbf{A} &= \begin{bmatrix} 1&2&4\\2&-1&3\\4&0&1\end{bmatrix} \\ \mathbf{A}_{11}&= \begin{bmatrix} -1 &3\\0&1\end{bmatrix}, \mathbf{A}_{12}= \begin{bmatrix} 2&3\\4&1\end{bmatrix}, \mathbf{A}_{13}= \begin{bmatrix} 2&-1\\4&0\end{bmatrix} \\ \det(\mathbf{A}) &=a_{11} \cdot \mathbf{A}_{11} - a_{12} \cdot \mathbf{A}_{12} + a_{13} \cdot \mathbf{A}_{13} \end{aligned}AA11​det(A)​=​124​2−10​431​​=[−10​31​],A12​=[24​31​],A13​=[24​−10​]=a11​⋅A11​−a12​⋅A12​+a13​⋅A13​​

接著就可以來定義 n × n 的 determinant:

det⁡(An×n)=a11det⁡(A11)−a12det⁡(A12)+a13det⁡(A13)−+⋯±a1ndet⁡(A1n)\det(\mathbf{A}_{n \times n}) = a_{11} \det(\mathbf{A_{11}}) - a_{12} \det(\mathbf{A_{12}}) + a_{13} \det(\mathbf{A_{13}}) - + \cdots \pm a_{1n}\det(A_{1n})det(An×n​)=a11​det(A11​)−a12​det(A12​)+a13​det(A13​)−+⋯±a1n​det(A1n​)

這個定義就是個 recursive definition ,可以一直往下 solve 到 2 × 2 matrix

我們來試個 4 × 4 的例子

∣1234102001232300∣=1∣020123300∣−2∣120023200∣+3∣100013230∣−4∣102012230∣\left\lvert \begin{matrix} 1&2&3&4\\1&0&2&0\\0&1&2&3\\2&3&0&0\end{matrix}\right\rvert = 1\left\lvert \begin{matrix} 0&2&0\\1&2&3\\3&0&0 \end{matrix} \right\rvert - 2\left\lvert \begin{matrix} 1&2&0\\0&2&3\\2&0&0 \end{matrix} \right\rvert + 3\left\lvert \begin{matrix} 1&0&0\\0&1&3\\2&3&0 \end{matrix} \right\rvert - 4\left\lvert \begin{matrix} 1&0&2\\0&1&2\\2&3&0 \end{matrix} \right\rvert​1102​2013​3220​4030​​=1​013​220​030​​−2​102​220​030​​+3​102​013​030​​−4​102​013​220​​

接著可以往下 solve 3 × 3 的矩陣,等於

1(0∣2300∣−2∣1330∣+0∣1230∣)−2(1∣2300∣−2∣0320∣+0∣0220∣)+3(1∣1330∣−0∣0320∣+0∣0123∣)−4(1∣1230∣−0∣0220∣+2∣0123∣)\begin{aligned} 1 \left( 0\left\lvert \begin{matrix} 2&3\\0&0 \end{matrix} \right\rvert -2 \left\lvert \begin{matrix} 1&3\\3&0 \end{matrix} \right\rvert +0 \left\lvert \begin{matrix} 1&2\\3&0 \end{matrix} \right\rvert \right) \\ -2 \left( 1\left\lvert \begin{matrix} 2&3\\0&0 \end{matrix} \right\rvert -2 \left\lvert \begin{matrix} 0&3\\2&0 \end{matrix} \right\rvert +0 \left\lvert \begin{matrix} 0&2\\2&0 \end{matrix} \right\rvert \right) \\ +3 \left( 1\left\lvert \begin{matrix} 1&3\\3&0 \end{matrix} \right\rvert -0 \left\lvert \begin{matrix} 0&3\\2&0 \end{matrix} \right\rvert +0 \left\lvert \begin{matrix} 0&1\\2&3 \end{matrix} \right\rvert \right) \\ -4 \left( 1\left\lvert \begin{matrix} 1&2\\3&0 \end{matrix} \right\rvert -0 \left\lvert \begin{matrix} 0&2\\2&0 \end{matrix} \right\rvert +2 \left\lvert \begin{matrix} 0&1\\2&3 \end{matrix} \right\rvert \right) \end{aligned}1(0​20​30​​−2​13​30​​+0​13​20​​)−2(1​20​30​​−2​02​30​​+0​02​20​​)+3(1​13​30​​−0​02​30​​+0​02​13​​)−4(1​13​20​​−0​02​20​​+2​02​13​​)​

接著就可以解掉 2 × 2 的矩陣了!

1(0+(−2)×(−9)+0)−2(0+(−2)×(−6)+0)+3(1×(−9)−0+0)−4(1×(−6)−0+2×(−2))\begin{aligned} 1 \left( 0+(-2)\times(-9)+0 \right) \\ -2 \left(0+(-2)\times(-6)+0 \right)\\ +3 \left(1\times(-9)-0+0\right) \\ -4 \left( 1 \times(-6) -0 +2 \times(-2) \right) \end{aligned}1(0+(−2)×(−9)+0)−2(0+(−2)×(−6)+0)+3(1×(−9)−0+0)−4(1×(−6)−0+2×(−2))​

得到答案

1(18)−2(12)+3(−9)−4(−6−4)=  18−24−27+40=  7\begin{aligned} &1(18) -2 (12)+3(-9)-4(-6-4)\\ =\,\,&18 -24-27 +40 \\ =\,\,& 7 \end{aligned}==​1(18)−2(12)+3(−9)−4(−6−4)18−24−27+407​

也就是說,這個矩陣是 invertible 的

Determinants along other rows/cols

其實求 determinant 不是只能展開第一列,可以從任何一列或一行來展開

也就是說我們可以選擇很多 0 的那一列 (行) 來展開

只是我們要注意展開的正負符號

∣+−+−⋯−+−+⋯+−+−⋯−+−+⋯⋮⋮⋮⋮⋱∣\left\lvert \begin{matrix}+&-&+&-&\cdots\\-&+&-&+&\cdots\\+&-&+&-&\cdots\\-&+&-&+&\cdots\\\vdots&\vdots&\vdots&\vdots&\ddots\end{matrix}\right\rvert​+−+−⋮​−+−+⋮​+−+−⋮​−+−+⋮​⋯⋯⋯⋯⋱​​

其實就是在前面加上 row 和 column 判斷

(−1)row+column(-1)^{\text{row} + \text{column}}(−1)row+column

在第一列第一行的就是正號

(−1)1+1=(−1)2=1(-1)^{1+1} = (-1)^2 = 1(−1)1+1=(−1)2=1

我們以上面的例子來做看看,我們展開第二列,因為有兩個 0

∣1234102001232300∣=−1∣234123300∣−2∣124013230∣\left\lvert \begin{matrix} 1&2&3&4\\ \color{red}{1}&\color{red}{0}&\color{red}{2}&\color{red}{0} \\0&1&2&3\\2&3&0&0\end{matrix}\right\rvert = -1 \left\lvert \begin{matrix} 2&3&4\\1&2&3\\3&0&0\end{matrix}\right\rvert -2 \left\lvert \begin{matrix} 1&2&4\\0&1&3\\2&3&0\end{matrix}\right\rvert​1102​2013​3220​4030​​=−1​213​320​430​​−2​102​213​430​​

再來第一個 3 × 3 當然展開第三列,第二個我們展開第二列好了

=−1(3×∣3423∣)−2(1∣1420∣−3∣1223∣)= -1\left(3\times \left\lvert \begin{matrix} 3&4\\2&3\end{matrix}\right\rvert\right) -2 \left(1\left\lvert \begin{matrix} 1&4\\2&0\end{matrix}\right\rvert -3\left\lvert \begin{matrix} 1&2\\2&3\end{matrix}\right\rvert \right)=−1(3×​32​43​​)−2(1​12​40​​−3​12​23​​)

我們比剛剛更快的還要求到 determinant

=((−1)×3)−(2×(−8+3))=(−3)−(−10)=7\begin{aligned} &= ((-1) \times 3) - (2\times(-8 +3))\\ &= (-3) - (-10) \\ &=7 \end{aligned}​=((−1)×3)−(2×(−8+3))=(−3)−(−10)=7​

Rule of Sarrus of determinants

這邊還有一個方法可以用來求 3 × 3 的 determinant ,叫作 Rule of Sarrus

我們先將一般的 3 × 3 determinant 求出

∣abcdefghi∣=a∣efhi∣−b∣dfgi∣+c∣degh∣=a(ei−fh)−b(di−fg)+c(dh−eg)=aei−afh−bdi+bfg+cdh−ceg=(aei+bfg+cdh)+(−afh−bdi−ceg)\begin{aligned} \left\lvert \begin{matrix} a&b&c\\d&e&f\\g&h&i \end{matrix}\right\rvert &= a \left\lvert \begin{matrix} e&f\\h&i \end{matrix}\right\rvert - b \left\lvert \begin{matrix} d&f\\g&i \end{matrix}\right\rvert + c \left\lvert \begin{matrix} d&e\\g&h \end{matrix}\right\rvert \\ &= a(ei-fh) - b(di-fg) + c(dh-eg)\\ &= aei - afh -bdi + bfg +cdh - ceg \\ &= \color{blue}{(aei+bfg+cdh)} + \color{red}{(-afh-bdi-ceg)} \end{aligned}​adg​beh​cfi​​​=a​eh​fi​​−b​dg​fi​​+c​dg​eh​​=a(ei−fh)−b(di−fg)+c(dh−eg)=aei−afh−bdi+bfg+cdh−ceg=(aei+bfg+cdh)+(−afh−bdi−ceg)​

仔細觀察,等於我們將矩陣多畫出兩行,然後將紅色部分 + 藍色部分

一樣來舉個例子

A=[1242−1340−1]\mathbf{A} = \begin{bmatrix} 1&2&4\\2&-1&3\\4&0&-1\end{bmatrix}A=​124​2−10​43−1​​
det⁡(A)=∣1242−1340−1∣122−140=(1⋅(−1)⋅(−1))+(2⋅3⋅4)+(4⋅2⋅0)−(4⋅(−1)⋅4)−(1⋅3⋅0)−(2⋅2⋅−1)=1+24+0+16−0+4=45\begin{aligned} \det(\mathbf{A}) &= \left\lvert \begin{matrix} 1&2&4\\2&-1&3\\4&0&-1\end{matrix}\right\rvert \begin{matrix} 1&2\\2&-1\\4&0\end{matrix} \\\\ &= \color{red}{(1 \cdot (-1) \cdot(-1)) + (2\cdot3\cdot4) + (4\cdot2\cdot0)} \color{blue}{- (4\cdot(-1)\cdot4) - (1\cdot3\cdot0) - (2\cdot2\cdot-1)} \\ &= 1+24+0 +16-0+4 \\ &= 45 \end{aligned}det(A)​=​124​2−10​43−1​​124​2−10​=(1⋅(−1)⋅(−1))+(2⋅3⋅4)+(4⋅2⋅0)−(4⋅(−1)⋅4)−(1⋅3⋅0)−(2⋅2⋅−1)=1+24+0+16−0+4=45​

https://youtu.be/6DpzCKJBsz0
https://youtu.be/r9aTLTN16V4
https://youtu.be/eEUK_ThrHuQ
https://youtu.be/0c7dt2SQfLw
https://youtu.be/H9BWRYJNIv4
https://youtu.be/nu87kfmwNfU
https://youtu.be/4xFIi0JF2AM