1 SUBROUTINE QRFAQF
(QT
,R
,N
,IFLAG
)
3 C SUBROUTINE QRFAQF COMPUTES THE QR FACTORIZATION OF A MATRIX A,
4 C WHERE R IS AN UPPER TRIANGULAR MATRIX, AND Q IS AN ORTHOGONAL
5 C MATRIX WHICH IS THE PRODUCT OF N-1 HOUSEHOLDER TRANSFORMATIONS
9 C THE ROUTINE HAS TWO MAJOR STEPS. FIRST, THE QR FACTORIZATION
10 C OF A IS COMPUTED, RESULTING IN DEFINING THE VECTOR R, AND
11 C STORING INFORMATION IN THE LOWER TRIANGLE OF QT WHICH WILL
12 C ENABLE THE CONSTRUCTION OF Q TRANSPOSE.
14 C THE SECOND STEP CONSTRUCTS Q TRANSPOSE FROM THE INFORMATION
15 C STORED IN QT, AND PLACES IT IN QT.
17 C THE INFORMATION STORED IN THE LOWER TRIANGLE OF QT DURING THE FIRST
18 C STEP ARE THE VECTORS UJ, WHICH DEFINE THE HOUSEHOLDER TRANSFORMATIONS
21 C HJ = I - (UJ*UJ / PJ), WHERE UJ[I]=0 FOR I=1...J-1,
22 C UJ[I]=QT[I,J], FOR I=J...N,
23 C PJ = THE JTH COMPONENT OF UJ.
28 C QT(1:N,1:N) CONTAINS THE MATRIX A TO BE FACTORED.
30 C R(1:N*(N+1)/2) IS UNDEFINED.
32 C N IS THE DIMENSION OF THE MATRIX TO BE FACTORED.
39 C QT CONTAINS Q TRANSPOSE.
41 C R(1:N*(N+1)/2) CONTAINS THE UPPER TRIANGLE OF R STORED BY ROWS.
45 C IFLAG = 4 IF THE MATRIX A IS SINGULAR. OTHERWISE, IFLAG
49 C CALLS DAXPY, DCOPY, DDOT, DNRM2, DSCAL.
51 C ***** DECLARATIONS *****
53 C FUNCTION DECLARATIONS
55 DOUBLE PRECISION DDOT
, DNRM2
59 DOUBLE PRECISION ONE
, TAU
, TEMP
60 INTEGER I
, J
, K
, INDEXR
, ISIGN
68 DOUBLE PRECISION QT
(N
,N
),R
(N
)
70 C ***** END OF DECLARATIONS *****
72 C ***** FIRST EXECUTABLE STATEMENT *****
76 C ***** CALCULATION OF QR DECOMPOSITION, PLACING R IN THE VECTOR *****
77 C R, AND PLACING THE UJ VECTORS IN THE LOWER TRIANGLE OF
82 TEMP
= DNRM2
(N
-K
+1,QT
(K
,K
),1)
83 IF (TEMP
.EQ
. 0.0) THEN
85 C MATRIX IS SINGULAR, SET IFLAG AND RETURN.
91 C FORM QK AND PREMULTIPLY QT BY IT.
93 C UK = EK - ISIGN*X/||X||, WHERE HK = I-(UK*UK /PK),
94 C PK = THE KTH COMPONENT OF UK,
95 C EK = THE KTH NATURAL BASIS VECTOR,
96 C X = THE KTH COLUMN OF THE MATRIX H(K-1)...H2*H1*QT,
97 C ISIGN = THE SIGN OF PK.
101 ISIGN
= SIGN
(ONE
,QT
(K
,K
))
105 R
(INDEXR
) = -ISIGN*TEMP
110 CALL DSCAL
(N
-K
+1,TEMP
,QT
(K
,K
),1)
111 QT
(K
,K
) = QT
(K
,K
) + 1.0
113 C UPDATE THE K+1ST - NTH COLUMNS OF QT, AND R.
117 TAU
= DDOT
(N
-K
+1,QT
(K
,K
),1,QT
(K
,J
),1)/QT
(K
,K
)
118 R
(INDEXR
) = QT
(K
,J
) - TAU*QT
(K
,K
)
120 CALL DAXPY
(N
-K
,-TAU
,QT
(K
+1,K
),1,QT
(K
+1,J
),1)
124 IF (QT
(N
,N
) .EQ
. 0.0) THEN
126 C MATRIX IS SINGULAR, SET IFLAG AND RETURN.
133 C ***** END OF FACTORING STEP *****
135 C ***** CONSTRUCT Q TRANSPOSE IN QT *****
137 C FORM Q BY MULTIPLYING ((I*H(N-1))*...)*H1.
138 C THIS IS DONE IN PLACE IN QT BY UPDATING ONLY THE LOWER
139 C RIGHT HAND CORNER OF QT (QT(K,K) TO QT(N,N)).
145 C MULTIPLY QT BY H(K).
151 QT
(K
,K
) = 1.0-QT
(K
,K
)
152 CALL DCOPY
(N
-K
,QT
(K
+1,K
),1,QT
(K
,K
+1),N
)
153 CALL DSCAL
(N
-K
,-ONE
,QT
(K
,K
+1),N
)
155 C UPDATE REMAINING ROWS.
158 TAU
= -DDOT
(N
-K
,QT
(I
,K
+1),N
,QT
(K
,K
+1),N
)
161 CALL DAXPY
(N
-K
,TAU
,QT
(K
,K
+1),N
,QT
(I
,K
+1),N
)
165 C ***** END OF Q TRANSPOSE CONSTRUCTION *****
169 C ***** END OF SUBROUTINE QRFAQF *****