strdi.f 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. *DECK STRDI
  2. SUBROUTINE STRDI (T, LDT, N, DET, JOB, INFO)
  3. C***BEGIN PROLOGUE STRDI
  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 SINGLE PRECISION (STRDI-S, DTRDI-D, CTRDI-C)
  8. C***KEYWORDS DETERMINANT, INVERSE, LINEAR ALGEBRA, LINPACK, MATRIX,
  9. C TRIANGULAR
  10. C***AUTHOR Moler, C. B., (U. of New Mexico)
  11. C***DESCRIPTION
  12. C
  13. C STRDI computes the determinant and inverse of a real
  14. C triangular matrix.
  15. C
  16. C On Entry
  17. C
  18. C T REAL(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 REAL(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***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
  56. C Stewart, LINPACK Users' Guide, SIAM, 1979.
  57. C***ROUTINES CALLED SAXPY, SSCAL
  58. C***REVISION HISTORY (YYMMDD)
  59. C 780814 DATE WRITTEN
  60. C 890831 Modified array declarations. (WRB)
  61. C 890831 REVISION DATE from Version 3.2
  62. C 891214 Prologue converted to Version 4.0 format. (BAB)
  63. C 900326 Removed duplicate information from DESCRIPTION section.
  64. C (WRB)
  65. C 920501 Reformatted the REFERENCES section. (WRB)
  66. C***END PROLOGUE STRDI
  67. INTEGER LDT,N,JOB,INFO
  68. REAL T(LDT,*),DET(2)
  69. C
  70. REAL TEMP
  71. REAL TEN
  72. INTEGER I,J,K,KB,KM1,KP1
  73. C***FIRST EXECUTABLE STATEMENT STRDI
  74. C
  75. C COMPUTE DETERMINANT
  76. C
  77. IF (JOB/100 .EQ. 0) GO TO 70
  78. DET(1) = 1.0E0
  79. DET(2) = 0.0E0
  80. TEN = 10.0E0
  81. DO 50 I = 1, N
  82. DET(1) = T(I,I)*DET(1)
  83. IF (DET(1) .EQ. 0.0E0) GO TO 60
  84. 10 IF (ABS(DET(1)) .GE. 1.0E0) GO TO 20
  85. DET(1) = TEN*DET(1)
  86. DET(2) = DET(2) - 1.0E0
  87. GO TO 10
  88. 20 CONTINUE
  89. 30 IF (ABS(DET(1)) .LT. TEN) GO TO 40
  90. DET(1) = DET(1)/TEN
  91. DET(2) = DET(2) + 1.0E0
  92. GO TO 30
  93. 40 CONTINUE
  94. 50 CONTINUE
  95. 60 CONTINUE
  96. 70 CONTINUE
  97. C
  98. C COMPUTE INVERSE OF UPPER TRIANGULAR
  99. C
  100. IF (MOD(JOB/10,10) .EQ. 0) GO TO 170
  101. IF (MOD(JOB,10) .EQ. 0) GO TO 120
  102. DO 100 K = 1, N
  103. INFO = K
  104. IF (T(K,K) .EQ. 0.0E0) GO TO 110
  105. T(K,K) = 1.0E0/T(K,K)
  106. TEMP = -T(K,K)
  107. CALL SSCAL(K-1,TEMP,T(1,K),1)
  108. KP1 = K + 1
  109. IF (N .LT. KP1) GO TO 90
  110. DO 80 J = KP1, N
  111. TEMP = T(K,J)
  112. T(K,J) = 0.0E0
  113. CALL SAXPY(K,TEMP,T(1,K),1,T(1,J),1)
  114. 80 CONTINUE
  115. 90 CONTINUE
  116. 100 CONTINUE
  117. INFO = 0
  118. 110 CONTINUE
  119. GO TO 160
  120. 120 CONTINUE
  121. C
  122. C COMPUTE INVERSE OF LOWER TRIANGULAR
  123. C
  124. DO 150 KB = 1, N
  125. K = N + 1 - KB
  126. INFO = K
  127. IF (T(K,K) .EQ. 0.0E0) GO TO 180
  128. T(K,K) = 1.0E0/T(K,K)
  129. TEMP = -T(K,K)
  130. IF (K .NE. N) CALL SSCAL(N-K,TEMP,T(K+1,K),1)
  131. KM1 = K - 1
  132. IF (KM1 .LT. 1) GO TO 140
  133. DO 130 J = 1, KM1
  134. TEMP = T(K,J)
  135. T(K,J) = 0.0E0
  136. CALL SAXPY(N-K+1,TEMP,T(K,K),1,T(K,J),1)
  137. 130 CONTINUE
  138. 140 CONTINUE
  139. 150 CONTINUE
  140. INFO = 0
  141. 160 CONTINUE
  142. 170 CONTINUE
  143. 180 CONTINUE
  144. RETURN
  145. END