MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
dgtsl.f90
Go to the documentation of this file.
1 
7 subroutine dgtsl ( n, c, d, e, b, info )
8 
9 !*****************************************************************************80
10 !
11 !! DGTSL solves a general tridiagonal linear system.
12 !
13 ! Licensing:
14 !
15 ! This code is distributed under the GNU LGPL license.
16 !
17 ! Modified:
18 !
19 ! 17 May 2005
20 !
21 ! Author:
22 !
23 ! FORTRAN90 version by John Burkardt.
24 !
25 ! Reference:
26 !
27 ! Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,
28 ! LINPACK User's Guide,
29 ! SIAM, 1979,
30 ! ISBN13: 978-0-898711-72-1,
31 ! LC: QA214.L56.
32 !
33 ! Parameters:
34 !
35 ! Input, integer ( kind = 4 ) N, the order of the tridiagonal matrix.
36 !
37 ! Input/output, real ( kind = 8 ) C(N), contains the subdiagonal of the
38 ! tridiagonal matrix in entries C(2:N). On output, C is destroyed.
39 !
40 ! Input/output, real ( kind = 8 ) D(N). On input, the diagonal of the
41 ! matrix. On output, D is destroyed.
42 !
43 ! Input/output, real ( kind = 8 ) E(N), contains the superdiagonal of the
44 ! tridiagonal matrix in entries E(1:N-1). On output E is destroyed.
45 !
46 ! Input/output, real ( kind = 8 ) B(N). On input, the right hand side.
47 ! On output, the solution.
48 !
49 ! Output, integer ( kind = 4 ) INFO, error flag.
50 ! 0, normal value.
51 ! K, the K-th element of the diagonal becomes exactly zero. The
52 ! subroutine returns if this error condition is detected.
53 !
54  implicit none
55 
56  integer ( kind = 4 ) n
57 
58  real ( kind = 8 ) b(n)
60  real ( kind = 8 ) c(n)
62  real ( kind = 8 ) d(n)
64  real ( kind = 8 ) e(n)
66  integer ( kind = 4 ) info
67  integer ( kind = 4 ) k
68  real ( kind = 8 ) t
69 
70  info = 0
71  c(1) = d(1)
72 
73  if ( 2 <= n ) then
74 
75  d(1) = e(1)
76  e(1) = 0.0d+00
77  e(n) = 0.0d+00
78 
79  do k = 1, n - 1
80 !
81 ! Find the larger of the two rows.
82 !
83  if ( abs( c(k) ) <= abs( c(k+1) ) ) then
84 !
85 ! Interchange rows.
86 !
87  t = c(k+1)
88  c(k+1) = c(k)
89  c(k) = t
90 
91  t = d(k+1)
92  d(k+1) = d(k)
93  d(k) = t
94 
95  t = e(k+1)
96  e(k+1) = e(k)
97  e(k) = t
98 
99  t = b(k+1)
100  b(k+1) = b(k)
101  b(k) = t
102 
103  end if
104 !
105 ! Zero elements.
106 !
107  if ( c(k) == 0.0d+00 ) then
108  info = k
109  return
110  end if
111 
112  t = -c(k+1) / c(k)
113  c(k+1) = d(k+1) + t * d(k)
114  d(k+1) = e(k+1) + t * e(k)
115  e(k+1) = 0.0d+00
116  b(k+1) = b(k+1) + t * b(k)
117 
118  end do
119 
120  end if
121 
122  if ( c(n) == 0.0d+00 ) then
123  info = n
124  return
125  end if
126 !
127 ! Back solve.
128 !
129  b(n) = b(n) / c(n)
130 
131  if ( 1 < n ) then
132 
133  b(n-1) = ( b(n-1) - d(n-1) * b(n) ) / c(n-1)
134 
135  do k = n-2, 1, -1
136  b(k) = ( b(k) - d(k) * b(k+1) - e(k) * b(k+2) ) / c(k)
137  end do
138 
139  end if
140 
141  return
142 end
subroutine dgtsl(n, c, d, e, b, info)
Definition: dgtsl.f90:8