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

◆ Dgbsv()

Sub Dgbsv ( N As  Long,
Kl As  Long,
Ku As  Long,
Ab() As  Double,
IPiv() As  Long,
B() As  Double,
Info As  Long,
Optional Nrhs As  Long = 1 
)

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

Purpose
This routine computes the solution to a real system of linear equations
A * X = B
where A is a band matrix of order n with kl sub-diagonals and ku super-diagonals, and X and B are n x nrhs matrices.

The LU decomposition with partial pivoting and row interchanges is used to factor A as
A = L * U
where L is a product of permutation and unit lower triangular matrices with kl sub-diagonals, and U is upper triangular with kl+ku super-diagonals. The factored form of A is then used to solve the system of equations A * X = B.
Parameters
[in]NNumber of linear equations, i.e., order of the matrix A. (N >= 0) (If N = 0, returns without computation)
[in]KlNumber of sub-diagonals within the band of A. (Kl >= 0)
[in]KuNumber of super-diagonals within the band of A. (Ku >= 0)
[in,out]Ab()Array Ab(LAb1 - 1, LAb2 - 1) (LAb1 >= 2Kl + Ku + 1, LAb2 >= N)
[in] The matrix A in band matrix form, in rows Kl+1 to 2Kl+Ku+1; rows 1 to Kl of the array need not be set.
[out] Details of the factorization: U is stored as an upper triangular band matrix with kl+ku super-diagonals in rows 1 to Kl+Ku+1, and the multipliers used during the factorization are stored in rows Kl+Ku+2 to 2*Kl+Ku+1. See below for further details.
[out]IPiv()Array IPiv(LIPiv - 1) (LIPiv >= N)
Pivot indices that define the permutation matrix P; row i of the matrix was interchanged with row IPiv(i-1).
[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 Kl had an illegal value. (Kl < 0)
= -3: The argument Ku had an illegal value. (Ku < 0)
= -4: The argument Ab() is invalid.
= -5: The argument IPiv() is invalid.
= -6: The argument B() is invalid.
= -8: The argument Nrhs had an illegal value. (Nrhs < 0)
= i > 0: The i-th diagonal element of the factor U is exactly zero. The factorization has been completed, but the factor U is exactly singular, and the solution has not been computed.
[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)
Further Details
The band matrix form is illustrated by the following example, when N = 6, Kl = 2, Ku = 1:
On entry:
   *    *    *    +    +    +
   *    *    +    +    +    +
   *   a12  a23  a34  a45  a56
  a11  a22  a33  a44  a55  a66
  a21  a32  a43  a54  a65   *
  a31  a42  a53  a64   *    *

On exit:
   *    *    *   u14  u25  u36
   *    *   u13  u24  u35  u46
   *   u12  u23  u34  u45  u56
  u11  u22  u33  u44  u55  u66
  m21  m32  m43  m54  m65   *
  m31  m42  m53  m64   *    *
Array elements marked * are not used by the routine; elements marked + need not be set on entry, but are required by the routine to store elements of U because of fill-in resulting from the row interchanges.
Reference
LAPACK
Example Program
Solve the system of linear equations Ax = B and estimate the reciprocal of the condition number (RCond) of A, where
( 2.34 0.57 0 ) ( 0.7416 )
A = ( 0.65 1.98 -1.39 ), B = ( 0.7885 )
( 0 1.50 1.73 ) ( 1.0833 )
Sub Ex_Dgbsv()
Const N = 3, Kl = 1, Ku = 1
Dim Ab(2 * Kl + Ku, N - 1) As Double, B(N - 1) As Double, IPiv(N - 1) As Long
Dim ANorm As Double, RCond As Double, Info As Long
Ab(1, 1) = 0.57: Ab(1, 2) = -1.39
Ab(2, 0) = 2.34: Ab(2, 1) = 1.98: Ab(2, 2) = 1.73
Ab(3, 0) = 0.65: Ab(3, 1) = 1.5
B(0) = 0.7416: B(1) = 0.7885: B(2) = 1.0833
ANorm = Dlangb("1", N, Kl, Ku, Ab(), , Kl)
Call Dgbsv(N, Kl, Ku, Ab(), IPiv(), B(), Info)
If Info = 0 Then Call Dgbcon("1", N, Kl, Ku, Ab(), IPiv(), ANorm, RCond, Info)
Debug.Print "X =", B(0), B(1), B(2)
Debug.Print "RCond =", RCond
Debug.Print "Info =", Info
End Sub
Function Dlangb(Norm As String, N As Long, Kl As Long, Ku As Long, Ab() As Double, Optional Info As Long, Optional Offset As Long=0) As Double
One norm, Frobenius norm, infinity norm, or largest absolute value of any element of a general band m...
Sub Dgbcon(Norm As String, N As Long, Kl As Long, Ku As Long, Ab() As Double, IPiv() As Long, ANorm As Double, RCond As Double, Info As Long)
Condition number of a general band matrix
Sub Dgbsv(N As Long, Kl As Long, Ku As Long, Ab() As Double, IPiv() As Long, B() As Double, Info As Long, Optional Nrhs As Long=1)
(Simple driver) Solution to system of linear equations AX = B for a general band matrix
Example Results
X = 0.2 0.48 0.21
RCond = 0.364187455306431
Info = 0