光的世界︰派生科學計算三

從『聯立方程式』 Simultaneous equations 、『線性方程組』 System of linear equations 、『矩陣』 Matrix 、『行列式』 Determinant …… 觀之,『高斯消去法』 Gaussian Elimination 歷史

History

The method of Gaussian elimination appears in the Chinese mathematical text Chapter Eight Rectangular Arrays of The Nine Chapters on the Mathematical Art. Its use is illustrated in eighteen problems, with two to five equations. The first reference to the book by this title is dated to 179 CE, but parts of it were written as early as approximately 150 BCE.[1][2] It was commented on by Liu Hui in the 3rd century.

The method in Europe stems from the notes of Isaac Newton.[3][4] In 1670, he wrote that all the algebra books known to him lacked a lesson for solving simultaneous equations, which Newton then supplied. Cambridge University eventually published the notes as Arithmetica Universalis in 1707 long after Newton left academic life. The notes were widely imitated, which made (what is now called) Gaussian elimination a standard lesson in algebra textbooks by the end of the 18th century. Carl Friedrich Gauss in 1810 devised a notation for symmetric elimination that was adopted in the 19th century by professional hand computers to solve the normal equations of least-squares problems.[5] The algorithm that is taught in high school was named for Gauss only in the 1950s as a result of confusion over the history of the subject.[6]

Some authors use the term Gaussian elimination to refer only to the procedure until the matrix is in echelon form, and use the term Gauss-Jordan elimination to refer to the procedure which ends in reduced echelon form. The name is used because it is a variation of Gaussian elimination as described by Wilhelm Jordan in 1888. However, the method also appears in an article by Clasen published in the same year. Jordan and Clasen probably discovered Gauss–Jordan elimination independently.[7]

 

久遠矣。或許很多人不曉此法漢代《九章算術》中已有,甚或不知作注的『Liu Hui』劉徽是何許人也!!而後歷經數百代凝鑄成

線性代數

線性代數是關於向量空間線性映射的一個數學分支。它包括對線、面和子空間的研究,同時也涉及到所有的向量空間的一般性質。

坐標滿足滿足線性方程的點集形成 n 維空間中的一個超平面n 個超平面相交於一點的條件是線性代數研究的一個重要焦點。此項研究源於包含多個未知數的線性方程組。這樣的方程組可以很自然地表示為矩陣和向量的形式。[1][2]

線性代數既是純數學也是應用數學的核心。例如,放寬向量空間的公理就產生了抽象代數,也就出現了若干推廣。泛函分析研究無窮維情形的向量空間理論。線性代數與微積分結合,使得微分方程線性系統的求解更加便利。 線性代數的理論已被泛化為算子理論

線性代數的方法還用在解析幾何工程物理自然科學計算機科學計算機動畫社會科學(尤其是經濟學)中。由於線性代數是一套完善的理論,非線性數學模型通常可以被近似為線性模型。

250px-Linear_subspaces_with_shading.svg

三維歐氏空間R3是一個向量空間,而通過原點的線及平面是R3的向量子空間

歷史

線性代數的研究最初出現於對行列式的研究上。行列式當時被用來求解線性方程組。萊布尼茨在1693年使用了行列式。隨後,加布里爾·克拉默在1750年推導出求解線性方程組的克萊姆法則。然後,高斯利用高斯消元法發展出求解線性系統的理論。這也被列為大地測量學的一項進展。[3][4]

現代線性代數的歷史可以上溯到19世紀中期的英國。1843年,哈密頓發現了四元數。1844年,赫爾曼·格拉斯曼發表了他的著作《線性外代數》(Die lineare Ausdehnungslehre),包括了今日線性代數的一些主題。1848年,詹姆斯·西爾維斯特引入了矩陣(matrix),該詞是「子宮」的拉丁語。阿瑟·凱萊在研究線性變換時引入了矩陣乘法和轉置的概念。很重要的是,凱萊使用了一個字母來代表一個矩陣,因此將矩陣當做了聚合對象。他也意識到矩陣和行列式之間的聯繫。[3]

不過除了這些早期的文獻以外.線性代數主要是在二十世紀發展的。在抽象代數環論開發之前,矩陣只有模糊不清的定義。隨著狹義相對論的到來,很多開拓者發現了線性代數的微妙。進一步的,解偏微分方程克萊姆法則的例行應用導致了大學的標準教育中包括了線性代數。例如,E.T. Copson寫到:

