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

◆ Zgtsvx()

Sub Zgtsvx ( Fact As  String,
Trans As  String,
N As  Long,
Dl() As  Complex,
D() As  Complex,
Du() As  Complex,
Dlf() As  Complex,
Df() As  Complex,
Duf() As  Complex,
Du2() As  Complex,
IPiv() As  Long,
B() As  Complex,
X() As  Complex,
RCond As  Double,
FErr() As  Double,
BErr() As  Double,
Info As  Long,
Optional Nrhs As  Long = 1 
)

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

Purpose
This routine uses the LU factorization to computes the solution to a complex system of linear equations
A * X = B or A^T * X = B
where A is a tridiagonal matrix of order n and X and B are n x nrhs matrices.
Error bounds on the solution and a condition estimate are also provided.
Description
The following steps are performed:

  1. If Fact = "N", the LU decomposition is used to factor the matrix A as
    A = L * U
    where L is a product of permutation and unit lower bidiagonal matrices and U is upper triangular with nonzeros in only the main diagonal and first two super-diagonals.

  2. If i-th diagonal element of U = 0, so that U is exactly singular, then the routine returns with info = i. Otherwise, the factored form of A is used to estimate the condition number of the matrix A. If the reciprocal of the condition number is less than machine precision, info = n+1 is returned as a warning, but the routine still goes on to solve for X and compute error bounds as described below.

  3. The system of equations is solved for X using the factored form of A.

  4. Iterative refinement is applied to improve the computed solution matrix and calculate error bounds and backward error estimates for it.
