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

◆ Dggsvd3()

Sub Dggsvd3 ( Jobu As  String,
Jobv As  String,
Jobq As  String,
M As  Long,
N As  Long,
P As  Long,
K As  Long,
L As  Long,
A() As  Double,
B() As  Double,
Alpha() As  Double,
Beta() As  Double,
U() As  Double,
V() As  Double,
Q() As  Double,
Info As  Long 
)

Generalized singular value decomposition (GSVD)

Purpose
This routine computes the generalized singular value decomposition (GSVD) of an M x N real matrix A and P x N real matrix B:
U^T*A*Q = D1*(0 R), V^T*B*Q = D2*(0 R)
where, U, V and Q are orthogonal matrices.

Let K+L = the effective numerical rank of the matrix (A^T, B^T)^T, then R is a K+L x K+L nonsingular upper triangular matrix, D1 and D2 are M x K+L and P x K+L "diagonal" matrices and of the following structures, respectively:

If M-K-L >= 0,
K L
D1 = K (I 0)
L (0 C)
M-K-L (0 0)
K L
D2 = L (0 S)
P-L (0 0)
N-K-L K L
(0 R) = K ( 0 R11 R12)
L ( 0 0 R22)
where
C = diag(Alpha(K), ... , Alpha(K+L-1)),
S = diag(Beta(K)), ... , Beta(K+L-1)),
C^2 + S^2 = I.
R is stored in A(0〜K+L-1, N-K-L〜N-1) on exit.
Function Beta(A As Double, B As Double, Optional Info As Long) As Double
Beta function B(a, b)
If M-K-L < 0,
K M-K K+L-M
D1 = K (I 0 0)
M-K (0 C 0)
K M-K K+L-M
D2 = M-K (0 S 0)
K+L-M (0 0 I)
P-L (0 0 0)
N-K-L K M-K K+L-M
(0 R) = K ( 0 R11 R12 R13)
M-K ( 0 0 R22 R23)
K+L-M ( 0 0 0 R33)
where
C = diag(Alpha(K), ... , Alpha(M-1)),
S = diag(Beta(K), ... , Beta(M-1)),
C^2 + S^2 = I.
(R11 R12 R13) is stored in A(0〜M-1, N-K-L〜N-1), and R33 is stored
( 0 R22 R23)
in B(M-K〜L-1, N+M-K-L〜N-1) on exit.
The routine computes C, S, R, and optionally the orthogonal transformation matrices U, V and Q.

In particular, if B is an N x N nonsingular matrix, then the GSVD of A and B implicitly gives the SVD of A*inv(B).
A*inv(B) = U*(D1*inv(D2))*V^T
If (A^T, B^T)^T has orthonormal columns, then the GSVD of A and B is also equal to the CS decomposition of A and B. Furthermore, the GSVD can be used to derive the solution of the eigenvalue problem:
A^T*A x = λ B^T*B x
In some literature, the GSVD of A and B is presented in the form
U^T*A*X = (0 D1), V^T*B*X = (0 D2)
where U and V are orthogonal and X is nonsingular, D1 and D2 are "diagonal". The former GSVD form can be converted to the latter form by taking the nonsingular matrix X as
X = Q*(I 0 )
(0 inv(R))
Parameters
[in]Jobu= 'U': Orthogonal matrix U is computed.
= 'N': U is not computed.
[in]Jobv= 'V': Orthogonal matrix V is computed.
= 'N': V is not computed.
[in]Jobq= "Q": Orthogonal matrix Q is computed.
= 'N': Q is not computed.
[in]MNumber of rows of the matrix A. (M >= 0)
[in]NNumber of columns of the matrices A and B. (N >= 0)
[in]PNumber of rows of the matrix B. (P >= 0)
[out]K
[out]LOn exit, K and L specify the dimension of the subblocks described in Purpose. (K + L = effective numerical rank of (A^T, B^T)^T).
[in,out]A()Array A(LA1 - 1, LA2 - 1) (LA1 >= M, LA2 >= N)
[in] M x N matrix A.
[out] A() contains the triangular matrix R, or part of R. See Purpose for details.
[in,out]B()Array B(LB1 - 1, LB2 - 1) (LB1 >= P, LB2 >= N)
[in] P x N matrix B.
[out] B() contains the triangular matrix R if M-K-L < 0. See Purpose for details.
[out]Alpha()Array Alpha(LAlpha - 1) (LAlpha >= N)
[out]Beta()Array Beta(LBeta - 1) (LBeta >= N)
Alpha() and Beta() contain the generalized singular value pairs of A and B.
  Alpha(0 to K-1) = 1,
  Beta(0 to K-1) = 0,
and if M-K-L >= 0,
  Alpha(K to K+L-1) = C,
  Beta(K to K+L-1) = S,
or if M-K-L < 0,
  Alpha(K to M-1)= C, Alpha(M to K+L-1) = 0,
  Beta(K to M-1) = S, Beta(M to K+L-1) = 1,
and
  Alpha(K+L to N-1) = 0,
  Beta(K+L to N-1) = 0.
