Debian Codegraph @

packages/seacas/libraries/chaco/tinvit/tinvit.f

raw
1 C Copyright(C) 1999-2020 National Technology & Engineering Solutions
2 C of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 C NTESS, the U.S. Government retains certain rights in this software.
4 C
5 C See packages/seacas/LICENSE for details
6
7 subroutine tinvit(nm,n,d,e,e2,m,w,ind,z,
8 x ierr,rv1,rv2,rv3,rv4,rv6)
9
10 integer i,j,m,n,p,q,r,s,ii,ip,jj,nm,its,tag,ierr,group
11 double precision d(n),e(n),e2(n),w(m),z(nm,m),
12 x rv1(n),rv2(n),rv3(n),rv4(n),rv6(n)
13 double precision u,v,uk,xu,x0,x1,eps2,eps3,eps4,norm,order,epslon,
14 x pythag
15 integer ind(m)
16
17 c this subroutine is a translation of the inverse iteration tech-
18 c nique in the algol procedure tristurm by peters and wilkinson.
19 c handbook for auto. comp., vol.ii-linear algebra, 418-439(1971).
20
21 c this subroutine finds those eigenvectors of a tridiagonal
22 c symmetric matrix corresponding to specified eigenvalues,
23 c using inverse iteration.
24
25 c on input
26
27 c nm must be set to the row dimension of two-dimensional
28 c array parameters as declared in the calling program
29 c dimension statement.
30
31 c n is the order of the matrix.
32
33 c d contains the diagonal elements of the input matrix.
34
35 c e contains the subdiagonal elements of the input matrix
36 c in its last n-1 positions. e(1) is arbitrary.
37
38 c e2 contains the squares of the corresponding elements of e,
39 c with zeros corresponding to negligible elements of e.
40 c e(i) is considered negligible if it is not larger than
41 c the product of the relative machine precision and the sum
42 c of the magnitudes of d(i) and d(i-1). e2(1) must contain
43 c 0.0d0 if the eigenvalues are in ascending order, or 2.0d0
44 c if the eigenvalues are in descending order. if bisect,
45 c tridib, or imtqlv has been used to find the eigenvalues,
46 c their output e2 array is exactly what is expected here.
47
48 c m is the number of specified eigenvalues.
49
50 c w contains the m eigenvalues in ascending or descending order.
51
52 c ind contains in its first m positions the submatrix indices
53 c associated with the corresponding eigenvalues in w --
54 c 1 for eigenvalues belonging to the first submatrix from
55 c the top, 2 for those belonging to the second submatrix, etc.
56
57 c on output
58
59 c all input arrays are unaltered.
60
61 c z contains the associated set of orthonormal eigenvectors.
62 c any vector which fails to converge is set to zero.
63
64 c ierr is set to
65 c zero for normal return,
66 c -r if the eigenvector corresponding to the r-th
67 c eigenvalue fails to converge in 5 iterations.
68
69 c rv1, rv2, rv3, rv4, and rv6 are temporary storage arrays.
70
71 c calls pythag for dsqrt(a*a + b*b) .
72
73 c questions and comments should be directed to burton s. garbow,
74 c mathematics and computer science div, argonne national laboratory
75
76 c this version dated august 1983.
77
78 c ------------------------------------------------------------------
79
80 ierr = 0
81 if (m .eq. 0) go to 1001
82 tag = 0
83 order = 1.0d0 - e2(1)
84 q = 0
85 c .......... establish and process next submatrix ..........
86 100 p = q + 1
87
88 do 120 q = p, n
89 if (q .eq. n) go to 140
90 if (e2(q+1) .eq. 0.0d0) go to 140
91 120 continue
92 c .......... find vectors by inverse iteration ..........
93 140 tag = tag + 1
94 s = 0
95
96 do 920 r = 1, m
97 if (ind(r) .ne. tag) go to 920
98 its = 1
99 x1 = w(r)
100 if (s .ne. 0) go to 510
101 c .......... check for isolated root ..........
102 xu = 1.0d0
103 if (p .ne. q) go to 490
104 rv6(p) = 1.0d0
105 go to 870
106 490 norm = dabs(d(p))
107 ip = p + 1
108
109 do 500 i = ip, q
110 500 norm = dmax1(norm, dabs(d(i))+dabs(e(i)))
111 c .......... eps2 is the criterion for grouping,
112 c eps3 replaces zero pivots and equal
113 c roots are modified by eps3,
114 c eps4 is taken very small to avoid overflow ..........
115 eps2 = 1.0d-3 * norm
116 eps3 = epslon(norm)
117 uk = q - p + 1
118 eps4 = uk * eps3
119 uk = eps4 / dsqrt(uk)
120 s = p
121 505 group = 0
122 go to 520
123 c .......... look for close or coincident roots ..........
124 510 if (dabs(x1-x0) .ge. eps2) go to 505
125 group = group + 1
126 if (order * (x1 - x0) .le. 0.0d0) x1 = x0 + order * eps3
127 c .......... elimination with interchanges and
128 c initialization of vector ..........
129 520 v = 0.0d0
130
131 do 580 i = p, q
132 rv6(i) = uk
133 if (i .eq. p) go to 560
134 if (dabs(e(i)) .lt. dabs(u)) go to 540
135 c .......... warning -- a divide check may occur here if
136 c e2 array has not been specified correctly ..........
137 xu = u / e(i)
138 rv4(i) = xu
139 rv1(i-1) = e(i)
140 rv2(i-1) = d(i) - x1
141 rv3(i-1) = 0.0d0
142 if (i .ne. q) rv3(i-1) = e(i+1)
143 u = v - xu * rv2(i-1)
144 v = -xu * rv3(i-1)
145 go to 580
146 540 xu = e(i) / u
147 rv4(i) = xu
148 rv1(i-1) = u
149 rv2(i-1) = v
150 rv3(i-1) = 0.0d0
151 560 u = d(i) - x1 - xu * v
152 if (i .ne. q) v = e(i+1)
153 580 continue
154
155 if (u .eq. 0.0d0) u = eps3
156 rv1(q) = u
157 rv2(q) = 0.0d0
158 rv3(q) = 0.0d0
159 c .......... back substitution
160 c for i=q step -1 until p do -- ..........
161 600 do 620 ii = p, q
162 i = p + q - ii
163 rv6(i) = (rv6(i) - u * rv2(i) - v * rv3(i)) / rv1(i)
164 v = u
165 u = rv6(i)
166 620 continue
167 c .......... orthogonalize with respect to previous
168 c members of group ..........
169 if (group .eq. 0) go to 700
170 j = r
171
172 do 680 jj = 1, group
173 630 j = j - 1
174 if (ind(j) .ne. tag) go to 630
175 xu = 0.0d0
176
177 do 640 i = p, q
178 640 xu = xu + rv6(i) * z(i,j)
179
180 do 660 i = p, q
181 660 rv6(i) = rv6(i) - xu * z(i,j)
182
183 680 continue
184
185 700 norm = 0.0d0
186
187 do 720 i = p, q
188 720 norm = norm + dabs(rv6(i))
189
190 if (norm .ge. 1.0d0) go to 840
191 c .......... forward substitution ..........
192 if (its .eq. 5) go to 830
193 if (norm .ne. 0.0d0) go to 740
194 rv6(s) = eps4
195 s = s + 1
196 if (s .gt. q) s = p
197 go to 780
198 740 xu = eps4 / norm
199
200 do 760 i = p, q
201 760 rv6(i) = rv6(i) * xu
202 c .......... elimination operations on next vector
203 c iterate ..........
204 780 do 820 i = ip, q
205 u = rv6(i)
206 c .......... if rv1(i-1) .eq. e(i), a row interchange
207 c was performed earlier in the
208 c triangularization process ..........
209 if (rv1(i-1) .ne. e(i)) go to 800
210 u = rv6(i-1)
211 rv6(i-1) = rv6(i)
212 800 rv6(i) = u - rv4(i) * rv6(i-1)
213 820 continue
214
215 its = its + 1
216 go to 600
217 c .......... set error -- non-converged eigenvector ..........
218 830 ierr = -r
219 xu = 0.0d0
220 go to 870
221 c .......... normalize so that sum of squares is
222 c 1 and expand to full order ..........
223 840 u = 0.0d0
224
225 do 860 i = p, q
226 860 u = pythag(u,rv6(i))
227
228 xu = 1.0d0 / u
229
230 870 do 880 i = 1, n
231 880 z(i,r) = 0.0d0
232
233 do 900 i = p, q
234 900 z(i,r) = rv6(i) * xu
235
236 x0 = x1
237 920 continue
238
239 if (q .lt. n) go to 100
240 1001 return
241 end