Parameters
[in]FactSpecifies whether or not the factored form of A has been supplied on entry.
= "F": Dlf(), Df(), Duf(), Du2() and IPiv() contain the factored form of A; Dlf(), Df(), Duf(), Du2() and IPiv() will not be modified.
= "N": The matrix will be copied to Dlf(), Df() and Duf() and factored.
[in]TransSpecifies the form of the system of equations:
= "N": A * X = B. (no transpose)
= "T" or "C": A^T * X = B. (transpose)
[in]NOrder of the matrix A. (N >= 0) (If N = 0, returns without computation)
[in]Dl()Array Dl(LDl - 1) (LDl >= N - 1)
N-1 sub-diagonal elements of A.
[in]D()Array D(LD - 1) (LD >= N)
N diagonal elements of A.
[in]Du()Array Du(LDu - 1) (LDu >= N - 1)
N-1 super-diagonal elements of A.
[in,out]Dlf()Array Dlf(LDlf - 1) (LDlf >= N - 1)
[in] If Fact = "F", N-1 multipliers that define the matrix L from the LU factorization of A as computed by Dgttrf, are to be stored.
[out] If Fact = "N", N-1 multipliers that define the matrix L from the LU factorization of A, are returned.
[in,out]Df()Array Df(LDf - 1) (LDf >= N)
[in] If Fact = "F", diagonal elements of the upper triangular matrix U from the LU factorization of A, are to be stored.
[out] If Fact = "N", diagonal elements of the upper triangular matrix U from the LU factorization of A, are returned.
[in,out]Duf()Array Duf(LDuf - 1) (LDuf >= N - 1)
[in] If Fact = "F", N-1 elements of the first super-diagonal of U, are to be stored.
[out] If Fact = "N", N-1 elements of the first super-diagonal of U, are returned.
[in,out]Du2()Array Du2(LDu2 - 1) (LDu2 >= N - 2)
[in] If Fact = "F", N-2 elements of the second super-diagonal of U, are to be stored.
[out] If Fact = "N", N-2 elements of the second super-diagonal of U, are returned.
[in,out]IPiv()Array IPiv(LIPiv - 1) (LIPiv >= N)
[in] If Fact = "F", the pivot indices from the LU factorization of A as computed by Dgttrf, are to be stored.
[out] If Fact = "N", the pivot indices from the LU factorization of A are returned; row i of the matrix was interchanged with row IPiv(i-1). IPiv(i-1) will always be either i or i+1; IPiv(i-1) = i indicates a row interchange was not required.
[in]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)
N x Nrhs matrix of right hand side matrix B.
[out]X()Array X(LX1 - 1, LX2 - 1) (LX1 >= max(1, N), LX2 >= Nrhs) (2D array) or X(LX - 1) (LX >= max(1, N), Nrhs = 1) (1D array)
If Info = 0 or Info = N+1, the N x Nrhs solution matrix X.
[out]RCondThe estimate of the reciprocal condition number of the matrix A. If RCond is less than the machine precision (in particular, if RCond = 0), the matrix is singular to working precision. This condition is indicated by a return code of Info > 0.
[out]FErr()Array FErr(LFErr - 1) (LFErr >= Nrhs)
The estimated forward error bound for each solution vector X(j) (the j-th column of the solution matrix X). If Xtrue is the true solution corresponding to X(j), FErr(j-1) is an estimated upper bound for the magnitude of the largest element in (X(j) - Xtrue) divided by the magnitude of the largest element in X(j). The estimate is as reliable as the estimate for rcond, and is almost always a slight overestimate of the true error.
[out]BErr()Array BErr(LBErr - 1) (LBErr >= Nrhs)
The componentwise relative backward error of each solution vector X(j) (i.e., the smallest relative change in any element of A or B that makes X(j) an exact solution).
[out]Info= 0: Successful exit.
= -1: The argument Fact had an illegal value. (Fact <> "F" nor "N")
= -2: The argument Trans had an illegal value. (Trans <> "N", "T" nor "C")
= -3: The argument N had an illegal value. (N < 0)
= -4: The argument Dl() is invalid.
= -5: The argument D() is invalid.
= -6: The argument Du() is invalid.
= -7: The argument Dlf() is invalid.
= -8: The argument Df() is invalid.
= -9: The argument Duf() is invalid.
= -10: The argument Du2() is invalid.
= -11: The argument IPiv() is invalid.
= -12: The argument B() is invalid.
= -13: The argument X() is invalid.
= -15: The argument FErr() is invalid.
= -16: The argument BErr() is invalid.
= -18: The argument Nrhs had an illegal value. (Nrhs < 0)
= i (0 < i <= N): The i-th diagonal element of the factor U is exactly zero. The factorization has not been completed unless i = N, but the factor U is exactly singular, so the solution and error bounds could not be computed. RCond = 0 is returned.
= N+1: U is nonsingular, but rcond is less than machine precision, meaning that the matrix is singular to working precision. Nevertheless, the solution and error bounds are computed because there are a number of situations where the computed solution can be more accurate than the value of RCond would suggest.
[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 and estimate the reciprocal of the condition number (RCond) of A, where
( 0.81+0.37i -0.20-0.11i 0 )
A = ( 0.64+0.51i -0.80-0.92i -0.93-0.32i )
( 0 0.71+0.59i -0.29+0.86i )
( -0.0484+0.2644i )
B = ( -0.2644-1.0228i )
( -0.5299+1.5025i )
Sub Ex_Zgtsvx()
Const N = 3
Dim Dl(N - 2) As Complex, D(N - 1) As Complex, Du(N - 2) As Complex
Dim Dlf(N - 2) As Complex, Df(N - 1) As Complex, Duf(N - 2) As Complex
Dim Du2(N - 3) As Complex, IPiv(N - 1) As Long
Dim B(N - 1) As Complex, X(N - 1) As Complex
Dim FErr(0) As Double, BErr(0) As Double
Dim RCond As Double, Info As Long
Dl(0) = Cmplx(0.64, 0.51): Dl(1) = Cmplx(0.71, 0.59)
D(0) = Cmplx(0.81, 0.37): D(1) = Cmplx(-0.8, -0.92): D(2) = Cmplx(-0.29, 0.86)
Du(0) = Cmplx(0.2, -0.11): Du(1) = Cmplx(-0.93, -0.32)
B(0) = Cmplx(-0.0484, 0.2644): B(1) = Cmplx(-0.2644, -1.0228): B(2) = Cmplx(-0.5299, 1.5025)
Call Zgtsvx("N", "N", N, Dl(), D(), Du(), Dlf(), Df(), Duf(), Du2(), IPiv(), B(), X(), RCond, FErr(), BErr(), Info)
Debug.Print "X =",
Debug.Print Creal(X(0)), Cimag(X(0)), Creal(X(1)), Cimag(X(1)), Creal(X(2)), Cimag(X(2))
Debug.Print "RCond =", RCond
Debug.Print "Info =", Info
End Sub
Function Cmplx(R As Double, Optional I As Double=0) As Complex
Building complex number
Function Cimag(A As Complex) As Double
Imaginary part of complex number
Function Creal(A As Complex) As Double
Real part of complex number
Sub Zgtsvx(Fact As String, Trans As String, N As Long, Dl() As Complex, D() As Complex, Du() As Complex, Dlf() As Complex, Df() As Complex, Duf() As Complex, Du2() As Complex, IPiv() As Long, B() As Complex, X() As Complex, RCond As Double, FErr() As Double, BErr() As Double, Info As Long, Optional Nrhs As Long=1)
(Expert driver) Solution to system of linear equations AX = B for a complex tridiagonal matrix
Example Results
X = -0.15 0.19 0.2 0.94 0.79 -0.13
RCond = 0.187722560135325
Info = 0