dgefs.f 6.3 KB

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