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

沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...