dtrdi.f 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. *DECK DTRDI
  2. SUBROUTINE DTRDI (T, LDT, N, DET, JOB, INFO)
  3. C***BEGIN PROLOGUE DTRDI
  4. C***PURPOSE Compute the determinant and inverse of a triangular matrix.
  5. C***LIBRARY SLATEC (LINPACK)
  6. C***CATEGORY D2A3, D3A3
  7. C***TYPE DOUBLE PRECISION (STRDI-S, DTRDI-D, CTRDI-C)
  8. C***KEYWORDS DETERMINANT, INVERSE, LINEAR ALGEBRA, LINPACK,
  9. C TRIANGULAR MATRIX
  10. C***AUTHOR Moler, C. B., (U. of New Mexico)
  11. C***DESCRIPTION
  12. C
  13. C DTRDI computes the determinant and inverse of a double precision
  14. C triangular matrix.
  15. C
  16. C On Entry
  17. C
  18. C T DOUBLE PRECISION(LDT,N)
  19. C T contains the triangular matrix. The zero
  20. C elements of the matrix are not referenced, and
  21. C the corresponding elements of the array can be
  22. C used to store other information.
  23. C
  24. C LDT INTEGER
  25. C LDT is the leading dimension of the array T.
  26. C
  27. C N INTEGER
  28. C N is the order of the system.
  29. C
  30. C JOB INTEGER
  31. C = 010 no det, inverse of lower triangular.
  32. C = 011 no det, inverse of upper triangular.
  33. C = 100 det, no inverse.
  34. C = 110 det, inverse of lower triangular.
  35. C = 111 det, inverse of upper triangular.
  36. C
  37. C On Return
  38. C
  39. C T inverse of original matrix if requested.
  40. C Otherwise unchanged.
  41. C
  42. C DET DOUBLE PRECISION(2)
  43. C determinant of original matrix if requested.
  44. C Otherwise not referenced.
  45. C DETERMINANT = DET(1) * 10.0**DET(2)
  46. C with 1.0 .LE. ABS(DET(1)) .LT. 10.0
  47. C or DET(1) .EQ. 0.0 .
  48. C
  49. C INFO INTEGER
  50. C INFO contains zero if the system is nonsingular
  51. C and the inverse is requested.
  52. C Otherwise INFO contains the index of
  53. C a zero diagonal element of T.
  54. C
  55. C
  56. C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
  57. C Stewart, LINPACK Users' Guide, SIAM, 1979.
  58. C***ROUTINES CALLED DAXPY, DSCAL
  59. C***REVISION HISTORY (YYMMDD)
  60. C 780814 DATE WRITTEN
  61. C 890531 Changed all specific intrinsics to generic. (WRB)
  62. C 890831 Modified array declarations. (WRB)
  63. C 890831 REVISION DATE from Version 3.2
  64. C 891214 Prologue converted to Version 4.0 format. (BAB)
  65. C 900326 Removed duplicate information from DESCRIPTION section.
  66. C (WRB)
  67. C 920501 Reformatted the REFERENCES section. (WRB)
  68. C***END PROLOGUE DTRDI
  69. INTEGER LDT,N,JOB,INFO
  70. DOUBLE PRECISION T(LDT,*),DET(2)
  71. C
  72. DOUBLE PRECISION TEMP
  73. DOUBLE PRECISION TEN
  74. INTEGER I,J,K,KB,KM1,KP1
  75. C***FIRST EXECUTABLE STATEMENT DTRDI
  76. C
  77. C COMPUTE DETERMINANT
  78. C
  79. IF (JOB/100 .EQ. 0) GO TO 70
  80. DET(1) = 1.0D0
  81. DET(2) = 0.0D0
  82. TEN = 10.0D0
  83. DO 50 I = 1, N
  84. DET(1) = T(I,I)*DET(1)
  85. IF (DET(1) .EQ. 0.0D0) GO TO 60
  86. 10 IF (ABS(DET(1)) .GE. 1.0D0) GO TO 20
  87. DET(1) = TEN*DET(1)
  88. DET(2) = DET(2) - 1.0D0
  89. GO TO 10
  90. 20 CONTINUE
  91. 30 IF (ABS(DET(1)) .LT. TEN) GO TO 40
  92. DET(1) = DET(1)/TEN
  93. DET(2) = DET(2) + 1.0D0
  94. GO TO 30
  95. 40 CONTINUE
  96. 50 CONTINUE
  97. 60 CONTINUE
  98. 70 CONTINUE
  99. C
  100. C COMPUTE INVERSE OF UPPER TRIANGULAR
  101. C
  102. IF (MOD(JOB/10,10) .EQ. 0) GO TO 170
  103. IF (MOD(JOB,10) .EQ. 0) GO TO 120
  104. DO 100 K = 1, N
  105. INFO = K
  106. IF (T(K,K) .EQ. 0.0D0) GO TO 110
  107. T(K,K) = 1.0D0/T(K,K)
  108. TEMP = -T(K,K)
  109. CALL DSCAL(K-1,TEMP,T(1,K),1)
  110. KP1 = K + 1
  111. IF (N .LT. KP1) GO TO 90
  112. DO 80 J = KP1, N
  113. TEMP = T(K,J)
  114. T(K,J) = 0.0D0
  115. CALL DAXPY(K,TEMP,T(1,K),1,T(1,J),1)
  116. 80 CONTINUE
  117. 90 CONTINUE
  118. 100 CONTINUE
  119. INFO = 0
  120. 110 CONTINUE
  121. GO TO 160
  122. 120 CONTINUE
  123. C
  124. C COMPUTE INVERSE OF LOWER TRIANGULAR
  125. C
  126. DO 150 KB = 1, N
  127. K = N + 1 - KB
  128. INFO = K
  129. IF (T(K,K) .EQ. 0.0D0) GO TO 180
  130. T(K,K) = 1.0D0/T(K,K)
  131. TEMP = -T(K,K)
  132. IF (K .NE. N) CALL DSCAL(N-K,TEMP,T(K+1,K),1)
  133. KM1 = K - 1
  134. IF (KM1 .LT. 1) GO TO 140
  135. DO 130 J = 1, KM1
  136. TEMP = T(K,J)
  137. T(K,J) = 0.0D0
  138. CALL DAXPY(N-K+1,TEMP,T(K,K),1,T(K,J),1)
  139. 130 CONTINUE
  140. 140 CONTINUE
  141. 150 CONTINUE
  142. INFO = 0
  143. 160 CONTINUE
  144. 170 CONTINUE
  145. 180 CONTINUE
  146. RETURN
  147. END