cpoir.f 7.5 KB

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