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

◆ Dgeqp3()

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

QR factorization with pivoting

Purpose
This routine computes a QR factorization with column pivoting of a matrix A:
A * P = Q * R
using Level 3 BLAS.
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 upper triangle of the array contains the min(M, N) x N upper trapezoidal matrix R; the elements below the diagonal, together with the array Tau(), represent the orthogonal matrix Q as a product of min(M, N) elementary reflectors.
[in,out]Jpvt()Array Jpvt(LJpvt - 1) (LJpvt >= N)
[in] If Jpvt(j-1) <> 0, the j-th column of A is permuted to the front of A*P (a leading column); if Jpvt(j-1) = 0, the j-th column of A is a free column.
[out] If Jpvt(j-1) = k, then the j-th column of A*P was the the k-th column of A.
[out]Tau()Array Tau(LTau - 1) (LTau >= min(M, N))
The scalar factors of the elementary reflectors.
[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 Jpvt() is invalid.
= -5: The argument Tau() is invalid.
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_Dgeqp3()
Const M = 3, N = 3, K = N
Dim A(M - 1, N - 1) As Double, Jpvt(N - 1) As Long, Tau(N - 1) As Double
Dim Info As Long, I 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
For I = 0 To N - 1
Jpvt(I) = 1
Next
'-- Compute QR factorization of A
Call Dgeqp3(M, N, A(), Jpvt(), 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 "Jpvt =", Jpvt(0), Jpvt(1), Jpvt(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 Dgeqp3(M As Long, N As Long, A() As Double, Jpvt() As Long, Tau() As Double, Info As Long)
QR factorization with pivoting
Example Results
R =
-0.884533775499839 -0.514169173181655 8.18510293279503E-02
-1.11813687057967 -0.635776616242947
-0.821576839520579
Jpvt = 1 2 3
Info = 0
Q =
-0.226107815823067 0.202352390539057 0.952852961199602
0.361772505316908 -0.890778487093709 0.275016983707865
0.904431263292269 0.406899492472248 0.128206446816755
Info = 0