snbfs.f 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. *DECK SNBFS
  2. SUBROUTINE SNBFS (ABE, LDA, N, ML, MU, V, ITASK, IND, WORK, IWORK)
  3. C***BEGIN PROLOGUE SNBFS
  4. C***PURPOSE Solve a general nonsymmetric banded system of linear
  5. C equations.
  6. C***LIBRARY SLATEC
  7. C***CATEGORY D2A2
  8. C***TYPE SINGLE PRECISION (SNBFS-S, DNBFS-D, CNBFS-C)
  9. C***KEYWORDS BANDED, LINEAR EQUATIONS, NONSYMMETRIC
  10. C***AUTHOR Voorhees, E. A., (LANL)
  11. C***DESCRIPTION
  12. C
  13. C Subroutine SNBFS solves a general nonsymmetric banded NxN
  14. C system of single precision real linear equations using
  15. C SLATEC subroutines SNBCO and SNBSL. These are adaptations
  16. C of the LINPACK subroutines SBGCO and SGBSL, which require
  17. C a different format for storing the matrix elements. If
  18. C A is an NxN real matrix and if X and B are real
  19. C N-vectors, then SNBFS solves the equation
  20. C
  21. C A*X=B.
  22. C
  23. C A band matrix is a matrix whose nonzero elements are all
  24. C fairly near the main diagonal, specifically A(I,J) = 0
  25. C if I-J is greater than ML or J-I is greater than
  26. C MU . The integers ML and MU are called the lower and upper
  27. C band widths and M = ML+MU+1 is the total band width.
  28. C SNBFS uses less time and storage than the corresponding
  29. C program for general matrices (SGEFS) if 2*ML+MU .LT. N .
  30. C
  31. C The matrix A is first factored into upper and lower tri-
  32. C angular matrices U and L using partial pivoting. These
  33. C factors and the pivoting information are used to find the
  34. C solution vector X. An approximate condition number is
  35. C calculated to provide a rough estimate of the number of
  36. C digits of accuracy in the computed solution.
  37. C
  38. C If the equation A*X=B is to be solved for more than one vector
  39. C B, the factoring of A does not need to be performed again and
  40. C the option to only solve (ITASK .GT. 1) will be faster for
  41. C the succeeding solutions. In this case, the contents of A,
  42. C LDA, N and IWORK must not have been altered by the user follow-
  43. C ing factorization (ITASK=1). IND will not be changed by SNBFS
  44. C in this case.
  45. C
  46. C
  47. C Band Storage
  48. C
  49. C If A is a band matrix, the following program segment
  50. C will set up the input.
  51. C
  52. C ML = (band width below the diagonal)
  53. C MU = (band width above the diagonal)
  54. C DO 20 I = 1, N
  55. C J1 = MAX(1, I-ML)
  56. C J2 = MIN(N, I+MU)
  57. C DO 10 J = J1, J2
  58. C K = J - I + ML + 1
  59. C ABE(I,K) = A(I,J)
  60. C 10 CONTINUE
  61. C 20 CONTINUE
  62. C
  63. C This uses columns 1 through ML+MU+1 of ABE .
  64. C Furthermore, ML additional columns are needed in
  65. C ABE starting with column ML+MU+2 for elements
  66. C generated during the triangularization. The total
  67. C number of columns needed in ABE is 2*ML+MU+1 .
  68. C
  69. C Example: If the original matrix is
  70. C
  71. C 11 12 13 0 0 0
  72. C 21 22 23 24 0 0
  73. C 0 32 33 34 35 0
  74. C 0 0 43 44 45 46
  75. C 0 0 0 54 55 56
  76. C 0 0 0 0 65 66
  77. C
  78. C then N = 6, ML = 1, MU = 2, LDA .GE. 5 and ABE should contain
  79. C
  80. C * 11 12 13 + , * = not used
  81. C 21 22 23 24 + , + = used for pivoting
  82. C 32 33 34 35 +
  83. C 43 44 45 46 +
  84. C 54 55 56 * +
  85. C 65 66 * * +
  86. C
  87. C
  88. C Argument Description ***
  89. C
  90. C ABE REAL(LDA,NC)
  91. C on entry, contains the matrix in band storage as
  92. C described above. NC must not be less than
  93. C 2*ML+MU+1 . The user is cautioned to specify NC
  94. C with care since it is not an argument and cannot
  95. C be checked by SNBFS. The rows of the original
  96. C matrix are stored in the rows of ABE and the
  97. C diagonals of the original matrix are stored in
  98. C columns 1 through ML+MU+1 of ABE .
  99. C on return, contains an upper triangular matrix U and
  100. C the multipliers necessary to construct a matrix L
  101. C so that A=L*U.
  102. C LDA INTEGER
  103. C the leading dimension of array ABE. LDA must be great-
  104. C er than or equal to N. (terminal error message IND=-1)
  105. C N INTEGER
  106. C the order of the matrix A. N must be greater
  107. C than or equal to 1 . (terminal error message IND=-2)
  108. C ML INTEGER
  109. C the number of diagonals below the main diagonal.
  110. C ML must not be less than zero nor greater than or
  111. C equal to N . (terminal error message IND=-5)
  112. C MU INTEGER
  113. C the number of diagonals above the main diagonal.
  114. C MU must not be less than zero nor greater than or
  115. C equal to N . (terminal error message IND=-6)
  116. C V REAL(N)
  117. C on entry, the singly subscripted array(vector) of di-
  118. C mension N which contains the right hand side B of a
  119. C system of simultaneous linear equations A*X=B.
  120. C on return, V contains the solution vector, X .
  121. C ITASK INTEGER
  122. C If ITASK=1, the matrix A is factored and then the
  123. C linear equation is solved.
  124. C If ITASK .GT. 1, the equation is solved using the existing
  125. C factored matrix A and IWORK.
  126. C If ITASK .LT. 1, then terminal error message IND=-3 is
  127. C printed.
  128. C IND INTEGER
  129. C GT. 0 IND is a rough estimate of the number of digits
  130. C of accuracy in the solution, X.
  131. C LT. 0 See error message corresponding to IND below.
  132. C WORK REAL(N)
  133. C a singly subscripted array of dimension at least N.
  134. C IWORK INTEGER(N)
  135. C a singly subscripted array of dimension at least N.
  136. C
  137. C Error Messages Printed ***
  138. C
  139. C IND=-1 terminal N is greater than LDA.
  140. C IND=-2 terminal N is less than 1.
  141. C IND=-3 terminal ITASK is less than 1.
  142. C IND=-4 terminal the matrix A is computationally singular.
  143. C A solution has not been computed.
  144. C IND=-5 terminal ML is less than zero or is greater than
  145. C or equal to N .
  146. C IND=-6 terminal MU is less than zero or is greater than
  147. C or equal to N .
  148. C IND=-10 warning the solution has no apparent significance.
  149. C The solution may be inaccurate or the matrix
  150. C A may be poorly scaled.
  151. C
  152. C Note- The above terminal(*fatal*) error messages are
  153. C designed to be handled by XERMSG in which
  154. C LEVEL=1 (recoverable) and IFLAG=2 . LEVEL=0
  155. C for warning error messages from XERMSG. Unless
  156. C the user provides otherwise, an error message
  157. C will be printed followed by an abort.
  158. C
  159. C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
  160. C Stewart, LINPACK Users' Guide, SIAM, 1979.
  161. C***ROUTINES CALLED R1MACH, SNBCO, SNBSL, XERMSG
  162. C***REVISION HISTORY (YYMMDD)
  163. C 800808 DATE WRITTEN
  164. C 890531 Changed all specific intrinsics to generic. (WRB)
  165. C 890831 Modified array declarations. (WRB)
  166. C 890831 REVISION DATE from Version 3.2
  167. C 891214 Prologue converted to Version 4.0 format. (BAB)
  168. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  169. C 900510 Convert XERRWV calls to XERMSG calls. (RWC)
  170. C 920501 Reformatted the REFERENCES section. (WRB)
  171. C***END PROLOGUE SNBFS
  172. C
  173. INTEGER LDA,N,ITASK,IND,IWORK(*),ML,MU
  174. REAL ABE(LDA,*),V(*),WORK(*),R1MACH
  175. REAL RCOND
  176. CHARACTER*8 XERN1, XERN2
  177. C***FIRST EXECUTABLE STATEMENT SNBFS
  178. IF (LDA.LT.N) THEN
  179. IND = -1
  180. WRITE (XERN1, '(I8)') LDA
  181. WRITE (XERN2, '(I8)') N
  182. CALL XERMSG ('SLATEC', 'SNBFS', 'LDA = ' // XERN1 //
  183. * ' IS LESS THAN N = ' // XERN2, -1, 1)
  184. RETURN
  185. ENDIF
  186. C
  187. IF (N.LE.0) THEN
  188. IND = -2
  189. WRITE (XERN1, '(I8)') N
  190. CALL XERMSG ('SLATEC', 'SNBFS', 'N = ' // XERN1 //
  191. * ' IS LESS THAN 1', -2, 1)
  192. RETURN
  193. ENDIF
  194. C
  195. IF (ITASK.LT.1) THEN
  196. IND = -3
  197. WRITE (XERN1, '(I8)') ITASK
  198. CALL XERMSG ('SLATEC', 'SNBFS', 'ITASK = ' // XERN1 //
  199. * ' IS LESS THAN 1', -3, 1)
  200. RETURN
  201. ENDIF
  202. C
  203. IF (ML.LT.0 .OR. ML.GE.N) THEN
  204. IND = -5
  205. WRITE (XERN1, '(I8)') ML
  206. CALL XERMSG ('SLATEC', 'SNBFS',
  207. * 'ML = ' // XERN1 // ' IS OUT OF RANGE', -5, 1)
  208. RETURN
  209. ENDIF
  210. C
  211. IF (MU.LT.0 .OR. MU.GE.N) THEN
  212. IND = -6
  213. WRITE (XERN1, '(I8)') MU
  214. CALL XERMSG ('SLATEC', 'SNBFS',
  215. * 'MU = ' // XERN1 // ' IS OUT OF RANGE', -6, 1)
  216. RETURN
  217. ENDIF
  218. C
  219. IF (ITASK.EQ.1) THEN
  220. C
  221. C FACTOR MATRIX A INTO LU
  222. C
  223. CALL SNBCO(ABE,LDA,N,ML,MU,IWORK,RCOND,WORK)
  224. C
  225. C CHECK FOR COMPUTATIONALLY SINGULAR MATRIX
  226. C
  227. IF (RCOND.EQ.0.0) THEN
  228. IND = -4
  229. CALL XERMSG ('SLATEC', 'SNBFS',
  230. * 'SINGULAR MATRIX A - NO SOLUTION', -4, 1)
  231. RETURN
  232. ENDIF
  233. C
  234. C COMPUTE IND (ESTIMATE OF NO. OF SIGNIFICANT DIGITS)
  235. C AND CHECK FOR IND GREATER THAN ZERO
  236. C
  237. IND = -LOG10(R1MACH(4)/RCOND)
  238. IF (IND.LE.0) THEN
  239. IND = -10
  240. CALL XERMSG ('SLATEC', 'SNBFS',
  241. * 'SOLUTION MAY HAVE NO SIGNIFICANCE', -10, 0)
  242. ENDIF
  243. ENDIF
  244. C
  245. C SOLVE AFTER FACTORING
  246. C
  247. CALL SNBSL(ABE,LDA,N,ML,MU,IWORK,V,0)
  248. RETURN
  249. END