cgefs.f 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. *DECK CGEFS
  2. SUBROUTINE CGEFS (A, LDA, N, V, ITASK, IND, WORK, IWORK)
  3. C***BEGIN PROLOGUE CGEFS
  4. C***PURPOSE Solve a general system of linear equations.
  5. C***LIBRARY SLATEC
  6. C***CATEGORY D2C1
  7. C***TYPE COMPLEX (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 CGEFS solves A general NxN system of complex
  14. C linear equations using LINPACK subroutines CGECO
  15. C and CGESL. That is, if A is an NxN complex matrix
  16. C and if X and B are complex N-vectors, then CGEFS
  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 CGEFS
  34. C in this case.
  35. C
  36. C Argument Description ***
  37. C
  38. C A COMPLEX(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 COMPLEX(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 COMPLEX(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 CGECO, CGESL, R1MACH, XERMSG
  94. C***REVISION HISTORY (YYMMDD)
  95. C 800328 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, cvt GOTO's to
  102. C IF-THEN-ELSE. (RWC)
  103. C 920501 Reformatted the REFERENCES section. (WRB)
  104. C***END PROLOGUE CGEFS
  105. C
  106. INTEGER LDA,N,ITASK,IND,IWORK(*)
  107. COMPLEX A(LDA,*),V(*),WORK(*)
  108. REAL R1MACH
  109. REAL RCOND
  110. CHARACTER*8 XERN1, XERN2
  111. C***FIRST EXECUTABLE STATEMENT CGEFS
  112. IF (LDA.LT.N) THEN
  113. IND = -1
  114. WRITE (XERN1, '(I8)') LDA
  115. WRITE (XERN2, '(I8)') N
  116. CALL XERMSG ('SLATEC', 'CGEFS', 'LDA = ' // XERN1 //
  117. * ' IS LESS THAN N = ' // XERN2, -1, 1)
  118. RETURN
  119. ENDIF
  120. C
  121. IF (N.LE.0) THEN
  122. IND = -2
  123. WRITE (XERN1, '(I8)') N
  124. CALL XERMSG ('SLATEC', 'CGEFS', 'N = ' // XERN1 //
  125. * ' IS LESS THAN 1', -2, 1)
  126. RETURN
  127. ENDIF
  128. C
  129. IF (ITASK.LT.1) THEN
  130. IND = -3
  131. WRITE (XERN1, '(I8)') ITASK
  132. CALL XERMSG ('SLATEC', 'CGEFS', 'ITASK = ' // XERN1 //
  133. * ' IS LESS THAN 1', -3, 1)
  134. RETURN
  135. ENDIF
  136. C
  137. C FACTOR MATRIX A INTO LU
  138. C
  139. IF (ITASK.EQ.1) THEN
  140. CALL CGECO(A,LDA,N,IWORK,RCOND,WORK)
  141. C
  142. C CHECK FOR COMPUTATIONALLY SINGULAR MATRIX
  143. C
  144. IF (RCOND.EQ.0.0) THEN
  145. IND = -4
  146. CALL XERMSG ('SLATEC', 'CGEFS',
  147. * 'SINGULAR MATRIX A - NO SOLUTION', -4, 1)
  148. RETURN
  149. ENDIF
  150. C
  151. C COMPUTE IND (ESTIMATE OF NO. OF SIGNIFICANT DIGITS)
  152. C
  153. IND = -LOG10(R1MACH(4)/RCOND)
  154. C
  155. C CHECK FOR IND GREATER THAN ZERO
  156. C
  157. IF (IND.LE.0) THEN
  158. IND = -10
  159. CALL XERMSG ('SLATEC', 'CGEFS',
  160. * 'SOLUTION MAY HAVE NO SIGNIFICANCE', -10, 0)
  161. ENDIF
  162. ENDIF
  163. C
  164. C SOLVE AFTER FACTORING
  165. C
  166. CALL CGESL(A,LDA,N,IWORK,V,0)
  167. RETURN
  168. END