dgesl.f 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. *DECK DGESL
  2. SUBROUTINE DGESL (A, LDA, N, IPVT, B, JOB)
  3. C***BEGIN PROLOGUE DGESL
  4. C***PURPOSE Solve the real system A*X=B or TRANS(A)*X=B using the
  5. C factors computed by DGECO or DGEFA.
  6. C***LIBRARY SLATEC (LINPACK)
  7. C***CATEGORY D2A1
  8. C***TYPE DOUBLE PRECISION (SGESL-S, DGESL-D, CGESL-C)
  9. C***KEYWORDS LINEAR ALGEBRA, LINPACK, MATRIX, SOLVE
  10. C***AUTHOR Moler, C. B., (U. of New Mexico)
  11. C***DESCRIPTION
  12. C
  13. C DGESL solves the double precision system
  14. C A * X = B or TRANS(A) * X = B
  15. C using the factors computed by DGECO or DGEFA.
  16. C
  17. C On Entry
  18. C
  19. C A DOUBLE PRECISION(LDA, N)
  20. C the output from DGECO or DGEFA.
  21. C
  22. C LDA INTEGER
  23. C the leading dimension of the array A .
  24. C
  25. C N INTEGER
  26. C the order of the matrix A .
  27. C
  28. C IPVT INTEGER(N)
  29. C the pivot vector from DGECO or DGEFA.
  30. C
  31. C B DOUBLE PRECISION(N)
  32. C the right hand side vector.
  33. C
  34. C JOB INTEGER
  35. C = 0 to solve A*X = B ,
  36. C = nonzero to solve TRANS(A)*X = B where
  37. C TRANS(A) is the transpose.
  38. C
  39. C On Return
  40. C
  41. C B the solution vector X .
  42. C
  43. C Error Condition
  44. C
  45. C A division by zero will occur if the input factor contains a
  46. C zero on the diagonal. Technically this indicates singularity
  47. C but it is often caused by improper arguments or improper
  48. C setting of LDA . It will not occur if the subroutines are
  49. C called correctly and if DGECO has set RCOND .GT. 0.0
  50. C or DGEFA has set INFO .EQ. 0 .
  51. C
  52. C To compute INVERSE(A) * C where C is a matrix
  53. C with P columns
  54. C CALL DGECO(A,LDA,N,IPVT,RCOND,Z)
  55. C IF (RCOND is too small) GO TO ...
  56. C DO 10 J = 1, P
  57. C CALL DGESL(A,LDA,N,IPVT,C(1,J),0)
  58. C 10 CONTINUE
  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, DDOT
  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 DGESL
  72. INTEGER LDA,N,IPVT(*),JOB
  73. DOUBLE PRECISION A(LDA,*),B(*)
  74. C
  75. DOUBLE PRECISION DDOT,T
  76. INTEGER K,KB,L,NM1
  77. C***FIRST EXECUTABLE STATEMENT DGESL
  78. NM1 = N - 1
  79. IF (JOB .NE. 0) GO TO 50
  80. C
  81. C JOB = 0 , SOLVE A * X = B
  82. C FIRST SOLVE L*Y = B
  83. C
  84. IF (NM1 .LT. 1) GO TO 30
  85. DO 20 K = 1, NM1
  86. L = IPVT(K)
  87. T = B(L)
  88. IF (L .EQ. K) GO TO 10
  89. B(L) = B(K)
  90. B(K) = T
  91. 10 CONTINUE
  92. CALL DAXPY(N-K,T,A(K+1,K),1,B(K+1),1)
  93. 20 CONTINUE
  94. 30 CONTINUE
  95. C
  96. C NOW SOLVE U*X = Y
  97. C
  98. DO 40 KB = 1, N
  99. K = N + 1 - KB
  100. B(K) = B(K)/A(K,K)
  101. T = -B(K)
  102. CALL DAXPY(K-1,T,A(1,K),1,B(1),1)
  103. 40 CONTINUE
  104. GO TO 100
  105. 50 CONTINUE
  106. C
  107. C JOB = NONZERO, SOLVE TRANS(A) * X = B
  108. C FIRST SOLVE TRANS(U)*Y = B
  109. C
  110. DO 60 K = 1, N
  111. T = DDOT(K-1,A(1,K),1,B(1),1)
  112. B(K) = (B(K) - T)/A(K,K)
  113. 60 CONTINUE
  114. C
  115. C NOW SOLVE TRANS(L)*X = Y
  116. C
  117. IF (NM1 .LT. 1) GO TO 90
  118. DO 80 KB = 1, NM1
  119. K = N - KB
  120. B(K) = B(K) + DDOT(N-K,A(K+1,K),1,B(K+1),1)
  121. L = IPVT(K)
  122. IF (L .EQ. K) GO TO 70
  123. T = B(L)
  124. B(L) = B(K)
  125. B(K) = T
  126. 70 CONTINUE
  127. 80 CONTINUE
  128. 90 CONTINUE
  129. 100 CONTINUE
  130. RETURN
  131. END