sgefs.f 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. *DECK SGEFS
  2. SUBROUTINE SGEFS (A, LDA, N, V, ITASK, IND, WORK, IWORK)
  3. C***BEGIN PROLOGUE SGEFS
  4. C***PURPOSE Solve a general system of linear equations.
  5. C***LIBRARY SLATEC
  6. C***CATEGORY D2A1
  7. C***TYPE SINGLE PRECISION (SGEFS-S, DGEFS-D, CGEFS-C)
  8. C***KEYWORDS COMPLEX LINEAR EQUATIONS, GENERAL MATRIX,
  9. C GENERAL SYSTEM OF LINEAR EQUATIONS
  10. C***AUTHOR Voorhees, E. A., (LANL)
  11. C***DESCRIPTION
  12. C
  13. C Subroutine SGEFS solves a general NxN system of single
  14. C precision linear equations using LINPACK subroutines SGECO
  15. C and SGESL. That is, if A is an NxN real matrix and if X
  16. C and B are real N-vectors, then SGEFS solves the equation
  17. C
  18. C A*X=B.
  19. C
  20. C The matrix A is first factored into upper and lower tri-
  21. C angular matrices U and L using partial pivoting. These
  22. C factors and the pivoting information are used to find the
  23. C 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 only solve (ITASK .GT. 1) will be faster for
  30. C the succeeding solutions. In this case, the contents of A,
  31. C LDA, N and IWORK must not have been altered by the user follow-
  32. C ing factorization (ITASK=1). IND will not be changed by SGEFS
  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.
  40. C on return, an upper triangular matrix U and the
  41. C multipliers necessary to construct a matrix L
  42. C so that A=L*U.
  43. C LDA INTEGER
  44. C the leading dimension of the array A. LDA must be great-
  45. C er than or equal to N. (terminal error message IND=-1)
  46. C N INTEGER
  47. C the order of the matrix A. The first N elements of
  48. C the array A are the elements of the first column of
  49. C the matrix A. N must be greater than or equal to 1.
  50. C (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 and IWORK.
  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 IWORK INTEGER(N)
  70. C a singly subscripted array of dimension at least N.
  71. C
  72. C Error Messages Printed ***
  73. C
  74. C IND=-1 terminal N is greater than LDA.
  75. C IND=-2 terminal N is less than 1.
  76. C IND=-3 terminal ITASK is less than 1.
  77. C IND=-4 terminal The matrix A is computationally singular.
  78. C A solution has not been computed.
  79. C IND=-10 warning The solution has no apparent significance.
  80. C The solution may be inaccurate or the matrix
  81. C A may be poorly scaled.
  82. C
  83. C Note- The above terminal(*fatal*) error messages are
  84. C designed to be handled by XERMSG in which
  85. C LEVEL=1 (recoverable) and IFLAG=2 . LEVEL=0
  86. C for warning error messages from XERMSG. Unless
  87. C the user provides otherwise, an error message
  88. C will be printed followed by an abort.
  89. C
  90. C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
  91. C Stewart, LINPACK Users' Guide, SIAM, 1979.
  92. C***ROUTINES CALLED R1MACH, SGECO, SGESL, XERMSG
  93. C***REVISION HISTORY (YYMMDD)
  94. C 800317 DATE WRITTEN
  95. C 890531 Changed all specific intrinsics to generic. (WRB)
  96. C 890831 Modified array declarations. (WRB)
  97. C 890831 REVISION DATE from Version 3.2
  98. C 891214 Prologue converted to Version 4.0 format. (BAB)
  99. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  100. C 900510 Convert XERRWV calls to XERMSG calls. (RWC)
  101. C 920501 Reformatted the REFERENCES section. (WRB)
  102. C***END PROLOGUE SGEFS
  103. C
  104. INTEGER LDA,N,ITASK,IND,IWORK(*)
  105. REAL A(LDA,*),V(*),WORK(*),R1MACH
  106. REAL RCOND
  107. CHARACTER*8 XERN1, XERN2
  108. C***FIRST EXECUTABLE STATEMENT SGEFS
  109. IF (LDA.LT.N) THEN
  110. IND = -1
  111. WRITE (XERN1, '(I8)') LDA
  112. WRITE (XERN2, '(I8)') N
  113. CALL XERMSG ('SLATEC', 'SGEFS', 'LDA = ' // XERN1 //
  114. * ' IS LESS THAN N = ' // XERN2, -1, 1)
  115. RETURN
  116. ENDIF
  117. C
  118. IF (N.LE.0) THEN
  119. IND = -2
  120. WRITE (XERN1, '(I8)') N
  121. CALL XERMSG ('SLATEC', 'SGEFS', 'N = ' // XERN1 //
  122. * ' IS LESS THAN 1', -2, 1)
  123. RETURN
  124. ENDIF
  125. C
  126. IF (ITASK.LT.1) THEN
  127. IND = -3
  128. WRITE (XERN1, '(I8)') ITASK
  129. CALL XERMSG ('SLATEC', 'SGEFS', 'ITASK = ' // XERN1 //
  130. * ' IS LESS THAN 1', -3, 1)
  131. RETURN
  132. ENDIF
  133. C
  134. IF (ITASK.EQ.1) THEN
  135. C
  136. C FACTOR MATRIX A INTO LU
  137. C
  138. CALL SGECO(A,LDA,N,IWORK,RCOND,WORK)
  139. C
  140. C CHECK FOR COMPUTATIONALLY SINGULAR MATRIX
  141. C
  142. IF (RCOND.EQ.0.0) THEN
  143. IND = -4
  144. CALL XERMSG ('SLATEC', 'SGEFS',
  145. * 'SINGULAR MATRIX A - NO SOLUTION', -4, 1)
  146. RETURN
  147. ENDIF
  148. C
  149. C COMPUTE IND (ESTIMATE OF NO. OF SIGNIFICANT DIGITS)
  150. C AND CHECK FOR IND GREATER THAN ZERO
  151. C
  152. IND = -LOG10(R1MACH(4)/RCOND)
  153. IF (IND.LE.0) THEN
  154. IND=-10
  155. CALL XERMSG ('SLATEC', 'SGEFS',
  156. * 'SOLUTION MAY HAVE NO SIGNIFICANCE', -10, 0)
  157. ENDIF
  158. ENDIF
  159. C
  160. C SOLVE AFTER FACTORING
  161. C
  162. CALL SGESL(A,LDA,N,IWORK,V,0)
  163. RETURN
  164. END