|
|
◆ Zgssvd()
| Sub Zgssvd |
( |
Jobv As |
String, |
|
|
Jobu As |
String, |
|
|
M As |
Long, |
|
|
N As |
Long, |
|
|
Val() As |
Complex, |
|
|
Ptr() As |
Long, |
|
|
Ind() As |
Long, |
|
|
Which As |
String, |
|
|
Nev As |
Long, |
|
|
Ncv As |
Long, |
|
|
S() As |
Double, |
|
|
V() As |
Complex, |
|
|
U() As |
Complex, |
|
|
Optional Info As |
Long, |
|
|
Optional Nconv As |
Long, |
|
|
Optional Niter As |
Long, |
|
|
Optional Base As |
Long = -1, |
|
|
Optional Format As |
Long = 0, |
|
|
Optional Maxiter As |
Long = 300, |
|
|
Optional Tol As |
Double = 0 |
|
) |
| |
Singular value decomposition (SVD) of a complex sparse matrix (implicitly restarted Arnoldi method (IRAM)) (Arpack) (driver)
- Purpose
- The singular values (s) and corresponding right singular vectors (v) for the the matrix A are computed by solving the symmetric eigenvalue problem: where A is an M by N complex sparse matrix. The left singular vectors are also computed by u = A*v/s if required.
The sparse matrix is stored in CSC or CSR format.
The eigenvalue problem is solved by the implicitly restarted Arnoldi method (IRAM) using Arpack routines Zsaupd and Zseupd.
- Parameters
-
| [in] | Jobv | = 'N': Do not compute right singular vector(s).
= 'V': Compute right singular vector(s). |
| [in] | Jobu | = 'N': Do not compute left singular vector(s).
= 'V': Compute left singular vector(s). (Jobv must also be 'V'.) |
| [in] | M | Number of rows of the matrix. (M >= 0) (If M = 0, returns without computation) |
| [in] | N | Number of 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 input matrix (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 input matrix. |
| [in] | Ind() | Array Ind(LInd - 1) (LInd >= Nnz)
Row indices (if CSC) or column indices (if CSR) of input matrix (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] | Nev | Number of singular values to be computed. (0 < Nev < N) |
| [in] | Ncv | This will indicate how many Arnoldi vectors are generated at each iteration. (Nev < Ncv <= N) (Ncv >= 2*Nev is recommended) |
| [out] | S() | Array S(LS - 1) (LS >= Nev)
Contains the singular values of A. |
| [out] | V() | Array V(LV1 - 1, LV2 - 1) (LV1 >= N, LV2 >= Nev)
Nev right singular vectors. Not referenced if Jobv = 'N'. |
| [out] | U() | Array U(LU1 - 1, LU2 - 1) (LU1 >= M, LU2 >= Nev)
Nev left singular vectors. Not referenced if Jobu = 'N'. |
| [out] | Info | Return 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 17: Internal code error. |
| [out] | Nconv | (Optional)
Number of Ritz values that satisfy the convergence criterion. |
| [out] | Niter | (Optional)
Number of Arnoldi 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] | Format | (Optional)
Sparse matrix format. (default = 0)
= 0: CSR format.
= 1: CSC format. |
| [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 largest two singular values and their singular vectors of matrix A 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 )
Sub Ex_Zgssvd()
Const M = 3, N = 3, Nnz = M * N, Ncv = 3, Nev = 2
Dim A(Nnz - 1) As Complex, Ia(M) As Long, Ja(Nnz - 1) As Long
Dim S(Nev - 1) As Double, V(N - 1, Nev - 1) As Complex, U(M - 1, Nev - 1) As Complex
Dim Nconv As Long, Niter As Long, Info As Long, J 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
Call Zgssvd("V", "V", M, N, A(), Ia(), Ja(), "LM", Nev, Ncv, S(), V(), U(), Info, Nconv)
Debug.Print "S ="
Debug.Print S(0), S(1)
Debug.Print "U ="
Debug.Print "V ="
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 Zgssvd(Jobv As String, Jobu As String, M As Long, N As Long, Val() As Complex, Ptr() As Long, Ind() As Long, Which As String, Nev As Long, Ncv As Long, S() As Double, V() As Complex, U() As Complex, Optional Info As Long, Optional Nconv As Long, Optional Niter As Long, Optional Base As Long=-1, Optional Format As Long=0, Optional Maxiter As Long=300, Optional Tol As Double=0) Singular value decomposition (SVD) of a complex sparse matrix (implicitly restarted Arnoldi method (I...
- Example Results
S =
2.07084030821889 1.23513084760163
U =
-0.499319835042685 -0.128907878805375 0.30744761793176 -0.106085551503547
-0.524690775955828 0.515849447652865 5.03089827914885E-02 0.63070250085819
-0.196074791420937 -0.392703545014794 0.700599777834659 5.53636247911296E-02
V =
-0.246963110991103 -0.550132820535747 -1.39614130074507E-02 -0.663671631033324
0.510037572083399 0.172828125992991 0.146757535786758 -0.138078610579205
-0.450648051781491 0.378512283728743 0.611917923700831 -0.37986579571262
Nconv = 2, Info = 0
|