XLPack 6.1
Excel VBA Numerical Library Reference Manual
Loading...
Searching...
No Matches

◆ Zgesvd()

Sub Zgesvd ( Jobu As  String,
Jobvt As  String,
M As  Long,
N As  Long,
A() As  Complex,
S() As  Double,
U() As  Complex,
Vt() As  Complex,
Info As  Long 
)

(Simple driver) Singular value decomposition (SVD) of a complex matrix

Purpose
This routine computes the singular value decomposition (SVD) of a complex M x N matrix A, optionally computing the left and/or right singular vectors. The SVD is written
A = U * SIGMA * V^H
where SIGMA is an M x N matrix which is zero except for its min(M, N) diagonal elements, U is an M x M unitary matrix, and V is an N x N unitary matrix. The diagonal elements of SIGMA are the singular values of A. They are real and non-negative, and are returned in descending order. The first min(M, N) columns of U and V are the left and right singular vectors of A.

Note that the routine returns V^H, not V.
Parameters
[in]JobuSpecifies options for computing all or part of the matrix U:
= "A": All M columns of U are returned in array U().
= "S": The first min(M, N) columns of U (the left singular vectors) are returned in the array U().
= "O": The first min(M, N) columns of U (the left singular vectors) are overwritten on the array A().
= "N": No columns of U (no left singular vectors) are computed.
[in]JobvtSpecifies options for computing all or part of the matrix V^H:
= "A": All N rows of V^H are returned in the array Vt().
= "S": The first min(M, N) rows of V^H (the right singular vectors) are returned in the array Vt().
= "O": The first min(M, N) rows of V^H (the right singular vectors) are overwritten on the array A().
= "N": No rows of V^H (no right singular vectors) are computed.
Jobvt and Jobu cannot both be "O".
[in]MNumber of rows of the input matrix A. (M >= 0) (If M = 0, returns without computation)
[in]NNumber of columns of the input matrix A. (N >= 0) (If N = 0, returns without computation)
[in,out]A()Array A(LA1 - 1, LA2 - 1) (LA1 >= M, LA2 >= N)
[in] M x N matrix A.
[out] Jobu = "O": A() is overwritten with the first min(M, N) columns of U (the left singular vectors, stored columnwise).
  Jobvt = "O": A() is overwritten with the first min(M, N) rows of V^H (the right singular vectors, stored rowwise).
  Jobu <> "O" and Jobvt <> "O": The contents of A() are destroyed.
[out]S()Array S(LS - 1) (LS >= min(M, N))
The singular values of A, sorted so that S(i) >= S(i+1).
[out]U()Array U(LU1 - 1, LU2 - 1) (LU1 >= M, LU2 >= M (Jobu = "A") or LU2 >= min(M, N) (Jobu = "S"))
Jobu = "A": U() contains the M x M unitary matrix U.
Jobu = "S": U() contains the first min(M, N) columns of U (the left singular vectors, stored columnwise).
Jobu = "N" or "O": U() is not referenced.
[out]Vt()Array Vt(LVt1 - 1, LVt2 - 1) (LVt1 >= N (JobVt = "A") or LVt1 >= min(M, N) (Jobvt = "S"), LVt2 >= N)
Jobvt = "A": Vt() contains the n x n unitary matrix V^H.
Jobvt = "S": Vt() contains the first min(M, N) rows of V^H (the right singular vectors, stored rowwise).
Jobvt = "N" or "O": Vt() is not referenced.
[out]Info= 0: Successful exit.
= -1: The argument Jobu had an illegal value. (Jobu <> "A", "S", "O" nor "N")
= -2: The argument Jobvt had an illegal value. (Jobvt <> "A", "S", "O" nor "N")
= -3: The argument M had an illegal value. (M < 0)
= -4: The argument N had an illegal value. (N < 0)
= -5: The argument A() is invalid.
= -6: The argument S() is invalid.
= -7: The argument U() is invalid.
= -8: The argument Vt() is invalid.
> 0: If Dbdsqr did not converge, info specifies how many super-diagonals of an intermediate bidiagonal form B did not converge to zero.
Reference
LAPACK
Example Program
Compute singular values and left and right 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_Zgesvd()
Const M = 3, N = 3
Dim A(M - 1, N - 1) As Complex, U(M - 1, N - 1) As Complex, Vt(N - 1, N - 1) As Complex
Dim S(N - 1) As Double, Info As Long
A(0, 0) = Cmplx(0.2, -0.11): A(0, 1) = Cmplx(-0.93, -0.32): A(0, 2) = Cmplx(0.81, 0.37)
A(1, 0) = Cmplx(-0.8, -0.92): A(1, 1) = Cmplx(-0.29, 0.86): A(1, 2) = Cmplx(0.64, 0.51)
A(2, 0) = Cmplx(0.71, 0.59): A(2, 1) = Cmplx(-0.15, 0.19): A(2, 2) = Cmplx(0.2, 0.94)
Call Zgesvd("S", "A", M, N, A(), S(), U(), Vt(), Info)
Debug.Print "Singular values =", S(0), S(1), S(2)
Debug.Print "U ="
Debug.Print Creal(U(0, 0)), Cimag(U(0, 0)), Creal(U(0, 1)), Cimag(U(0, 1))
Debug.Print Creal(U(1, 0)), Cimag(U(1, 0)), Creal(U(1, 1)), Cimag(U(1, 1))
Debug.Print Creal(U(2, 0)), Cimag(U(2, 0)), Creal(U(2, 1)), Cimag(U(2, 1))
Debug.Print Creal(U(0, 2)), Cimag(U(0, 2))
Debug.Print Creal(U(1, 2)), Cimag(U(1, 2))
Debug.Print Creal(U(2, 2)), Cimag(U(2, 2))
Debug.Print "V^H ="
Debug.Print Creal(Vt(0, 0)), Cimag(Vt(0, 0)), Creal(Vt(0, 1)), Cimag(Vt(0, 1))
Debug.Print Creal(Vt(1, 0)), Cimag(Vt(1, 0)), Creal(Vt(1, 1)), Cimag(Vt(1, 1))
Debug.Print Creal(Vt(2, 0)), Cimag(Vt(2, 0)), Creal(Vt(2, 1)), Cimag(Vt(2, 1))
Debug.Print Creal(Vt(0, 2)), Cimag(Vt(0, 2))
Debug.Print Creal(Vt(1, 2)), Cimag(Vt(1, 2))
Debug.Print Creal(Vt(2, 2)), Cimag(Vt(2, 2))
Debug.Print "Info =", Info
End Sub
Example Results
Singular values = 2.07084030821889 1.23513084760163 0.901483337149816
U =
-0.322093837376809 0.402732043434636 9.95958553097355E-02 0.309610800223195
0.25572227156877 0.689932737910446 -0.631621088952191 3.70329357348017E-02
-0.438560869464762 1.80488745428174E-02 -7.00863751874233E-02 0.699280401316292
0.711819740685389 -0.348707521966052
-9.32902099996816E-02 0.222663951646943
-0.55115638604919 -9.82856061041459E-02
V^H =
-0.603023132575377 0 0.366551261475641 0.394522570687146
0.663818465313821 -0 0.134961467338043 -0.149629139353428
-0.44238913491109 0 -0.297134277147366 -0.762299060909463
0.16075433957414 -0.566138903287951
0.366911928609536 -0.61977189734833
0.331437452593181 -0.158279598849071
Info = 0