You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

slagts.f 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. *> \brief \b SLAGTS solves the system of equations (T-λI)x = y or (T-λI)Tx = y,where T is a general tridiagonal matrix and λ a scalar, using the LU factorization computed by slagtf.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SLAGTS + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slagts.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slagts.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slagts.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SLAGTS( JOB, N, A, B, C, D, IN, Y, TOL, INFO )
  22. *
  23. * .. Scalar Arguments ..
  24. * INTEGER INFO, JOB, N
  25. * REAL TOL
  26. * ..
  27. * .. Array Arguments ..
  28. * INTEGER IN( * )
  29. * REAL A( * ), B( * ), C( * ), D( * ), Y( * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> SLAGTS may be used to solve one of the systems of equations
  39. *>
  40. *> (T - lambda*I)*x = y or (T - lambda*I)**T*x = y,
  41. *>
  42. *> where T is an n by n tridiagonal matrix, for x, following the
  43. *> factorization of (T - lambda*I) as
  44. *>
  45. *> (T - lambda*I) = P*L*U ,
  46. *>
  47. *> by routine SLAGTF. The choice of equation to be solved is
  48. *> controlled by the argument JOB, and in each case there is an option
  49. *> to perturb zero or very small diagonal elements of U, this option
  50. *> being intended for use in applications such as inverse iteration.
  51. *> \endverbatim
  52. *
  53. * Arguments:
  54. * ==========
  55. *
  56. *> \param[in] JOB
  57. *> \verbatim
  58. *> JOB is INTEGER
  59. *> Specifies the job to be performed by SLAGTS as follows:
  60. *> = 1: The equations (T - lambda*I)x = y are to be solved,
  61. *> but diagonal elements of U are not to be perturbed.
  62. *> = -1: The equations (T - lambda*I)x = y are to be solved
  63. *> and, if overflow would otherwise occur, the diagonal
  64. *> elements of U are to be perturbed. See argument TOL
  65. *> below.
  66. *> = 2: The equations (T - lambda*I)**Tx = y are to be solved,
  67. *> but diagonal elements of U are not to be perturbed.
  68. *> = -2: The equations (T - lambda*I)**Tx = y are to be solved
  69. *> and, if overflow would otherwise occur, the diagonal
  70. *> elements of U are to be perturbed. See argument TOL
  71. *> below.
  72. *> \endverbatim
  73. *>
  74. *> \param[in] N
  75. *> \verbatim
  76. *> N is INTEGER
  77. *> The order of the matrix T.
  78. *> \endverbatim
  79. *>
  80. *> \param[in] A
  81. *> \verbatim
  82. *> A is REAL array, dimension (N)
  83. *> On entry, A must contain the diagonal elements of U as
  84. *> returned from SLAGTF.
  85. *> \endverbatim
  86. *>
  87. *> \param[in] B
  88. *> \verbatim
  89. *> B is REAL array, dimension (N-1)
  90. *> On entry, B must contain the first super-diagonal elements of
  91. *> U as returned from SLAGTF.
  92. *> \endverbatim
  93. *>
  94. *> \param[in] C
  95. *> \verbatim
  96. *> C is REAL array, dimension (N-1)
  97. *> On entry, C must contain the sub-diagonal elements of L as
  98. *> returned from SLAGTF.
  99. *> \endverbatim
  100. *>
  101. *> \param[in] D
  102. *> \verbatim
  103. *> D is REAL array, dimension (N-2)
  104. *> On entry, D must contain the second super-diagonal elements
  105. *> of U as returned from SLAGTF.
  106. *> \endverbatim
  107. *>
  108. *> \param[in] IN
  109. *> \verbatim
  110. *> IN is INTEGER array, dimension (N)
  111. *> On entry, IN must contain details of the matrix P as returned
  112. *> from SLAGTF.
  113. *> \endverbatim
  114. *>
  115. *> \param[in,out] Y
  116. *> \verbatim
  117. *> Y is REAL array, dimension (N)
  118. *> On entry, the right hand side vector y.
  119. *> On exit, Y is overwritten by the solution vector x.
  120. *> \endverbatim
  121. *>
  122. *> \param[in,out] TOL
  123. *> \verbatim
  124. *> TOL is REAL
  125. *> On entry, with JOB < 0, TOL should be the minimum
  126. *> perturbation to be made to very small diagonal elements of U.
  127. *> TOL should normally be chosen as about eps*norm(U), where eps
  128. *> is the relative machine precision, but if TOL is supplied as
  129. *> non-positive, then it is reset to eps*max( abs( u(i,j) ) ).
  130. *> If JOB > 0 then TOL is not referenced.
  131. *>
  132. *> On exit, TOL is changed as described above, only if TOL is
  133. *> non-positive on entry. Otherwise TOL is unchanged.
  134. *> \endverbatim
  135. *>
  136. *> \param[out] INFO
  137. *> \verbatim
  138. *> INFO is INTEGER
  139. *> = 0: successful exit
  140. *> < 0: if INFO = -i, the i-th argument had an illegal value
  141. *> > 0: overflow would occur when computing the INFO(th)
  142. *> element of the solution vector x. This can only occur
  143. *> when JOB is supplied as positive and either means
  144. *> that a diagonal element of U is very small, or that
  145. *> the elements of the right-hand side vector y are very
  146. *> large.
  147. *> \endverbatim
  148. *
  149. * Authors:
  150. * ========
  151. *
  152. *> \author Univ. of Tennessee
  153. *> \author Univ. of California Berkeley
  154. *> \author Univ. of Colorado Denver
  155. *> \author NAG Ltd.
  156. *
  157. *> \ingroup OTHERauxiliary
  158. *
  159. * =====================================================================
  160. SUBROUTINE SLAGTS( JOB, N, A, B, C, D, IN, Y, TOL, INFO )
  161. *
  162. * -- LAPACK auxiliary routine --
  163. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  164. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  165. *
  166. * .. Scalar Arguments ..
  167. INTEGER INFO, JOB, N
  168. REAL TOL
  169. * ..
  170. * .. Array Arguments ..
  171. INTEGER IN( * )
  172. REAL A( * ), B( * ), C( * ), D( * ), Y( * )
  173. * ..
  174. *
  175. * =====================================================================
  176. *
  177. * .. Parameters ..
  178. REAL ONE, ZERO
  179. PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
  180. * ..
  181. * .. Local Scalars ..
  182. INTEGER K
  183. REAL ABSAK, AK, BIGNUM, EPS, PERT, SFMIN, TEMP
  184. * ..
  185. * .. Intrinsic Functions ..
  186. INTRINSIC ABS, MAX, SIGN
  187. * ..
  188. * .. External Functions ..
  189. REAL SLAMCH
  190. EXTERNAL SLAMCH
  191. * ..
  192. * .. External Subroutines ..
  193. EXTERNAL XERBLA
  194. * ..
  195. * .. Executable Statements ..
  196. *
  197. INFO = 0
  198. IF( ( ABS( JOB ).GT.2 ) .OR. ( JOB.EQ.0 ) ) THEN
  199. INFO = -1
  200. ELSE IF( N.LT.0 ) THEN
  201. INFO = -2
  202. END IF
  203. IF( INFO.NE.0 ) THEN
  204. CALL XERBLA( 'SLAGTS', -INFO )
  205. RETURN
  206. END IF
  207. *
  208. IF( N.EQ.0 )
  209. $ RETURN
  210. *
  211. EPS = SLAMCH( 'Epsilon' )
  212. SFMIN = SLAMCH( 'Safe minimum' )
  213. BIGNUM = ONE / SFMIN
  214. *
  215. IF( JOB.LT.0 ) THEN
  216. IF( TOL.LE.ZERO ) THEN
  217. TOL = ABS( A( 1 ) )
  218. IF( N.GT.1 )
  219. $ TOL = MAX( TOL, ABS( A( 2 ) ), ABS( B( 1 ) ) )
  220. DO 10 K = 3, N
  221. TOL = MAX( TOL, ABS( A( K ) ), ABS( B( K-1 ) ),
  222. $ ABS( D( K-2 ) ) )
  223. 10 CONTINUE
  224. TOL = TOL*EPS
  225. IF( TOL.EQ.ZERO )
  226. $ TOL = EPS
  227. END IF
  228. END IF
  229. *
  230. IF( ABS( JOB ).EQ.1 ) THEN
  231. DO 20 K = 2, N
  232. IF( IN( K-1 ).EQ.0 ) THEN
  233. Y( K ) = Y( K ) - C( K-1 )*Y( K-1 )
  234. ELSE
  235. TEMP = Y( K-1 )
  236. Y( K-1 ) = Y( K )
  237. Y( K ) = TEMP - C( K-1 )*Y( K )
  238. END IF
  239. 20 CONTINUE
  240. IF( JOB.EQ.1 ) THEN
  241. DO 30 K = N, 1, -1
  242. IF( K.LE.N-2 ) THEN
  243. TEMP = Y( K ) - B( K )*Y( K+1 ) - D( K )*Y( K+2 )
  244. ELSE IF( K.EQ.N-1 ) THEN
  245. TEMP = Y( K ) - B( K )*Y( K+1 )
  246. ELSE
  247. TEMP = Y( K )
  248. END IF
  249. AK = A( K )
  250. ABSAK = ABS( AK )
  251. IF( ABSAK.LT.ONE ) THEN
  252. IF( ABSAK.LT.SFMIN ) THEN
  253. IF( ABSAK.EQ.ZERO .OR. ABS( TEMP )*SFMIN.GT.ABSAK )
  254. $ THEN
  255. INFO = K
  256. RETURN
  257. ELSE
  258. TEMP = TEMP*BIGNUM
  259. AK = AK*BIGNUM
  260. END IF
  261. ELSE IF( ABS( TEMP ).GT.ABSAK*BIGNUM ) THEN
  262. INFO = K
  263. RETURN
  264. END IF
  265. END IF
  266. Y( K ) = TEMP / AK
  267. 30 CONTINUE
  268. ELSE
  269. DO 50 K = N, 1, -1
  270. IF( K.LE.N-2 ) THEN
  271. TEMP = Y( K ) - B( K )*Y( K+1 ) - D( K )*Y( K+2 )
  272. ELSE IF( K.EQ.N-1 ) THEN
  273. TEMP = Y( K ) - B( K )*Y( K+1 )
  274. ELSE
  275. TEMP = Y( K )
  276. END IF
  277. AK = A( K )
  278. PERT = SIGN( TOL, AK )
  279. 40 CONTINUE
  280. ABSAK = ABS( AK )
  281. IF( ABSAK.LT.ONE ) THEN
  282. IF( ABSAK.LT.SFMIN ) THEN
  283. IF( ABSAK.EQ.ZERO .OR. ABS( TEMP )*SFMIN.GT.ABSAK )
  284. $ THEN
  285. AK = AK + PERT
  286. PERT = 2*PERT
  287. GO TO 40
  288. ELSE
  289. TEMP = TEMP*BIGNUM
  290. AK = AK*BIGNUM
  291. END IF
  292. ELSE IF( ABS( TEMP ).GT.ABSAK*BIGNUM ) THEN
  293. AK = AK + PERT
  294. PERT = 2*PERT
  295. GO TO 40
  296. END IF
  297. END IF
  298. Y( K ) = TEMP / AK
  299. 50 CONTINUE
  300. END IF
  301. ELSE
  302. *
  303. * Come to here if JOB = 2 or -2
  304. *
  305. IF( JOB.EQ.2 ) THEN
  306. DO 60 K = 1, N
  307. IF( K.GE.3 ) THEN
  308. TEMP = Y( K ) - B( K-1 )*Y( K-1 ) - D( K-2 )*Y( K-2 )
  309. ELSE IF( K.EQ.2 ) THEN
  310. TEMP = Y( K ) - B( K-1 )*Y( K-1 )
  311. ELSE
  312. TEMP = Y( K )
  313. END IF
  314. AK = A( K )
  315. ABSAK = ABS( AK )
  316. IF( ABSAK.LT.ONE ) THEN
  317. IF( ABSAK.LT.SFMIN ) THEN
  318. IF( ABSAK.EQ.ZERO .OR. ABS( TEMP )*SFMIN.GT.ABSAK )
  319. $ THEN
  320. INFO = K
  321. RETURN
  322. ELSE
  323. TEMP = TEMP*BIGNUM
  324. AK = AK*BIGNUM
  325. END IF
  326. ELSE IF( ABS( TEMP ).GT.ABSAK*BIGNUM ) THEN
  327. INFO = K
  328. RETURN
  329. END IF
  330. END IF
  331. Y( K ) = TEMP / AK
  332. 60 CONTINUE
  333. ELSE
  334. DO 80 K = 1, N
  335. IF( K.GE.3 ) THEN
  336. TEMP = Y( K ) - B( K-1 )*Y( K-1 ) - D( K-2 )*Y( K-2 )
  337. ELSE IF( K.EQ.2 ) THEN
  338. TEMP = Y( K ) - B( K-1 )*Y( K-1 )
  339. ELSE
  340. TEMP = Y( K )
  341. END IF
  342. AK = A( K )
  343. PERT = SIGN( TOL, AK )
  344. 70 CONTINUE
  345. ABSAK = ABS( AK )
  346. IF( ABSAK.LT.ONE ) THEN
  347. IF( ABSAK.LT.SFMIN ) THEN
  348. IF( ABSAK.EQ.ZERO .OR. ABS( TEMP )*SFMIN.GT.ABSAK )
  349. $ THEN
  350. AK = AK + PERT
  351. PERT = 2*PERT
  352. GO TO 70
  353. ELSE
  354. TEMP = TEMP*BIGNUM
  355. AK = AK*BIGNUM
  356. END IF
  357. ELSE IF( ABS( TEMP ).GT.ABSAK*BIGNUM ) THEN
  358. AK = AK + PERT
  359. PERT = 2*PERT
  360. GO TO 70
  361. END IF
  362. END IF
  363. Y( K ) = TEMP / AK
  364. 80 CONTINUE
  365. END IF
  366. *
  367. DO 90 K = N, 2, -1
  368. IF( IN( K-1 ).EQ.0 ) THEN
  369. Y( K-1 ) = Y( K-1 ) - C( K-1 )*Y( K )
  370. ELSE
  371. TEMP = Y( K-1 )
  372. Y( K-1 ) = Y( K )
  373. Y( K ) = TEMP - C( K-1 )*Y( K )
  374. END IF
  375. 90 CONTINUE
  376. END IF
  377. *
  378. * End of SLAGTS
  379. *
  380. END