spofs.f 6.3 KB

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