1
subroutine comqr3(nm,n,low,igh,hr,hi,wr,wi,zr,zi,ierr,job)
3
integer i,j,l,n,en,ll,nm,igh,ip1,
4
x itn,its,low,lp1,enm1,iend,ierr
5
double precision hr(nm,n),hi(nm,n),wr(n),wi(n),zr(nm,n),zi(nm,n)
6
double precision si,sr,ti,tr,xi,xr,yi,yr,zzi,zzr,norm
7
double precision pythag
10
c this subroutine is a translation of a unitary analogue of the
11
c algol procedure comlr2, num. math. 16, 181-204(1970) by peters
13
c handbook for auto. comp., vol.ii-linear algebra, 372-395(1971).
14
c the unitary analogue substitutes the qr algorithm of francis
15
c (comp. jour. 4, 332-345(1962)) for the lr algorithm.
17
c modified by c. moler
19
c this subroutine finds the eigenvalues of a complex upper
20
c hessenberg matrix by the qr method. The unitary transformation
21
c can also be accumulated if corth has been used to reduce
22
c this general matrix to hessenberg form.
24
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
25
c MODIFICATION OF EISPACK COMQR+COMQR2
26
c 1. job parameter added
27
c 2. code concerning eigenvector computation deleted
28
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
31
c subroutine comqr3(nm,n,low,igh,hr,hi,wr,wi,zr,zi,ierr
36
c nm must be set to the row dimension of two-dimensional
37
c array parameters as declared in the calling program
38
c dimension statement.
40
c n is the order of the matrix.
42
c low and igh are integers determined by the balancing
43
c subroutine cbal. if cbal has not been used,
46
c hr and hi contain the real and imaginary parts,
47
c respectively, of the complex upper hessenberg matrix.
48
c their lower triangles below the subdiagonal contain further
49
c information about the transformations which were used in the
50
c reduction by corth, if performed.
52
c zr and zi contain the real and imaginary parts,respectively
53
c of the unitary similarity used to put h on hessenberg form
54
c or a unitary matrix ,if vectors are desired
56
c job indicate the job to be performed: job=xy
57
c if y=0 no accumulation of the unitary transformation
58
c if y=1 transformation accumulated in z
61
c the upper hessenberg portions of hr and hi have been destroyed
64
c wr and wi contain the real and imaginary parts,
65
c respectively, of the eigenvalues. if an error
66
c exit is made, the eigenvalues should be correct
67
c for indices ierr+1,...,n.
69
c zr and zi contain the real and imaginary parts,
70
c respectively, of the eigenvectors. the eigenvectors
71
c are unnormalized. if an error exit is made, none of
72
c the eigenvectors has been found.
75
c zero for normal return,
76
c j if the j-th eigenvalue has not been
77
c determined after a total of 30*n iterations.
80
c questions and comments should be directed to b. s. garbow,
81
c applied mathematics division, argonne national laboratory
86
c ------------------------------------------------------------------
93
c .......... create real subdiagonal elements ..........
95
if(iend.lt.0) goto 180
100
if (hi(i,i-1) .eq. 0.0d+0) go to 170
101
norm = pythag(hr(i,i-1),hi(i,i-1))
108
si = yr*hi(i,j) - yi*hr(i,j)
109
hr(i,j) = yr*hr(i,j) + yi*hi(i,j)
114
si = yr*hi(j,i) + yi*hr(j,i)
115
hr(j,i) = yr*hr(j,i) - yi*hi(j,i)
119
if (jy .eq. 0) go to 170
122
si = yr*zi(j,i) + yi*zr(j,i)
123
zr(j,i) = yr*zr(j,i) - yi*zi(j,i)
128
c .......... store roots isolated by cbal ..........
131
if (i .ge. low .and. i .le. igh) go to 200
141
c .......... search for next eigenvalue ..........
142
220 if (en .lt. low) go to 1001
145
c .......... look for single small sub-diagonal element
146
c for l=en step -1 until low do -- ..........
147
240 do 260 ll = low, en
149
if (l .eq. low) go to 300
151
xr = abs(hr(l-1,l-1)) + abs(hi(l-1,l-1)
152
x + abs(hr(l,l)) +abs(hi(l,l)))
153
yr = xr + abs(hr(l,l-1))
154
if (xr .eq. yr) go to 300
157
c .......... form shift ..........
158
300 if (l .eq. en) go to 660
159
if (itn .eq. 0) go to 1000
160
if (its .eq. 10 .or. its .eq. 20) go to 320
163
xr = hr(enm1,en)*hr(en,enm1)
164
xi = hi(enm1,en)*hr(en,enm1)
165
if (xr .eq. 0.0d+0 .and. xi .eq. 0.0d+0) go to 340
166
yr = (hr(enm1,enm1) - sr)/2.0d+0
167
yi = (hi(enm1,enm1) - si)/2.0d+0
168
call wsqrt(yr**2-yi**2+xr,2.0d+0*yr*yi+xi,zzr,zzi)
169
if (yr*zzr + yi*zzi .ge. 0.0d+0) go to 310
172
310 call cdiv(xr,xi,yr+zzr,yi+zzi,zzr,zzi)
176
c .......... form exceptional shift ..........
177
320 sr = abs(hr(en,enm1)) + abs(hr(enm1,en-2))
180
340 do 360 i = low, en
181
hr(i,i) = hr(i,i) - sr
182
hi(i,i) = hi(i,i) - si
189
c .......... reduce to triangle (rows) ..........
195
norm = pythag(pythag(hr(i-1,i-1),hi(i-1,i-1)),sr)
196
xr = hr(i-1,i-1)/norm
198
xi = hi(i-1,i-1)/norm
209
hr(i-1,j) = xr*yr + xi*yi + hi(i,i-1)*zzr
210
hi(i-1,j) = xr*yi - xi*yr + hi(i,i-1)*zzi
211
hr(i,j) = xr*zzr - xi*zzi - hi(i,i-1)*yr
212
hi(i,j) = xr*zzi + xi*zzr - hi(i,i-1)*yi
218
if (si .eq. 0.0d+0) go to 540
219
norm = pythag(hr(en,en),si)
224
if (en .eq. n) go to 540
230
hr(en,j) = sr*yr + si*yi
231
hi(en,j) = sr*yi - si*yr
233
c .......... inverse operation (columns) ..........
234
540 do 600 j = lp1, en
243
if (i .eq. j) go to 560
245
hi(i,j-1) = xr*yi + xi*yr + hi(j,j-1)*zzi
246
560 hr(i,j-1) = xr*yr - xi*yi + hi(j,j-1)*zzr
247
hr(i,j) = xr*zzr + xi*zzi - hi(j,j-1)*yr
248
hi(i,j) = xr*zzi - xi*zzr - hi(j,j-1)*yi
251
if (jy .eq. 0) go to 600
258
zr(i,j-1) = xr*yr - xi*yi + hi(j,j-1)*zzr
259
zi(i,j-1) = xr*yi + xi*yr + hi(j,j-1)*zzi
260
zr(i,j) = xr*zzr + xi*zzi - hi(j,j-1)*yr
261
zi(i,j) = xr*zzi - xi*zzr - hi(j,j-1)*yi
266
if (si .eq. 0.0d+0) go to 240
271
hr(i,en) = sr*yr - si*yi
272
hi(i,en) = sr*yi + si*yr
275
if (jy .eq. 0) go to 240
280
zr(i,en) = sr*yr - si*yi
281
zi(i,en) = sr*yi + si*yr
285
c .......... a root found ..........
286
660 hr(en,en) = hr(en,en) + tr
288
hi(en,en) = hi(en,en) + ti
292
c .......... all roots found. ..........
296
c .......... set error -- no convergence to an
297
c eigenvalue after 30 iterations ..........