dpodi.f 4.3 KB

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