sgeir.f 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. *DECK SGEIR
  2. SUBROUTINE SGEIR (A, LDA, N, V, ITASK, IND, WORK, IWORK)
  3. C***BEGIN PROLOGUE SGEIR
  4. C***PURPOSE Solve a general system of linear equations. Iterative
  5. C refinement is used to obtain an error estimate.
  6. C***LIBRARY SLATEC
  7. C***CATEGORY D2A1
  8. C***TYPE SINGLE PRECISION (SGEIR-S, CGEIR-C)
  9. C***KEYWORDS COMPLEX LINEAR EQUATIONS, GENERAL MATRIX,
  10. C GENERAL SYSTEM OF LINEAR EQUATIONS
  11. C***AUTHOR Voorhees, E. A., (LANL)
  12. C***DESCRIPTION
  13. C
  14. C Subroutine SGEIR solves a general NxN system of single
  15. C precision linear equations using LINPACK subroutines SGEFA and
  16. C SGESL. One pass of iterative refinement is used only to obtain
  17. C an estimate of the accuracy. That is, if A is an NxN real
  18. C matrix and if X and B are real N-vectors, then SGEIR solves
  19. C the equation
  20. C
  21. C A*X=B.
  22. C
  23. C The matrix A is first factored into upper and lower tri-
  24. C angular matrices U and L using partial pivoting. These
  25. C factors and the pivoting information are used to calculate
  26. C the solution, X. Then the residual vector is found and
  27. C used to calculate an estimate of the relative error, IND.
  28. C IND estimates the accuracy of the solution only when the
  29. C input matrix and the right hand side are represented
  30. C exactly in the computer and does not take into account
  31. C any errors in the input data.
  32. C
  33. C If the equation A*X=B is to be solved for more than one vector
  34. C B, the factoring of A does not need to be performed again and
  35. C the option to solve only (ITASK .GT. 1) will be faster for
  36. C the succeeding solutions. In this case, the contents of A,
  37. C LDA, N, WORK, and IWORK must not have been altered by the
  38. C user following factorization (ITASK=1). IND will not be
  39. C changed by SGEIR in this case.
  40. C
  41. C Argument Description ***
  42. C
  43. C A REAL(LDA,N)
  44. C the doubly subscripted array with dimension (LDA,N)
  45. C which contains the coefficient matrix. A is not
  46. C altered by the routine.
  47. C LDA INTEGER
  48. C the leading dimension of the array A. LDA must be great-
  49. C er than or equal to N. (terminal error message IND=-1)
  50. C N INTEGER
  51. C the order of the matrix A. The first N elements of
  52. C the array A are the elements of the first column of
  53. C matrix A. N must be greater than or equal to 1.
  54. C (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 error message 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 IWORK INTEGER(N)
  75. C a singly subscripted array of dimension at least N.
  76. C
  77. C Error Messages Printed ***
  78. C
  79. C IND=-1 terminal N is greater than LDA.
  80. C IND=-2 terminal N is less than one.
  81. C IND=-3 terminal ITASK is less than one.
  82. C IND=-4 terminal The matrix A is computationally singular.
  83. C A solution has not been computed.
  84. C IND=-10 warning The solution has no apparent significance.
  85. C The solution may be inaccurate or the matrix
  86. C A may be poorly scaled.
  87. C
  88. C Note- The above terminal(*fatal*) error messages are
  89. C designed to be handled by XERMSG in which
  90. C LEVEL=1 (recoverable) and IFLAG=2 . LEVEL=0
  91. C for warning error messages from XERMSG. Unless
  92. C the user provides otherwise, an error message
  93. C will be printed followed by an abort.
  94. C
  95. C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
  96. C Stewart, LINPACK Users' Guide, SIAM, 1979.
  97. C***ROUTINES CALLED R1MACH, SASUM, SCOPY, SDSDOT, SGEFA, SGESL, XERMSG
  98. C***REVISION HISTORY (YYMMDD)
  99. C 800430 DATE WRITTEN
  100. C 890531 Changed all specific intrinsics to generic. (WRB)
  101. C 890831 Modified array declarations. (WRB)
  102. C 890831 REVISION DATE from Version 3.2
  103. C 891214 Prologue converted to Version 4.0 format. (BAB)
  104. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  105. C 900510 Convert XERRWV calls to XERMSG calls. (RWC)
  106. C 920501 Reformatted the REFERENCES section. (WRB)
  107. C***END PROLOGUE SGEIR
  108. C
  109. INTEGER LDA,N,ITASK,IND,IWORK(*),INFO,J
  110. REAL A(LDA,*),V(*),WORK(N,*),XNORM,DNORM,SDSDOT,SASUM,R1MACH
  111. CHARACTER*8 XERN1, XERN2
  112. C***FIRST EXECUTABLE STATEMENT SGEIR
  113. IF (LDA.LT.N) THEN
  114. IND = -1
  115. WRITE (XERN1, '(I8)') LDA
  116. WRITE (XERN2, '(I8)') N
  117. CALL XERMSG ('SLATEC', 'SGEIR', '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', 'SGEIR', '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', 'SGEIR', '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 LU
  147. C
  148. CALL SGEFA(WORK,N,N,IWORK,INFO)
  149. C
  150. C CHECK FOR COMPUTATIONALLY SINGULAR MATRIX
  151. C
  152. IF (INFO.NE.0) THEN
  153. IND = -4
  154. CALL XERMSG ('SLATEC', 'SGEIR',
  155. * 'SINGULAR MATRIX A - NO SOLUTION', -4, 1)
  156. RETURN
  157. ENDIF
  158. ENDIF
  159. C
  160. C SOLVE WHEN FACTORING COMPLETE
  161. C MOVE VECTOR B TO WORK
  162. C
  163. CALL SCOPY(N,V(1),1,WORK(1,N+1),1)
  164. CALL SGESL(WORK,N,N,IWORK,V,0)
  165. C
  166. C FORM NORM OF X0
  167. C
  168. XNORM=SASUM(N,V(1),1)
  169. IF (XNORM.EQ.0.0) THEN
  170. IND = 75
  171. RETURN
  172. ENDIF
  173. C
  174. C COMPUTE RESIDUAL
  175. C
  176. DO 40 J=1,N
  177. WORK(J,N+1) = SDSDOT(N,-WORK(J,N+1),A(J,1),LDA,V,1)
  178. 40 CONTINUE
  179. C
  180. C SOLVE A*DELTA=R
  181. C
  182. CALL SGESL(WORK,N,N,IWORK,WORK(1,N+1),0)
  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', 'SGEIR',
  195. * 'SOLUTION MAY HAVE NO SIGNIFICANCE', -10, 0)
  196. ENDIF
  197. RETURN
  198. END