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

◆ Dgeqrf()

Sub Dgeqrf ( M As  Long,
N As  Long,
A() As  Double,
Tau() As  Double,
Info As  Long 
)

QR factorization

Purpose
This routine computes a QR factorization of a real m x n matrix A.
A = Q * R
Parameters
[in]MNumber of rows of the matrix A. (M >= 0) (If M = 0, returns without computation)
[in]NNumber of columns of the 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] The elements on and above the diagonal of the array contains the min(M, N) x N upper trapezoidal matrix R (R is upper triangular if M >= N); the elements below the diagonal, with the array Tau(), represent the orthogonal matrix Q as a product of min(M, N) elementary reflectors (see Further Details).
[out]Tau()Array Tau(LTau - 1) (LTau >= min(M, N))
The scalar factors of the elementary reflectors (see Further Details).
[out]Info= 0: Successful exit.
= -1: The argument M had an illegal value. (M < 0)
= -2: The argument N had an illegal value. (N < 0)
= -3: The argument A() is invalid.
= -4: The argument Tau() is invalid.
Further Details
The matrix Q is represented as a product of elementary reflectors
Q = H(1) H(2) . . . H(k), where k = min(M, N).
Each H(i) has the form
H(i) = I - tau * v * v^T
where tau is a real scalar, and v is a real vector with v(1 to i-1) = 0 and v(i) = 1; v(i+1 to M) is stored on exit in A(i to M-1, i-1), and tau in Tau(i-1).
Reference
LAPACK
Example Program
Compute QR factorization of the matrix A, where
( 2.20 -0.11 -0.32 )
A = ( -0.11 2.93 0.81 )
( -0.32 0.81 2.37 )
Sub Ex_Dgeqrf()
Const M = 3, N = 3, K = N
Dim A(M - 1, N - 1) As Double, Tau(N - 1) As Double, Info 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)
Debug.Print "R ="
Debug.Print A(0, 0), A(0, 1), A(0, 2)
Debug.Print A(1, 1), A(1, 2)
Debug.Print A(2, 2)
Debug.Print "Info =", Info
'-- Compute Q
Call Dorgqr(M, N, K, A(), Tau(), Info)
Debug.Print "Q ="
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 "Info =", Info
End Sub
Sub Dorgqr(M As Long, N As Long, K As Long, A() As Double, Tau() As Double, Info As Long)
Generates matrix 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
-1.11813687057967 -0.635776616242947
-0.821576839520579
Info = 0
Q =
-0.226107815823067 0.202352390539057 0.952852961199602
0.361772505316908 -0.890778487093709 0.275016983707865
0.904431263292269 0.406899492472248 0.128206446816755
Info = 0