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

◆ Zgsgv()

Sub Zgsgv ( Jobz As  String,
Uplo2 As  String,
N As  Long,
Val() As  Complex,
Ptr() As  Long,
Ind() As  Long,
Val2() As  Complex,
Ptr2() As  Long,
Ind2() As  Long,
Which As  String,
Nev As  Long,
Ncv As  Long,
D() As  Complex,
Z() As  Complex,
Optional Info As  Long,
Optional Nconv As  Long,
Optional Niter As  Long,
Optional Base As  Long = -1,
Optional Base2 As  Long = -1,
Optional Format As  Long = 0,
Optional Mode As  Long = 2,
Optional Sigmar As  Double = 0,
Optional Sigmai As  Double = 0,
Optional Maxiter As  Long = 300,
Optional Tol As  Double = 0 
)

Generalized eigenvalue problem of a complex sparse matrix (implicitly restarted Arnoldi method (IRAM)) (Arpack) (simple driver)

Purpose
Let's consider the generalized eigenvalue problem
A*z = λ*B*z
where λ is eigenvalue and z is its eigenvector. A is a complex sparse matrix and B is an Hermitian positive semi-definite sparse matrix.

This routine computes the eigenvalues λ and eigenvectors z of the above problem by implicitly restarted Arnoldi method (IRAM) using Arpack routines Dnaupd and Dneupd.

It is assumed that the sparse matrix A is stored in CSC or CSR format, and the upper or lower triangular part or both (whole matrix) of the Hermitian sparse matrix B is stored in CSC or CSR format.

This routine works in the following two modes.

(1) Regular inverse mode
When Mode = 2, this routine computes in the regular inverse mode. Largest or smallest some eigenvalues and associated eigenvectors are computed. Sigmar and Sigmai are not referenced.