當我在1922年到愛丁堡做年輕的講師的時候,我驚奇的發現了不同於牛津的課程。這裡包括了我根本就不知道的主題如勒貝格積分矩陣論數值分析黎曼幾何
——E.T. Copson,《偏微分方程》前言, 1973

1882年,Hüseyin Tevfik Pasha寫了一本書,名為《線性代數》。[5][6]第一次現代化精確定義向量空間是在1888年,由朱塞佩·皮亞諾提出。在1888年,弗蘭西斯·高爾頓還發起了相關係數的應用。經常有多於一個隨機變量出現並且它們可以互相關。在多變元隨機變量的統計分析中,相關矩陣是自然的工具。所以這種隨機向量的統計研究幫助了矩陣用途的開發。到1900年,一種有限維向量空間的線性變換理論被提出。在20世紀上半葉,許多前幾世紀的想法和方法被總結成抽象代數,線性代數第一次有了它的現代形式。矩陣在量子力學狹義相對論統計學上的應用幫助線性代數的主題超越了純數學的範疇。計算機的發展導致更多地研究致力於有關高斯消元法和矩陣分解的有效算法上。線性代數成為了數字模擬和模型的基本工具。[3]

 

其論述能不厚重乎?其內容能不範圍廣闊耶!系統符號混雜、概念層出不窮、各種分支頻起旁徵博引,豈不目不暇給望洋興嘆呀!!

此處藉著『高斯消去法』例子為範︰

Gaussian elimination

Example of the algorithm

Suppose the goal is to find and describe the set of solutions to the following system of linear equations:

{\begin{alignedat}{7}2x&&\;+\;&&y&&\;-\;&&z&&\;=\;&&8&\qquad (L_{1})\\-3x&&\;-\;&&y&&\;+\;&&2z&&\;=\;&&-11&\qquad (L_{2})\\-2x&&\;+\;&&y&&\;+\;&&2z&&\;=\;&&-3&\qquad (L_{3})\end{alignedat}}

The table below is the row reduction process applied simultaneously to the system of equations, and its associated augmented matrix. In practice, one does not usually deal with the systems in terms of equations but instead makes use of the augmented matrix, which is more suitable for computer manipulations. The row reduction procedure may be summarized as follows: eliminate x from all equations below  L_{1}, and then eliminate y from all equations below  L_{2}. This will put the system into triangular form. Then, using back-substitution, each unknown can be solved for.

System of equations Row operations Augmented matrix
{\begin{alignedat}{7}2x&&\;+\;&&y&&\;-\;&&z&&\;=\;&&8&\\-3x&&\;-\;&&y&&\;+\;&&2z&&\;=\;&&-11&\\-2x&&\;+\;&&y&&\;+\;&&2z&&\;=\;&&-3&\end{alignedat}}   \left[{\begin{array}{ccc|c}2&1&-1&8\\-3&-1&2&-11\\-2&1&2&-3\end{array}}\right]
{\begin{alignedat}{7}2x&&\;+&&y&&\;-&&\;z&&\;=\;&&8&\\&&&&{\frac {1}{2}}y&&\;+&&\;{\frac {1}{2}}z&&\;=\;&&1&\\&&&&2y&&\;+&&\;z&&\;=\;&&5&\end{alignedat}} L_{2}+{\frac {3}{2}}L_{1}\rightarrow L_{2}
L_{3}+L_{1}\rightarrow L_{3}
\left[{\begin{array}{ccc|c}2&1&-1&8\\0&1/2&1/2&1\\0&2&1&5\end{array}}\right]
{\begin{alignedat}{7}2x&&\;+&&y\;&&-&&\;z\;&&=\;&&8&\\&&&&{\frac {1}{2}}y\;&&+&&\;{\frac {1}{2}}z\;&&=\;&&1&\\&&&&&&&&\;-z\;&&\;=\;&&1&\end{alignedat}} L_{3}+-4L_{2}\rightarrow L_{3} \left[{\begin{array}{ccc|c}2&1&-1&8\\0&1/2&1/2&1\\0&0&-1&1\end{array}}\right]
The matrix is now in echelon form (also called triangular form)
{\begin{alignedat}{7}2x&&\;+&&y\;&&&&\;\;&&=\;&&7&\\&&&&{\frac {1}{2}}y\;&&&&\;\;&&=\;&&{\frac {3}{2}}&\\&&&&&&&&\;-z\;&&\;=\;&&1&\end{alignedat}} L_{2}+{\frac {1}{2}}L_{3}\rightarrow L_{2}
L_{1}-L_{3}\rightarrow L_{1}
\left[{\begin{array}{ccc|c}2&1&0&7\\0&1/2&0&3/2\\0&0&-1&1\end{array}}\right]
  {\begin{alignedat}{7}2x&&\;+&&y\;&&&&\;\;&&=\;&&7&\\&&&&y\;&&&&\;\;&&=\;&&3&\\&&&&&&&&\;z\;&&\;=\;&&-1&\end{alignedat}} 2L_{2}\rightarrow L_{2}
