dgedi.f 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. *DECK DGEDI
  2. SUBROUTINE DGEDI (A, LDA, N, IPVT, DET, WORK, JOB)
  3. C***BEGIN PROLOGUE DGEDI
  4. C***PURPOSE Compute the determinant and inverse of a matrix using the
  5. C factors computed by DGECO or DGEFA.
  6. C***LIBRARY SLATEC (LINPACK)
  7. C***CATEGORY D3A1, D2A1
  8. C***TYPE DOUBLE PRECISION (SGEDI-S, DGEDI-D, CGEDI-C)
  9. C***KEYWORDS DETERMINANT, INVERSE, LINEAR ALGEBRA, LINPACK, MATRIX
  10. C***AUTHOR Moler, C. B., (U. of New Mexico)
  11. C***DESCRIPTION
  12. C
  13. C DGEDI computes the determinant and inverse of a matrix
  14. C using the factors computed by DGECO or DGEFA.
  15. C
  16. C On Entry
  17. C
  18. C A DOUBLE PRECISION(LDA, N)
  19. C the output from DGECO or DGEFA.
  20. C
  21. C LDA INTEGER
  22. C the leading dimension of the array A .
  23. C
  24. C N INTEGER
  25. C the order of the matrix A .
  26. C
  27. C IPVT INTEGER(N)
  28. C the pivot vector from DGECO or DGEFA.
  29. C
  30. C WORK DOUBLE PRECISION(N)
  31. C work vector. Contents destroyed.
  32. C
  33. C JOB INTEGER
  34. C = 11 both determinant and inverse.
  35. C = 01 inverse only.
  36. C = 10 determinant only.
  37. C
  38. C On Return
  39. C
  40. C A inverse of original matrix if requested.
  41. C Otherwise unchanged.
  42. C
  43. C DET DOUBLE PRECISION(2)
  44. C determinant of original matrix if requested.
  45. C Otherwise not referenced.
  46. C Determinant = DET(1) * 10.0**DET(2)
  47. C with 1.0 .LE. ABS(DET(1)) .LT. 10.0
  48. C or DET(1) .EQ. 0.0 .
  49. C
  50. C Error Condition
  51. C
  52. C A division by zero will occur if the input factor contains
  53. C a zero on the diagonal and the inverse is requested.
  54. C It will not occur if the subroutines are called correctly
  55. C and if DGECO has set RCOND .GT. 0.0 or DGEFA has set
  56. C INFO .EQ. 0 .
  57. C
  58. C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
  59. C Stewart, LINPACK Users' Guide, SIAM, 1979.
  60. C***ROUTINES CALLED DAXPY, DSCAL, DSWAP
  61. C***REVISION HISTORY (YYMMDD)
  62. C 780814 DATE WRITTEN
  63. C 890531 Changed all specific intrinsics to generic. (WRB)
  64. C 890831 Modified array declarations. (WRB)
  65. C 890831 REVISION DATE from Version 3.2
  66. C 891214 Prologue converted to Version 4.0 format. (BAB)
  67. C 900326 Removed duplicate information from DESCRIPTION section.
  68. C (WRB)
  69. C 920501 Reformatted the REFERENCES section. (WRB)
  70. C***END PROLOGUE DGEDI
  71. INTEGER LDA,N,IPVT(*),JOB
  72. DOUBLE PRECISION A(LDA,*),DET(2),WORK(*)
  73. C
  74. DOUBLE PRECISION T
  75. DOUBLE PRECISION TEN
  76. INTEGER I,J,K,KB,KP1,L,NM1
  77. C***FIRST EXECUTABLE STATEMENT DGEDI
  78. C
  79. C COMPUTE DETERMINANT
  80. C
  81. IF (JOB/10 .EQ. 0) GO TO 70
  82. DET(1) = 1.0D0
  83. DET(2) = 0.0D0
  84. TEN = 10.0D0
  85. DO 50 I = 1, N
  86. IF (IPVT(I) .NE. I) DET(1) = -DET(1)
  87. DET(1) = A(I,I)*DET(1)
  88. IF (DET(1) .EQ. 0.0D0) GO TO 60
  89. 10 IF (ABS(DET(1)) .GE. 1.0D0) GO TO 20
  90. DET(1) = TEN*DET(1)
  91. DET(2) = DET(2) - 1.0D0
  92. GO TO 10
  93. 20 CONTINUE
  94. 30 IF (ABS(DET(1)) .LT. TEN) GO TO 40
  95. DET(1) = DET(1)/TEN
  96. DET(2) = DET(2) + 1.0D0
  97. GO TO 30
  98. 40 CONTINUE
  99. 50 CONTINUE
  100. 60 CONTINUE
  101. 70 CONTINUE
  102. C
  103. C COMPUTE INVERSE(U)
  104. C
  105. IF (MOD(JOB,10) .EQ. 0) GO TO 150
  106. DO 100 K = 1, N
  107. A(K,K) = 1.0D0/A(K,K)
  108. T = -A(K,K)
  109. CALL DSCAL(K-1,T,A(1,K),1)
  110. KP1 = K + 1
  111. IF (N .LT. KP1) GO TO 90
  112. DO 80 J = KP1, N
  113. T = A(K,J)
  114. A(K,J) = 0.0D0
  115. CALL DAXPY(K,T,A(1,K),1,A(1,J),1)
  116. 80 CONTINUE
  117. 90 CONTINUE
  118. 100 CONTINUE
  119. C
  120. C FORM INVERSE(U)*INVERSE(L)
  121. C
  122. NM1 = N - 1
  123. IF (NM1 .LT. 1) GO TO 140
  124. DO 130 KB = 1, NM1
  125. K = N - KB
  126. KP1 = K + 1
  127. DO 110 I = KP1, N
  128. WORK(I) = A(I,K)
  129. A(I,K) = 0.0D0
  130. 110 CONTINUE
  131. DO 120 J = KP1, N
  132. T = WORK(J)
  133. CALL DAXPY(N,T,A(1,J),1,A(1,K),1)
  134. 120 CONTINUE
  135. L = IPVT(K)
  136. IF (L .NE. K) CALL DSWAP(N,A(1,K),1,A(1,L),1)
  137. 130 CONTINUE
  138. 140 CONTINUE
  139. 150 CONTINUE
  140. RETURN
  141. END