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

◆ Zgssv()

Sub Zgssv ( N As  Long,
Val() As  Complex,
Ptr() As  Long,
Ind() As  Long,
B() As  Complex,
RCond As  Double,
Optional Info As  Long,
Optional Format As  Long = 0,
Optional Base As  Long = -1,
Optional Nrhs As  Long = 1,
Optional ColPerm As  String = "A",
Optional Thresh As  Double = 1,
Optional SymMode As  String = "N" 
)

Solves the system of linear equations A*X = B (direct method) (complex sparse matrix) (SuperLU) (simple driver)

Purpose
This routine solves the system of linear equations A*X = B, using the LU factorization, where A is a general N x N complex sparse matrix. A condition estimate is also computed. It performs the following steps:

  1. If A is stored column-wise (CSC):

    1.1. Permute the columns of A, forming A*Pc, where Pc is a permutation matrix.
    1.2. Factor A as Pr*A*Pc = L*U with the permutation Pr determined by Gaussian elimination with partial pivoting. L is unit lower triangular with offdiagonal entries bounded by 1 in magnitude, and U is upper triangular.
    1.3. Solve the system of equations A*X = B using the factored form of A.

  2. If A is stored row-wise (CSR), apply the above algorithm to the transpose of A:

    2.1. Permute columns of transpose(A) (rows of A), forming transpose(A)*Pc, where Pc is a permutation matrix.
    2.2. Factor A as Pr*transpose(A)*Pc = L*U with the permutation Pr determined by Gaussian elimination with partial pivoting. L is unit lower triangular with offdiagonal entries bounded by 1 in magnitude, and U is upper triangular.
    2.3. Solve the system of equations A*X = B using the factored form of A.
Parameters
[in]NNumber of rows and columns of the matrix A. (N >= 0) (If N = 0, returns without computation)
[in]Val()Array Val(LVal - 1) (LVal >= Nnz) (Nnz is the number of nonzero elements of the matrix)
Values of nonzero elements of the matrix A.
[in]Ptr()Array Ptr(LPtr - 1) (LPtr >= N + 1)
Column pointers (if CSC) or row pointers (if CSR) of the matrix A.
[in]Ind()Array Ind(LInd - 1) (LInd >= Nnz)
Row indices (if CSC) or column indices (if CSR) of the matrix A.
[in,out]B()Array B(LB1 - 1, LB2 - 1) (LB1 >= N, LB2 >= Nrhs) (2D array) or B(LB - 1) (LB >= N, Nrhs = 1) (1D array)
[in] N x Nrhs right hand side matrix B.
[out] The solution matrix X.
[out]RcondEstimated reciprocal of the condition number of the matrix A.
[out]Info(Optional)
= 0: Successful exit.
< 0: The (-Info)-th argument is invalid.
= -10000: Unrecoverble error occured in SuperLU routine.
= i > 0 and <= N: U(i,i) is exactly zero. The factorization has been completed, but the factor U is exactly singular, so the solution could not be computed.
= i > N: Memory allocation failure occurred. i - N is the number of bytes allocated.
[in]Format(Optional)
Sparse matrix format. (default = 0)
= 0: CSR format.
= 1: CSC format.
[in]Base(Optional)
Indexing of Rowptr() and Colind().
= 0: Zero-based (C style) indexing: Starting index is 0.
= 1: One-based (Fortran style) indexing: Starting index is 1.
(default: Assumes 1 if Ptr(0) = 1, otherwise 0)
[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)
[in]ColPerm(Optional)
Specifies the type of column ordering to reduce fill-in.
= "A": Approximate minimum degree (AMD) ordering.
= "N": Natural ordering (No ordering) (Pc = I).
= "M": Multiple minimum degree (MMD) ordering on A^T*A.
= "P": Multiple minimum degree (MMD) ordering on A^T + A.
(default = "A")
[in]Thresh(Optional)
Specifies the threshold used for a diagonal entry to be an acceptable pivot (0 <= Thresh <= 1). (default = 1)
[in]SymMode(Optional)
Specifies whether to use symmetric mode. Symmetric mode gives preference to diagonal pivots, and uses an (A^T + A)-based column permutation algorithm.
= "N": Do not use symmetric mode.
= "S": Use symmetric mode.
(default = "N")
Reference
SuperLU
Example Program
Solve the system of linear equations Ax = B and estimate the reciprocal of the condition number (RCond) of A, where
( 0.78+0.16i -0.9-1.46i 0.48-1.08i )
A = ( 0.73+0.63i 1.58-1.24 -0.41-0.91i )
( 0.23-1.37i 0.79+0.64i -0.73-1.5i )
( 0.2126-0.2904i )
B = ( -0.3028+0.3346i )
( -1.2905-1.0346i )
Sub Ex_Zgssv()
Const N = 3, Nnz = N * N
Dim A(Nnz - 1) As Complex, Ia(N) As Long, Ja(Nnz - 1) As Long
Dim B(N - 1) As Complex
Dim RCond As Double, Info As Long
A(0) = Cmplx(0.78, 0.16): A(1) = Cmplx(-0.9, -1.46): A(2) = Cmplx(0.48, -1.08): A(3) = Cmplx(0.73, 0.63): A(4) = Cmplx(1.58, -1.24): A(5) = Cmplx(-0.41, -0.91): A(6) = Cmplx(0.23, -1.37): A(7) = Cmplx(0.79, 0.64): A(8) = Cmplx(-0.73, -1.5)
Ia(0) = 0: Ia(1) = 3: Ia(2) = 6: Ia(3) = 9
Ja(0) = 0: Ja(1) = 1: Ja(2) = 2: Ja(3) = 0: Ja(4) = 1: Ja(5) = 2: Ja(6) = 0: Ja(7) = 1: Ja(8) = 2
B(0) = Cmplx(0.2126, -0.2904): B(1) = Cmplx(-0.3028, 0.3346): B(2) = Cmplx(-1.2905, -1.0346)
Call Zgssv(N, A(), Ia(), Ja(), B(), RCond, Info)
Debug.Print "X ="
Debug.Print "(" + CStr(Creal(B(0))) + ", " + CStr(Cimag(B(0))) + ")"
Debug.Print "(" + CStr(Creal(B(1))) + ", " + CStr(Cimag(B(1))) + ")"
Debug.Print "(" + CStr(Creal(B(2))) + ", " + CStr(Cimag(B(2))) + ")"
Debug.Print "RCond = " + CStr(RCond) + ", Info = " + CStr(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 Zgssv(N As Long, Val() As Complex, Ptr() As Long, Ind() As Long, B() As Complex, RCond As Double, Optional Info As Long, Optional Format As Long=0, Optional Base As Long=-1, Optional Nrhs As Long=1, Optional ColPerm As String="A", Optional Thresh As Double=1, Optional SymMode As String="N")
Solves the system of linear equations A*X = B (direct method) (complex sparse matrix) (SuperLU) (simp...
Example Results
X =
(0.59, -0.28)
(-0.2, -3.99999999999999E-02)
(0.24, -0.49)
RCond = 0.194425064735609, Info = 0