2019年1月28日 星期一

Tridiagonal matrix algorithm

Tridiagonal matrix algorithm

From Wikipedia, the free encyclopedia
Jump to navigationJump to search
In numerical linear algebra, the tridiagonal matrix algorithm, also known as the Thomas algorithm (named after Llewellyn Thomas), is a simplified form of Gaussian elimination that can be used to solve tridiagonal systems of equations. A tridiagonal system for n unknowns may be written as
where  and .
For such systems, the solution can be obtained in  operations instead of  required by Gaussian elimination. A first sweep eliminates the 's, and then an (abbreviated) backward substitution produces the solution. Examples of such matrices commonly arise from the discretization of 1D Poisson equation and natural cubic spline interpolation.
Thomas' algorithm is not stable in general, but is so in several special cases, such as when the matrix is diagonally dominant(either by rows or columns) or symmetric positive definite;[1][2] for a more precise characterization of stability of Thomas' algorithm, see Higham Theorem 9.12.[3] If stability is required in the general case, Gaussian elimination with partial pivoting(GEPP) is recommended instead.[2]

Method[edit]

The forward sweep consists of modifying the coefficients as follows, denoting the new coefficients with primes:
and
The solution is then obtained by back substitution:
The method above preserves the original coefficient vectors. If this is not required, then a much simpler form of the algorithm is
followed by the back substitution
The implementation in a VBA subroutine without preserving the coefficient vectors is shown below

Sub TriDiagonal_Matrix_Algorithm(N%, A#(), B#(), C#(), D#(), X#())
 Dim i%, W#
 For i = 2 To N
  W = A(i) / B(i - 1)
  B(i) = B(i) - W * C(i - 1)
  D(i) = D(i) - W * D(i - 1)
 Next i
 X(N) = D(N) / B(N)
 For i = N - 1 To 1 Step -1
  X(i) = (D(i) - C(i) * X(i + 1)) / B(i)
 Next i
End Sub

沒有留言:

張貼留言

Telegram +ESP32自動發報機

  Telegram   +ESP32自動發報機 這套系統是一個典型的 IoT(物聯網)架構 ,結合了遠端配置(Python)、通訊中介(MQTT)與硬體執行(ESP32)。 以下我為您拆解這兩支程式的核心運作原理: 一、 系統架構流程 Python 端 (控制台) :使用者輸入...