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

◆ Dormqr()

Sub Dormqr ( Side As  String,
Trans As  String,
M As  Long,
N As  Long,
K As  Long,
A() As  Double,
Tau() As  Double,
C() As  Double,
Info As  Long 
)

Multiplies matrix by Q of QR factorization

Purpose
This routine overwrites the general real m x n matrix C with
Side = "L" Side = "R"
Trans = "N": Q * C C * Q
Trans = "T": Q^T * C C * Q^T
where Q is a real orthogonal matrix defined as the product of k elementary reflectors
Q = H(1) H(2) . . . H(k)
as returned by Dgeqrf. Q is of order m if Side = "L" and of order n if Side = "R".
Parameters
[in]Side= "L": Apply Q or Q^T from the left.
= "R": Apply Q or Q^T from the right.
[in]Trans= "N": No transpose, apply Q.
= "T": Transpose, apply Q^T.
[in]MNumber of rows of the matrix C. (M >= 0) (If M = 0, returns without computation)
[in]NNumber of columns of the matrix C. (N >= 0) (If N = 0, returns without computation)
[in]KNumber of elementary reflectors whose product defines the matrix Q. (M => K >= 0 if Side = "L", N >= K >= 0 if Side = "R") (If K = 0, returns without computation)
[in]A()Array A(LA1 - 1, LA2 - 1) (LA1 >= M (Side = "L") or N (Side = "R"), LA2 >= K)
The i-th column must contain the vector which defines the elementary reflector H(i), for i = 1, 2, ..., K, as returned by Dgeqrf in the first K columns of its array argument A().
[in]Tau()Array Tau(LTau - 1) (LTau >= K)
The scalar factors of the elementary reflectors H(i) as returned by Dgeqrf.
[in,out]C()Array C(LC1 - 1, LC2 - 1) (LC1 >= M, LC2 >= N)
[in] M x N matrix C.
[out] C() is overwritten by Q*C or Q^T*C or C*Q^T or C*Q.
[out]Info= 0: Successful exit.
= -1: The argument Side had an illegal value. (Side <> "L" nor "R")
= -2: The argument Trans had an illegal value. (Trans <> "T" 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 K had an illegal value. (K < 0, or K > M (Side = "L") or N (Side = "R"))
= -6: The argument A() is invalid.
= -7: The argument Tau() is invalid.
= -8: The argument C() is invalid.
Reference
LAPACK
Example Program
Compute QR factorization of the matrix A, and compute Q*R, where
( 2.20 -0.11 -0.32 )
A = ( -0.11 2.93 0.81 )
( -0.32 0.81 2.37 )
Sub Ex_Dormqr()
Const M = 3, N = 3, K = N
Dim A(M - 1, N - 1) As Double, Tau(N - 1) As Double, Info As Long
Dim R(M - 1, N - 1) As Double, I As Long, J As Long
A(0, 0) = 0.2: A(0, 1) = -0.11: A(0, 2) = -0.93
A(1, 0) = -0.32: A(1, 1) = 0.81: A(1, 2) = 0.37
A(2, 0) = -0.8: A(2, 1) = -0.92: A(2, 2) = -0.29
'-- Compute QR factorization of A
Call Dgeqrf(M, N, A(), Tau(), Info)
For I = 0 To M - 1
For J = I To N - 1
R(I, J) = A(I, J)
Next
Next
Debug.Print "R ="
Debug.Print R(0, 0), R(0, 1), R(0, 2)
Debug.Print R(1, 0), R(1, 1), R(1, 2)
Debug.Print R(2, 0), R(2, 1), R(2, 2)
Debug.Print "Info =", Info
'-- Compute Q*R
Call Dormqr("L", "N", M, N, K, A(), Tau(), R(), Info)
Debug.Print "Q*R ="
Debug.Print R(0, 0), R(0, 1), R(0, 2)
Debug.Print R(1, 0), R(1, 1), R(1, 2)
Debug.Print R(2, 0), R(2, 1), R(2, 2)
Debug.Print "Info =", Info
End Sub
Sub Dormqr(Side As String, Trans As String, M As Long, N As Long, K As Long, A() As Double, Tau() As Double, C() As Double, Info As Long)
Multiplies matrix by Q of QR factorization
Sub Dgeqrf(M As Long, N As Long, A() As Double, Tau() As Double, Info As Long)
QR factorization
Example Results
R =
-0.884533775499839 -0.514169173181655 8.18510293279503E-02
0 -1.11813687057967 -0.635776616242947
0 0 -0.821576839520579
Info = 0
Q*R =
0.2 -0.11 -0.93
-0.32 0.81 0.37
-0.8 -0.92 -0.29
Info = 0