XLPack 7.0
XLPack Numerical Library (Excel VBA) Reference Manual
Loading...
Searching...
No Matches

◆ Dgtsv()

Sub Dgtsv ( N As  Long,
Dl() As  Double,
D() As  Double,
Du() As  Double,
B() As  Double,
Info As  Long,
Optional Nrhs As  Long = 1 
)

(Simple driver) Solution to system of linear equations AX = B for a general tridiagonal matrix

Purpose
This routine solves the equation
A * X = B
where A is an n x n tridiagonal matrix, by Gaussian elimination with partial pivoting.
Note that the equation A^T*X = B may be solved by interchanging the order of the arguments Du and Dl.
Parameters
[in]NOrder of the matrix A. (N >= 0) (If N = 0, returns without computation)
[in,out]Dl()Array Dl(LDl - 1) (LDl >= N - 1)
[in] N-1 sub-diagonal elements of A. [out] N-2 elements of the second super-diagonal of the upper triangular matrix U from the LU factorization of A, in Dl(0), ..., Dl(N-3).
[in,out]D()Array D(LD - 1) (LD >= N)
[in] Diagonal elements of A.
[out] Diagonal elements of U.
[in,out]Du()Array Du(LDu - 1) (LDu >= N - 1)
[in] N-1 super-diagonal elements of A.
[out] N-1 elements of the first super-diagonal of U.
[in,out]B()Array B(LB1 - 1, LB2 - 1) (LB1 >= max(1, N), LB2 >= Nrhs) (2D array) or B(LB - 1) (LB >= max(1, N), Nrhs = 1) (1D array)
[in] N x Nrhs matrix of right hand side matrix B.
[out] If Info = 0, the N x Nrhs solution matrix X.
[out]Info= 0: Successful exit.
= -1: The argument N had an illegal value. (N < 0)
= -2: The argument Dl() is invalid.
= -3: The argument D() is invalid.
= -4: The argument Du() is invalid.
= -5: The argument B() is invalid.
= -7: The argument Nrhs had an illegal value. (Nrhs < 0, or, Nrhs <> 1 and B() is 1D array)
= i > 0: The i-th diagonal element of the factor U is exactly zero, and the solution has not been computed. The factorization has not been completed unless i = n.
[in]Nrhs(Optional)
Number of right hand sides, i.e., number of columns of the matrix B. (Nrhs >= 0) (If Nrhs = 0, returns without computation) (default = 1)
Reference
LAPACK
Example Program
Solve the system of linear equations Ax = B, where
( -0.58 1.14 0 ) ( -0.5960 )
A = ( -1.56 2.21 0.16 ), B = ( -0.6798 )
( 0 0.24 0.25 ) ( -0.0406 )
Sub Ex_Dgtsv()
Const N = 3
Dim Dl(N - 2) As Double, D(N - 1) As Double, Du(N - 2) As Double
Dim B(N - 1) As Double, Info As Long
Dl(0) = -1.56: Dl(1) = 0.24
D(0) = -0.58: D(1) = 2.21: D(2) = 0.25
Du(0) = 1.14: Du(1) = 0.16
B(0) = -0.596: B(1) = -0.6798: B(2) = -0.0406
Call Dgtsv(N, Dl(), D(), Du(), B(), Info)
Debug.Print "X =", B(0), B(1), B(2)
Debug.Print "Info =", Info
End Sub
Sub Dgtsv(N As Long, Dl() As Double, D() As Double, Du() As Double, B() As Double, Info As Long, Optional Nrhs As Long=1)
(Simple driver) Solution to system of linear equations AX = B for a general tridiagonal matrix
Example Results
X = -0.82 -0.94 0.74
Info = 0