[out]U()Array U(LU1 - 1, LU2 - 1) (LU1 >= M, LU2 >= M)
Jobu = 'U': U() contains the M x M orthogonal matrix U.
Jobu = 'N': U() is not referenced.
[out]V()Array V(LV1 - 1, LV2 - 1) (LV1 >= P, LV2 >= P)
Jobv = 'V': V() contains the P x P orthogonal matrix V.
Jobv = 'N': V() is not referenced.
[out]Q()Array Q(LQ1 - 1, LQ2 - 1) (LQ1 >= N, LQ2 >= N)
Jobq = 'Q': Q() contains the N x N orthogonal matrix Q.
Jobq = 'N': Q() is not referenced.
[out]Info= 0: Successful exit.
= -1: The argument Jobu had an illegal value. (Jobu <> "U" nor "N")
= -2: The argument Jobv had an illegal value. (Jobv <> "V" nor "N")
= -3: The argument Jobq had an illegal value. (Jobq <> "Q" nor "N")
= -4: The argument M had an illegal value. (M < 0)
= -5: The argument N had an illegal value. (N < 0)
= -6: The argument P had an illegal value. (P < 0)
= -9: The argument A() is invalid.
= -10: The argument B() is invalid.
= -11: The argument Alpha() is invalid.
= -12: The argument Beta() is invalid.
= -13: The argument U() is invalid.
= -14: The argument V() is invalid.
= -15: The argument Q() is invalid.
= 1: The Jacobi-type procedure failed to converge.
Reference
LAPACK
Example Program
Compute generalized singular value decomposition (GSVD) of matrix A and B, where
( 1 6 11 ) ( 1 5 9 )
( 2 7 12 ) ( 2 6 10 )
A = ( 3 8 13 ), B = ( 3 7 11 )
( 4 9 14 ) ( 4 8 12 )
( 5 10 15 )
Sub Ex_Dggsvd3()
Const M = 5, N = 3, P = 4
Dim A(M - 1, N - 1) As Double, B(P - 1, N - 1) As Double
Dim Alpha(N - 1) As Double, Beta(N - 1) As Double
Dim U(M - 1, M - 1) As Double, V(P - 1, P - 1) As Double, Q(N - 1, N - 1) As Double
Dim K As Long, L As Long, 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
B(0, 0) = 1: B(0, 1) = 5: B(0, 2) = 9
B(1, 0) = 2: B(1, 1) = 6: B(1, 2) = 10
B(2, 0) = 3: B(2, 1) = 7: B(2, 2) = 11
B(3, 0) = 4: B(3, 1) = 8: B(3, 2) = 12
Call Dggsvd3("U", "V", "Q", M, N, P, K, L, A(), B(), Alpha(), Beta(), U(), V(), Q(), Info)
Debug.Print "Alpha =", Alpha(0), Alpha(1), Alpha(2)
Debug.Print "Beta =", Beta(0), Beta(1), Beta(2)
Debug.Print "R ="
Debug.Print A(0, 0), A(0, 1), A(0, 2)
Debug.Print A(1, 0), A(1, 1), A(1, 2)
Debug.Print A(2, 0), A(2, 1), A(2, 2)
Debug.Print "U ="
Debug.Print U(0, 0), U(0, 1), U(0, 2), U(0, 3), U(0, 4)
Debug.Print U(1, 0), U(1, 1), U(1, 2), U(1, 3), U(1, 4)
Debug.Print U(2, 0), U(2, 1), U(2, 2), U(2, 3), U(2, 4)
Debug.Print U(3, 0), U(3, 1), U(3, 2), U(3, 3), U(3, 4)
Debug.Print U(4, 0), U(4, 1), U(4, 2), U(4, 3), U(4, 4)
Debug.Print "V ="
Debug.Print V(0, 0), V(0, 1), V(0, 2), V(0, 3)
Debug.Print V(1, 0), V(1, 1), V(1, 2), V(1, 3)
Debug.Print V(2, 0), V(2, 1), V(2, 2), V(2, 3)
Debug.Print V(3, 0), V(3, 1), V(3, 2), V(3, 3)
Debug.Print "Q ="
Debug.Print Q(0, 0), Q(0, 1), Q(0, 2)
Debug.Print Q(1, 0), Q(1, 1), Q(1, 2)
Debug.Print Q(2, 0), Q(2, 1), Q(2, 2)
Debug.Print "K =", K, "L =", L, "Info =", Info
End Sub
Sub Dggsvd3(Jobu As String, Jobv As String, Jobq As String, M As Long, N As Long, P As Long, K As Long, L As Long, A() As Double, B() As Double, Alpha() As Double, Beta() As Double, U() As Double, V() As Double, Q() As Double, Info As Long)
Generalized singular value decomposition (GSVD)
Example Results
Alpha = 0.802331750723485 0.826878800377287 0
Beta = 0.596878347555838 0.56238016455652 0
R =
0 -5.40364104666407 -35.7382954334068
0 0 24.1572950255889
0 0 0
U =
-9.72172871075144E-02 -0.768471729530407 -0.369047538143976 -0.45043765685718 -0.246799173164912
0.116318998962025 -0.535228820674366 1.34135766249015E-02 0.516457650749435 0.658096931268109
0.329855285031565 -0.301985911818325 0.857835814511989 -0.145130339105955 -0.207496746990269
0.543391571101105 -6.87430029622829E-02 -0.279722206322779 0.542638353392326 -0.572100607164143
0.756927857170645 0.164499905893758 -0.222479646670135 -0.463528008178625 0.368299596051215
V =
-4.71369494280112E-02 -0.835331136734781 0.537498761722548 0.105333191097239
0.239901343964157 -0.492389424301732 -0.795175740823531 0.260183668214875
0.526939637356325 -0.149447711868684 -2.21448035205818E-02 -0.836366909721466
0.813977930748493 0.193494000564365 0.279821782621565 0.470850050409352
Q =
0.408248290463863 -0.906218690095711 -0.1100046319686
-0.816496580927726 -0.308596432505139 -0.487956530009011
0.408248290463863 0.289025825085432 -0.865908428049421
K = 0 L = 2 Info = 0