-L_{3}\rightarrow L_{3}
  \left[{\begin{array}{ccc|c}2&1&0&7\\0&1&0&3\\0&0&1&-1\end{array}}\right]
{\begin{alignedat}{7}x&&\;&&\;&&&&\;\;&&=\;&&2&\\&&&&y\;&&&&\;\;&&=\;&&3&\\&&&&&&&&\;z\;&&\;=\;&&-1&\end{alignedat}}   L_{1}-L_{2}\rightarrow L_{1}
{\frac {1}{2}}L_{1}\rightarrow L_{1}
  \left[{\begin{array}{ccc|c}1&0&0&2\\0&1&0&3\\0&0&1&-1\end{array}}\right]

The second column describes which row operations have just been performed. So for the first step, the x is eliminated from L_{2} by adding  {\begin{matrix}{\frac {3}{2}}\end{matrix}}L_{1} to  L_{2}. Next x is eliminated from  L_{3} by adding  L_{1} to  L_{3}. These row operations are labelled in the table as

L_{2}+{\frac {3}{2}}L_{1}\rightarrow L_{2}
L_{3}+L_{1}\rightarrow L_{3}.

Once y is also eliminated from the third row, the result is a system of linear equations in triangular form, and so the first part of the algorithm is complete. From a computational point of view, it is faster to solve the variables in reverse order, a process known as back-substitution. One sees the solution is z = -1, y = 3, and x = 2. So there is a unique solution to the original system of equations.

Instead of stopping once the matrix is in echelon form, one could continue until the matrix is in reduced row echelon form, as it is done in the table. The process of row reducing until the matrix is reduced is sometimes referred to as Gauss-Jordan elimination, to distinguish it from stopping after reaching echelon form.

 

翻古出新,談談如何用『SymPy』之

Matrices

Matrices (linear algebra)

模組為『工具』,操作

初等矩陣

線性代數中,初等矩陣(又稱為基本矩陣[1])是一個與單位矩陣只有微小區別的矩陣。具體來說,一個n階單位矩陣E經過一次初等行變換或一次初等列變換所得矩陣稱為n階初等矩陣。[2]

操作

初等矩陣分為3種類型,分別對應著3種不同的行/列變換。

兩行(列)互換:
  R_i \leftrightarrow R_j
把某行(列)乘以一非零常數:
kR_i \rightarrow R_i,\ 其中   k \neq 0
把第i行(列)加上第j行(列)的k倍:
R_i + kR_j \rightarrow R_i

初等矩陣即是將上述3種初等變換應用於一單位矩陣的結果。以下只討論對某行的變換,列變換可以類推。

行互換

這一變換Tij,將一單位矩陣的第i行的所有元素與第j行互換。

 T_{i,j} = \begin{bmatrix} 1 & & & & & & & \\ & \ddots & & & & & & \\ & & 0 & & 1 & & \\ & & & \ddots & & & & \\ & & 1 & & 0 & & \\ & & & & & & \ddots & \\ & & & & & & & 1\end{bmatrix}\quad

性質

  • 逆矩陣即自身: T_{ij}^{-1} = T_{ij}
  • 因為單位矩陣的行列式為1,故  |T_{ij}|=-1。與其他相同大小的方陣A亦有一下性質:  |T_{ij}A|=-|A|

把某行乘以一非零常數

這一變換Tim),將第i行的所有元素乘以一非零常數m

 T_i (m) = \begin{bmatrix} 1 & & & & & & \\ & \ddots & & & & & \\ & & 1 & & & & \\ & & & m & & & \\ & & & & 1 & & \\ & & & & & \ddots & \\ & & & & & & 1\end{bmatrix}\quad

性質

  • 逆矩陣為 T_{i}(m)^{-1} = T_{i}(\frac{1}{m})
  • 此矩陣及其逆矩陣均為對角矩陣
  • 其行列式 |T_{i}(m)|=m。故對於一等大方陣A|T_{i}(m)A|=m|A|

把第i行加上第j行的m