(2) Shift and invert mode
When Mode = 3, this routine computes in the shift and invert mode. The eigenvalues closest to the specified σ (shift) can be obtained.
Let's consider the other eigenvalue problem
OP*x = ν*M*x
where OP = (A - σ*M)^(-1)*M, M = B and ν is the eigenvalue of this problem. If the eigenvalue ν is obtained, the eigenvalue λ of the original problem can be computed by ν = 1/(λ - σ). Therefore, the eigenvalue λ closest to σ can be computed if the largest ν is obtained. The parameter Which specifies which eigenvalues ν are to be found. Generally, the closest eigenvalue λ to σ can be obtained by specifying "LM".
Parameters
[in]Jobz= 'N': Compute eigenvalues only.
= 'V': Compute eigenvalues and eigenvectors.
[in]Uplo2Specifies whether the upper or lower triangular part of the matrix B is stored.
= 'U': Upper triangular part is stored.
= 'L': Lower triangular part is stored.
= 'B': Whole matrix is stored (both upper and lower parts are stored).
The other triangular elements (not including diagonal elements) are ignored.
[in]NNumber of rows and columns of the matrix. (N >= 0) (If N = 0, returns without computation)
[in]Val()Array Val(LVal - 1) (LVal >= Nnz)
Values of nonzero elements of matrix A (where Nnz is the number of nonzero elements).
[in]Ptr()Array Ptr(LPtr - 1) (LPtr >= N + 1
Column pointers (if CSC) or row pointers (if CSR) of matrix A.
[in]Ind()Array Ind(LInd - 1) (LInd >= Nnz)
Row indices (if CSC) or column indices (if CSR) of matrix A (where Nnz is the number of nonzero elements).
[in]Val2()Array Val2(LVal2 - 1) (LVal2 >= Nnz2)
Values of nonzero elements of matrix B (where Nnz is the number of nonzero elements).
[in]Ptr2()Array Ptr2(LPtr2 - 1) (LPtr2 >= N + 1
Column pointers (if CSC) or row pointers (if CSR) of matrix B.
[in]Ind2()Array Ind2(LInd2 - 1) (LInd2 >= Nnz2)
Row indices (if CSC) or column indices (if CSR) of matrix B (where Nnz is the number of nonzero elements).
[in]Which= "LM": Compute the Nev eigenvalues of largest magnitude.
= "SM": Compute the Nev eigenvalues of smallest magnitude.
= "LR": Compute the Nev eigenvalues of largest real part.
= "SR": Compute the Nev eigenvalues of smallest real part.
= "LI": Compute the Nev eigenvalues of largest imaginary part.
= "SI": Compute the Nev eigenvalues of smallest imaginary part.
[in]NevNumber of eigenvalues to be computed. (0 < Nev < N)
[in]NcvNumber of columns of the matrix V. (Nev < Ncv <= N)
This will indicate how many Arnoldi vectors are generated at each iteration (Ncv >= 2*Nev is recommended).
[out]D()Array D(LD - 1) (LD >= Nev)
Contains the Ritz value approximations to the eigenvalues of A*z = λ*B*z.
[out]Z()Array Z(Ldz - 1, LZ - 1) (Ldz >= N, LZ >= Nev)
Contains the Ritz vectors (approximations to the eigenvectors) of the eigensystem A*z = λ*B*z corresponding to the Ritz value approximations.
If Jobz = "N" then Z() is not referenced.
[out]InfoReturn code.
= 0: Successful exit.
< 0: The (-Info)-th argument is invalid.
= 1: Maximum number of iterations taken.
= 3: No shifts could be applied during a cycle of the implicitly restarted Arnoldi iteration. A possible remedy is to increase Ncv relative to Nev (Ncv >= 2*Nev is recommended).
= 11: Initial residual vector is zero.
= 12: Failed to build a Arnoldi factorization.
= 13: Error return from LAPACK eigenvalue calculation.
= 14: Znaupd did not find any eigenvalues to sufficient accuracy.
= 15 to 19: Internal code error.
[out]Nconv(Optional)
Number of Ritz values that satisfy the convergence criterion.
[out]Niter(Optional)
Number of Lanczos update iterations taken.
[in]Base(Optional)
Indexing of Ptr() and Ind().
= 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, 0 otherwise)
[in]Base2(Optional)
Indexing of Ptr2() and Ind2().
= 0: Zero-based (C style) indexing: Starting index is 0.
= 1: One-based (Fortran style) indexing: Starting index is 1.
(default: Assumes 1 if Ptr2(0) = 1, 0 otherwise)
[in]Format(Optional)
Sparse matrix format. (default = 0)
= 0: CSR format.
= 1: CSC format.
[in]Mode(Optional)
Computation mode. (default = 2)
= 2: Regular inverse mode.
= 3: Shift and invert mode.
[in]Sigmar(Optional)
Real part of the shift (σ). Not referenced if Mode = 2. (default = 0)
[in]Sigmai(Optional)
Imaginary part of the shift (σ). Not referenced if Mode = 2. (default = 0)
[in]MaxIter(Optional)
Maximum number of Arnoldi update iterations. (MaxIter > 0) (default = 300)
[in]Tol(Optional)
Stopping criterion: the acceptable relative accuracy of the Ritz value. (default = 0)
If Tol <= 0, machine precision is assumed.
Example Program
Computes the largest generalized eigenvalue and its eigenvector of mastrix A and Hermitian matrix B where
( 0.20-0.11i -0.93-0.32i 0.81+0.37i )
A = ( -0.80-0.92i -0.29+0.86i 0.64+0.51i )
( 0.71+0.59i -0.15+0.19i 0.20+0.94i )
( 2.31 0.25-0.23i -0.81+0.83i )
B = ( 0.25+0.23i 2.26 -0.56+0.08i )
( -0.81-0.83i -0.56-0.08i 2.09 )
Sub Ex_Zgsgv()
Const N = 3, Nnz = 9, Nnz2 = 6, Ncv = 3, Nev = 2
Dim A(Nnz - 1) As Complex, Ia(N) As Long, Ja(Nnz - 1) As Long
Dim B(Nnz2 - 1) As Complex, Ib(N) As Long, Jb(Nnz2 - 1) As Long
Dim D(Nev - 1) As Complex, Z(N - 1, Nev - 1) As Complex
Dim Nconv As Long, Info As Long
A(0) = Cmplx(0.2, -0.11): A(1) = Cmplx(-0.93, -0.32): A(2) = Cmplx(0.81, 0.37): A(3) = Cmplx(-0.8, -0.92): A(4) = Cmplx(-0.29, 0.86): A(5) = Cmplx(0.64, 0.51): A(6) = Cmplx(0.71, 0.59): A(7) = Cmplx(-0.15, 0.19): A(8) = Cmplx(0.2, 0.94)
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(2.31): B(1) = Cmplx(0.25, 0.23): B(2) = Cmplx(2.26): B(3) = Cmplx(-0.81, -0.83): B(4) = Cmplx(-0.56, -0.08): B(5) = Cmplx(2.09)
Ib(0) = 0: Ib(1) = 1: Ib(2) = 3: Ib(3) = 6
Jb(0) = 0: Jb(1) = 0: Jb(2) = 1: Jb(3) = 0: Jb(4) = 1: Jb(5) = 2
Call Zgsgv("V", "L", N, A(), Ia(), Ja(), B(), Ib(), Jb(), "LM", Nev, Ncv, D(), Z(), Info, Nconv)
Debug.Print "D ="
Debug.Print Creal(D(0)), Cimag(D(0)), Creal(D(1)), Cimag(D(1))
Debug.Print "Z ="
Debug.Print Creal(Z(0, 0)), Cimag(Z(0, 0)), Creal(Z(0, 1)), Cimag(Z(0, 1))
Debug.Print Creal(Z(1, 0)), Cimag(Z(1, 0)), Creal(Z(1, 1)), Cimag(Z(1, 1))
Debug.Print Creal(Z(2, 0)), Cimag(Z(2, 0)), Creal(Z(2, 1)), Cimag(Z(2, 1))
Debug.Print "Nconv =" + Str(Nconv) + ", Info =" + Str(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 Zgsgv(Jobz As String, Uplo2 As String, N As Long, Val() As Complex, Ptr() As Long, Ind() As Long, Val2() As Complex, Ptr2() As Long, Ind2() As Long, Which As String, Nev As Long, Ncv As Long, D() As Complex, Z() As Complex, Optional Info As Long, Optional Nconv As Long, Optional Niter As Long, Optional Base As Long=-1, Optional Base2 As Long=-1, Optional Format As Long=0, Optional Mode As Long=2, Optional Sigmar As Double=0, Optional Sigmai As Double=0, Optional Maxiter As Long=300, Optional Tol As Double=0)
Generalized eigenvalue problem of a complex sparse matrix (implicitly restarted Arnoldi method (IRAM)...
Example Results
D =
0.790264815830272 0.731095506039657 0.144386602592976 0.763021818472598
Z =
-0.602926109593061 -2.54716468513815E-02 -6.04572102722823E-03 -0.162145611949676
0.174190955405643 -0.156732370014386 0.578522100432737 -5.20895534988314E-02
-0.403225790941503 -0.558909798961031 0.533641052631575 -0.179122219344393
Nconv = 2, Info = 0