spoir.f 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. *DECK SPOIR
  2. SUBROUTINE SPOIR (A, LDA, N, V, ITASK, IND, WORK)
  3. C***BEGIN PROLOGUE SPOIR
  4. C***PURPOSE Solve a positive definite symmetric system of linear
  5. C equations. Iterative refinement is used to obtain an error
  6. C estimate.
  7. C***LIBRARY SLATEC
  8. C***CATEGORY D2B1B
  9. C***TYPE SINGLE PRECISION (SPOIR-S, CPOIR-C)
  10. C***KEYWORDS HERMITIAN, LINEAR EQUATIONS, POSITIVE DEFINITE, SYMMETRIC
  11. C***AUTHOR Voorhees, E. A., (LANL)
  12. C***DESCRIPTION
  13. C
  14. C Subroutine SPOIR solves a real positive definite symmetric
  15. C NxN system of single precision linear equations using LINPACK
  16. C subroutines SPOFA and SPOSL. One pass of iterative refine-
  17. C ment is used only to obtain an estimate of the accuracy. That
  18. C is, if A is an NxN real positive definite symmetric matrix
  19. C and if X and B are real N-vectors, then SPOIR solves the
  20. C equation
  21. C
  22. C A*X=B.
  23. C
  24. C The matrix A is first factored into upper and lower
  25. C triangular matrices R and R-TRANSPOSE. These
  26. C factors are used to calculate the solution, X.
  27. C Then the residual vector is found and used
  28. C to calculate an estimate of the relative error, IND.
  29. C IND estimates the accuracy of the solution only when the
  30. C input matrix and the right hand side are represented
  31. C exactly in the computer and does not take into account
  32. C any errors in the input data.
  33. C
  34. C If the equation A*X=B is to be solved for more than one vector
  35. C B, the factoring of A does not need to be performed again and
  36. C the option to only solve (ITASK .GT. 1) will be faster for
  37. C the succeeding solutions. In this case, the contents of A,
  38. C LDA, N, and WORK must not have been altered by the user
  39. C following factorization (ITASK=1). IND will not be changed
  40. C by SPOIR in this case.
  41. C
  42. C Argument Description ***
  43. C A REAL(LDA,N)
  44. C the doubly subscripted array with dimension (LDA,N)
  45. C which contains the coefficient matrix. Only the
  46. C upper triangle, including the diagonal, of the
  47. C coefficient matrix need be entered. A is not
  48. C altered by the routine.
  49. C LDA INTEGER
  50. C the leading dimension of the array A. LDA must be great-
  51. C er than or equal to N. (Terminal error message IND=-1)
  52. C N INTEGER
  53. C the order of the matrix A. N must be greater than
  54. C or equal to one. (Terminal error message IND=-2)
  55. C V REAL(N)
  56. C on entry, the singly subscripted array(vector) of di-
  57. C mension N which contains the right hand side B of a
  58. C system of simultaneous linear equations A*X=B.
  59. C on return, V contains the solution vector, X .
  60. C ITASK INTEGER
  61. C If ITASK = 1, the matrix A is factored and then the
  62. C linear equation is solved.
  63. C If ITASK .GT. 1, the equation is solved using the existing
  64. C factored matrix A (stored in WORK).
  65. C If ITASK .LT. 1, then terminal terminal error IND=-3 is
  66. C printed.
  67. C IND INTEGER
  68. C GT. 0 IND is a rough estimate of the number of digits
  69. C of accuracy in the solution, X. IND=75 means
  70. C that the solution vector X is zero.
  71. C LT. 0 See error message corresponding to IND below.
  72. C WORK REAL(N*(N+1))
  73. C a singly subscripted array of dimension at least N*(N+1).
  74. C
  75. C Error Messages Printed ***
  76. C
  77. C IND=-1 terminal N is greater than LDA.
  78. C IND=-2 terminal N is less than one.
  79. C IND=-3 terminal ITASK is less than one.
  80. C IND=-4 Terminal The matrix A is computationally singular
  81. C or is not positive definite.
  82. C A solution has not been computed.
  83. C IND=-10 warning The solution has no apparent significance.
  84. C The solution may be inaccurate or the matrix
  85. C A may be poorly scaled.
  86. C
  87. C Note- The above terminal(*fatal*) error messages are
  88. C designed to be handled by XERMSG in which
  89. C LEVEL=1 (recoverable) and IFLAG=2 . LEVEL=0
  90. C for warning error messages from XERMSG. Unless
  91. C the user provides otherwise, an error message
  92. C will be printed followed by an abort.
  93. C
  94. C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
  95. C Stewart, LINPACK Users' Guide, SIAM, 1979.
  96. C***ROUTINES CALLED DSDOT, R1MACH, SASUM, SCOPY, SPOFA, SPOSL, XERMSG
  97. C***REVISION HISTORY (YYMMDD)
  98. C 800528 DATE WRITTEN
  99. C 890531 Changed all specific intrinsics to generic. (WRB)
  100. C 890831 Modified array declarations. (WRB)
  101. C 890831 REVISION DATE from Version 3.2
  102. C 891214 Prologue converted to Version 4.0 format. (BAB)
  103. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  104. C 900510 Convert XERRWV calls to XERMSG calls. (RWC)
  105. C 920501 Reformatted the REFERENCES section. (WRB)
  106. C***END PROLOGUE SPOIR
  107. C
  108. INTEGER LDA,N,ITASK,IND,INFO,J
  109. REAL A(LDA,*),V(*),WORK(N,*),SASUM,XNORM,DNORM,R1MACH
  110. DOUBLE PRECISION DSDOT
  111. CHARACTER*8 XERN1, XERN2
  112. C***FIRST EXECUTABLE STATEMENT SPOIR
  113. IF (LDA.LT.N) THEN
  114. IND = -1
  115. WRITE (XERN1, '(I8)') LDA
  116. WRITE (XERN2, '(I8)') N
  117. CALL XERMSG ('SLATEC', 'SPOIR', 'LDA = ' // XERN1 //
  118. * ' IS LESS THAN N = ' // XERN2, -1, 1)
  119. RETURN
  120. ENDIF
  121. C
  122. IF (N.LE.0) THEN
  123. IND = -2
  124. WRITE (XERN1, '(I8)') N
  125. CALL XERMSG ('SLATEC', 'SPOIR', 'N = ' // XERN1 //
  126. * ' IS LESS THAN 1', -2, 1)
  127. RETURN
  128. ENDIF
  129. C
  130. IF (ITASK.LT.1) THEN
  131. IND = -3
  132. WRITE (XERN1, '(I8)') ITASK
  133. CALL XERMSG ('SLATEC', 'SPOIR', 'ITASK = ' // XERN1 //
  134. * ' IS LESS THAN 1', -3, 1)
  135. RETURN
  136. ENDIF
  137. C
  138. IF (ITASK.EQ.1) THEN
  139. C
  140. C MOVE MATRIX A TO WORK
  141. C
  142. DO 10 J=1,N
  143. CALL SCOPY(N,A(1,J),1,WORK(1,J),1)
  144. 10 CONTINUE
  145. C
  146. C FACTOR MATRIX A INTO R
  147. CALL SPOFA(WORK,N,N,INFO)
  148. C
  149. C CHECK FOR SINGULAR OR NOT POS.DEF. MATRIX
  150. IF (INFO.NE.0) THEN
  151. IND = -4
  152. CALL XERMSG ('SLATEC', 'SPOIR',
  153. * 'SINGULAR OR NOT POSITIVE DEFINITE - NO SOLUTION', -4, 1)
  154. RETURN
  155. ENDIF
  156. ENDIF
  157. C
  158. C SOLVE AFTER FACTORING
  159. C MOVE VECTOR B TO WORK
  160. C
  161. CALL SCOPY(N,V(1),1,WORK(1,N+1),1)
  162. CALL SPOSL(WORK,N,N,V)
  163. C
  164. C FORM NORM OF X0
  165. C
  166. XNORM = SASUM(N,V(1),1)
  167. IF (XNORM.EQ.0.0) THEN
  168. IND = 75
  169. RETURN
  170. ENDIF
  171. C
  172. C COMPUTE RESIDUAL
  173. C
  174. DO 40 J=1,N
  175. WORK(J,N+1) = -WORK(J,N+1)
  176. 1 +DSDOT(J-1,A(1,J),1,V(1),1)
  177. 2 +DSDOT(N-J+1,A(J,J),LDA,V(J),1)
  178. 40 CONTINUE
  179. C
  180. C SOLVE A*DELTA=R
  181. C
  182. CALL SPOSL(WORK,N,N,WORK(1,N+1))
  183. C
  184. C FORM NORM OF DELTA
  185. C
  186. DNORM = SASUM(N,WORK(1,N+1),1)
  187. C
  188. C COMPUTE IND (ESTIMATE OF NO. OF SIGNIFICANT DIGITS)
  189. C AND CHECK FOR IND GREATER THAN ZERO
  190. C
  191. IND = -LOG10(MAX(R1MACH(4),DNORM/XNORM))
  192. IF (IND.LE.0) THEN
  193. IND = -10
  194. CALL XERMSG ('SLATEC', 'SPOIR',
  195. * 'SOLUTION MAY HAVE NO SIGNIFICANCE', -10, 0)
  196. ENDIF
  197. RETURN
  198. END