|
|
◆ Dgesvd()
| Sub Dgesvd |
( |
Jobu As |
String, |
|
|
Jobvt As |
String, |
|
|
M As |
Long, |
|
|
N As |
Long, |
|
|
A() As |
Double, |
|
|
S() As |
Double, |
|
|
U() As |
Double, |
|
|
Vt() As |
Double, |
|
|
Info As |
Long |
|
) |
| |
(Simple driver) Singular value decomposition (SVD)
- Purpose
- This routine computes the singular value decomposition (SVD) of a real m x n matrix A, optionally computing the left and/or right singular vectors. The SVD is written where Σ is an m x n matrix which is zero except for its min(m, n) diagonal elements, U is an m x m orthogonal matrix, and V is an n x n orthogonal matrix. The diagonal elements of Σ 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^T, not V.
- Parameters
-
| [in] | Jobu | Specifies 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.
Note - Jobvt and Jobu cannot both be "O". |
| [in] | Jobvt | Specifies options for computing all or part of the matrix V^T:
= "A": All N rows of V^T are returned in the array Vt().
= "S": The first min(M, N) rows of V^T (the right singular vectors) are returned in the array Vt().
= "O": The first min(M, N) rows of V^T (the right singular vectors) are overwritten on the array A().
= "N": No rows of V^T (no right singular vectors) are computed.
Note - Jobvt and Jobu cannot both be "O". |
| [in] | M | Number of rows of the input matrix A. (M >= 0) (If M = 0, returns without computation) |
| [in] | N | Number 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^T (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 orthogonal 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 orthogonal matrix V^T.
Jobvt = "S": Vt() contains the first min(M, N) rows of V^T (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
( 1 6 11 )
( 2 7 12 )
A = ( 3 8 13 )
( 4 9 14 )
( 5 10 15 )
Sub Ex_Dgesvd()
Const M = 5, N = 3
Dim A(M - 1, N - 1) As Double, U(M - 1, N - 1) As Double, Vt(N - 1, N - 1) As Double
Dim S(N - 1) As Double, Info As Long
A(0, 0) = 1: A(0, 1) = 6: A(0, 2) = 11
A(1, 0) = 2: A(1, 1) = 7: A(1, 2) = 12
A(2, 0) = 3: A(2, 1) = 8: A(2, 2) = 13
A(3, 0) = 4: A(3, 1) = 9: A(3, 2) = 14
A(4, 0) = 5: A(4, 1) = 10: A(4, 2) = 15
Call Dgesvd("S", "A", M, N, A(), S(), U(), Vt(), Info)
Debug.Print "Singular values ="
Debug.Print S(0), S(1), S(2)
Debug.Print "U ="
Debug.Print U(0, 0), U(0, 1), U(0, 2)
Debug.Print U(1, 0), U(1, 1), U(1, 2)
Debug.Print U(2, 0), U(2, 1), U(2, 2)
Debug.Print U(3, 0), U(3, 1), U(3, 2)
Debug.Print U(4, 0), U(4, 1), U(4, 2)
Debug.Print "V^T ="
Debug.Print Vt(0, 0), Vt(0, 1), Vt(0, 2)
Debug.Print Vt(1, 0), Vt(1, 1), Vt(1, 2)
Debug.Print Vt(2, 0), Vt(2, 1), Vt(2, 2)
Debug.Print "Info =", Info
End Sub
Sub Dgesvd(Jobu As String, Jobvt As String, M As Long, N As Long, A() As Double, S() As Double, U() As Double, Vt() As Double, Info As Long) (Simple driver) Singular value decomposition (SVD)
- Example Results
Singular values =
35.1272233335747 2.46539669691652 1.26909062514315E-15
U =
-0.354557057037681 0.688686643768252 0.570044169987079
-0.398696369998832 0.375554529395871 -0.74547800114907
-0.442835682959984 6.24224150234906E-02 -0.170157929158505
-0.486974995921135 -0.25070969934889 0.296573181815902
-0.531114308882286 -0.56384181372127 4.90185785045937E-02
V^T =
-0.201664911192694 -0.516830501392304 -0.831996091591915
-0.890317132783019 -0.257331626824052 0.375653879134918
0.408248290463864 -0.816496580927726 0.408248290463863
Info = 0
|