orthor.f 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. *DECK ORTHOR
  2. SUBROUTINE ORTHOR (A, N, M, NRDA, IFLAG, IRANK, ISCALE, DIAG,
  3. + KPIVOT, SCALES, ROWS, RS)
  4. C***BEGIN PROLOGUE ORTHOR
  5. C***SUBSIDIARY
  6. C***PURPOSE Subsidiary to BVSUP
  7. C***LIBRARY SLATEC
  8. C***TYPE SINGLE PRECISION (ORTHOR-S, DORTHR-D)
  9. C***AUTHOR Watts, H. A., (SNLA)
  10. C***DESCRIPTION
  11. C
  12. C Reduction of the matrix A to lower triangular form by a sequence of
  13. C orthogonal HOUSEHOLDER transformations post-multiplying A
  14. C
  15. C Modeled after the ALGOL codes in the articles in the REFERENCES
  16. C section.
  17. C
  18. C **********************************************************************
  19. C INPUT
  20. C **********************************************************************
  21. C
  22. C A -- Contains the matrix to be decomposed, must be dimensioned
  23. C NRDA by N
  24. C N -- Number of rows in the matrix, N greater or equal to 1
  25. C M -- Number of columns in the matrix, M greater or equal to N
  26. C IFLAG -- Indicates the uncertainty in the matrix data
  27. C = 0 when the data is to be treated as exact
  28. C =-K when the data is assumed to be accurate to about
  29. C K digits
  30. C ISCALE -- Scaling indicator
  31. C =-1 if the matrix is to be pre-scaled by
  32. C columns when appropriate.
  33. C Otherwise no scaling will be attempted
  34. C NRDA -- Row dimension of A, NRDA greater or equal to N
  35. C DIAG,KPIVOT,ROWS -- Arrays of length at least N used internally
  36. C ,RS,SCALES (except for SCALES which is M)
  37. C
  38. C **********************************************************************
  39. C OUTPUT
  40. C **********************************************************************
  41. C
  42. C IFLAG - status indicator
  43. C =1 for successful decomposition
  44. C =2 if improper input is detected
  45. C =3 if rank of the matrix is less than N
  46. C A -- contains the reduced matrix in the strictly lower triangular
  47. C part and transformation information
  48. C IRANK -- contains the numerically determined matrix rank
  49. C DIAG -- contains the diagonal elements of the reduced
  50. C triangular matrix
  51. C KPIVOT -- Contains the pivotal information, the column
  52. C interchanges performed on the original matrix are
  53. C recorded here.
  54. C SCALES -- contains the column scaling parameters
  55. C
  56. C **********************************************************************
  57. C
  58. C***SEE ALSO BVSUP
  59. C***REFERENCES G. Golub, Numerical methods for solving linear least
  60. C squares problems, Numerische Mathematik 7, (1965),
  61. C pp. 206-216.
  62. C P. Businger and G. Golub, Linear least squares
  63. C solutions by Householder transformations, Numerische
  64. C Mathematik 7, (1965), pp. 269-276.
  65. C***ROUTINES CALLED CSCALE, R1MACH, SDOT, XERMSG
  66. C***REVISION HISTORY (YYMMDD)
  67. C 750601 DATE WRITTEN
  68. C 890531 Changed all specific intrinsics to generic. (WRB)
  69. C 890831 Modified array declarations. (WRB)
  70. C 891214 Prologue converted to Version 4.0 format. (BAB)
  71. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  72. C 900328 Added TYPE section. (WRB)
  73. C 910408 Updated the AUTHOR and REFERENCES sections. (WRB)
  74. C 920501 Reformatted the REFERENCES section. (WRB)
  75. C***END PROLOGUE ORTHOR
  76. DIMENSION A(NRDA,*),DIAG(*),KPIVOT(*),ROWS(*),RS(*),SCALES(*)
  77. C
  78. C END OF ABSTRACT
  79. C
  80. C **********************************************************************
  81. C
  82. C MACHINE PRECISION (COMPUTER UNIT ROUNDOFF VALUE) IS DEFINED
  83. C BY THE FUNCTION R1MACH.
  84. C
  85. C **********************************************************************
  86. C
  87. C***FIRST EXECUTABLE STATEMENT ORTHOR
  88. URO = R1MACH(4)
  89. IF (M .GE. N .AND. N .GE. 1 .AND. NRDA .GE. N) GO TO 1
  90. IFLAG=2
  91. CALL XERMSG ('SLATEC', 'ORTHOR', 'INVALID INPUT PARAMETERS.', 2,
  92. + 1)
  93. RETURN
  94. C
  95. 1 ACC=10.*URO
  96. IF (IFLAG .LT. 0) ACC=MAX(ACC,10.**IFLAG)
  97. SRURO=SQRT(URO)
  98. IFLAG=1
  99. IRANK=N
  100. C
  101. C COMPUTE NORM**2 OF JTH ROW AND A MATRIX NORM
  102. C
  103. ANORM=0.
  104. DO 2 J=1,N
  105. KPIVOT(J)=J
  106. ROWS(J)=SDOT(M,A(J,1),NRDA,A(J,1),NRDA)
  107. RS(J)=ROWS(J)
  108. ANORM=ANORM+ROWS(J)
  109. 2 CONTINUE
  110. C
  111. C PERFORM COLUMN SCALING ON A WHEN SPECIFIED
  112. C
  113. CALL CSCALE(A,NRDA,N,M,SCALES,DUM,ROWS,RS,ANORM,SCALES,ISCALE,1)
  114. C
  115. ANORM=SQRT(ANORM)
  116. C
  117. C
  118. C CONSTRUCTION OF LOWER TRIANGULAR MATRIX AND RECORDING OF
  119. C ORTHOGONAL TRANSFORMATIONS
  120. C
  121. C
  122. DO 50 K=1,N
  123. MK=M-K+1
  124. IF (K .EQ. N) GO TO 25
  125. KP=K+1
  126. C
  127. C SEARCHING FOR PIVOTAL ROW
  128. C
  129. DO 10 J=K,N
  130. IF (ROWS(J) .GE. SRURO*RS(J)) GO TO 5
  131. ROWS(J)=SDOT(MK,A(J,K),NRDA,A(J,K),NRDA)
  132. RS(J)=ROWS(J)
  133. 5 IF (J .EQ. K) GO TO 7
  134. IF (SIGMA .GE. 0.99*ROWS(J)) GO TO 10
  135. 7 SIGMA=ROWS(J)
  136. JROW=J
  137. 10 CONTINUE
  138. IF (JROW .EQ. K) GO TO 25
  139. C
  140. C PERFORM ROW INTERCHANGE
  141. C
  142. L=KPIVOT(K)
  143. KPIVOT(K)=KPIVOT(JROW)
  144. KPIVOT(JROW)=L
  145. ROWS(JROW)=ROWS(K)
  146. ROWS(K)=SIGMA
  147. RSS=RS(K)
  148. RS(K)=RS(JROW)
  149. RS(JROW)=RSS
  150. DO 20 L=1,M
  151. ASAVE=A(K,L)
  152. A(K,L)=A(JROW,L)
  153. 20 A(JROW,L)=ASAVE
  154. C
  155. C CHECK RANK OF THE MATRIX
  156. C
  157. 25 SIG=SDOT(MK,A(K,K),NRDA,A(K,K),NRDA)
  158. DIAGK=SQRT(SIG)
  159. IF (DIAGK .GT. ACC*ANORM) GO TO 30
  160. C
  161. C RANK DEFICIENT PROBLEM
  162. IFLAG=3
  163. IRANK=K-1
  164. CALL XERMSG ('SLATEC', 'ORTHOR',
  165. + 'RANK OF MATRIX IS LESS THAN THE NUMBER OF ROWS.', 1, 1)
  166. RETURN
  167. C
  168. C CONSTRUCT AND APPLY TRANSFORMATION TO MATRIX A
  169. C
  170. 30 AKK=A(K,K)
  171. IF (AKK .GT. 0.) DIAGK=-DIAGK
  172. DIAG(K)=DIAGK
  173. A(K,K)=AKK-DIAGK
  174. IF (K .EQ. N) GO TO 50
  175. SAD=DIAGK*AKK-SIG
  176. DO 40 J=KP,N
  177. AS=SDOT(MK,A(K,K),NRDA,A(J,K),NRDA)/SAD
  178. DO 35 L=K,M
  179. 35 A(J,L)=A(J,L)+AS*A(K,L)
  180. 40 ROWS(J)=ROWS(J)-A(J,K)**2
  181. 50 CONTINUE
  182. C
  183. C
  184. RETURN
  185. END