這一變換Tijm),將第i行加上第j行的m倍。

 T_{i,j}(m) = \begin{bmatrix} 1 & & & & & & & \\ & \ddots & & & & & & \\ & & 1 & & & & & \\ & & & \ddots & & & & \\ & & m & & 1 & & \\ & & & & & & \ddots & \\ & & & & & & & 1\end{bmatrix}

性質

  • 逆矩陣具有性質  T_{ij}(m)^{-1}=T_{ij}(-m)
  • 此矩陣及其逆矩陣均為三角矩陣
  • |T_{ij}(m)|=1。故對於一等大方陣A有: |T_{ij}(m)A| = |A|

 

親自『實證』消去法的精神,體驗用『工具』來『學習』之樂趣吧! !

省思這個『初等』當真可『模擬』紙筆運算嗎??

pi@raspberrypi:~ $ python3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> from sympy import *
>>> init_printing()
>>> a, b, c, d, e, f, g, h, i, m = symbols('a, b, c, d, e, f, g, h, i, m')
>>> M = Matrix([[a, b, c], [d, e, f], [g, h, i]])
>>> M
⎡a  b  c⎤
⎢       ⎥
⎢d  e  f⎥
⎢       ⎥
⎣g  h  i⎦

>>> 二三列交換 = Matrix([[1, 0, 0], [0, 0, 1], [0, 1, 0]])
>>> 二三列交換
⎡1  0  0⎤
⎢       ⎥
⎢0  0  1⎥
⎢       ⎥
⎣0  1  0⎦
>>> 二三列交換 * M
⎡a  b  c⎤
⎢       ⎥
⎢g  h  i⎥
⎢       ⎥
⎣d  e  f⎦

>>> 第二列乘m = Matrix([[1, 0, 0], [0, m, 0], [0, 0, 1]])
>>> 第二列乘m
⎡1  0  0⎤
⎢       ⎥
⎢0  m  0⎥
⎢       ⎥
⎣0  0  1⎦
>>> 第二列乘m * M
⎡ a    b    c ⎤
⎢             ⎥
⎢d⋅m  e⋅m  f⋅m⎥
⎢             ⎥
⎣ g    h    i ⎦

>>> 第三列加第二列乘m = Matrix([[1, 0, 0], [0, 1, 0], [0, m, 1]])
>>> 第三列加第二列乘m
⎡1  0  0⎤
⎢       ⎥
⎢0  1  0⎥
⎢       ⎥
⎣0  m  1⎦
>>> 第三列加第二列乘m * M
⎡   a        b        c   ⎤
⎢                         ⎥
⎢   d        e        f   ⎥
⎢                         ⎥
⎣d⋅m + g  e⋅m + h  f⋅m + i⎦
>>> 

 

或可得『自學』之法哩!!??

>>> AM = Matrix([[2, 1, -1, 8], [-3, -1, 2, -11], [-2, 1, 2, -3]])
>>> AM
⎡2   1   -1   8 ⎤
⎢               ⎥
⎢-3  -1  2   -11⎥
⎢               ⎥
⎣-2  1   2   -3 ⎦

>>> L2加二分之三L1 = Matrix([[1, 0, 0], [3/2, 1, 0], [0, 0, 1]])
>>> L2加二分之三L1
⎡ 1   0  0⎤
⎢         ⎥
⎢1.5  1  0⎥
⎢         ⎥
⎣ 0   0  1⎦

>>> L2加二分之三L1 * AM
⎡2    1   -1    8 ⎤
⎢                 ⎥
⎢0   0.5  0.5  1.0⎥
⎢                 ⎥
⎣-2   1    2   -3 ⎦

>>> L3加上L1 = Matrix([[1, 0, 0], [0, 1, 0], [1, 0, 1]]) 
>>> L3加上L1
⎡1  0  0⎤
⎢       ⎥
⎢0  1  0⎥
⎢       ⎥
⎣1  0  1⎦

>>> L3加上L1 * AM
⎡2   1   -1   8 ⎤
⎢               ⎥
⎢-3  -1  2   -11⎥
⎢               ⎥
⎣0   2   1    5 ⎦

>>> L3加上L1 * L2加二分之三L1 * AM
⎡2   1   -1    8 ⎤
⎢                ⎥
⎢0  0.5  0.5  1.0⎥
⎢                ⎥
⎣0   2    1    5 ⎦

>>> L2加二分之三L1 * L3加上L1 * AM
⎡2   1   -1    8 ⎤
⎢                ⎥
⎢0  0.5  0.5  1.0⎥
⎢                ⎥
⎣0   2    1    5 ⎦
# ……