-
Notifications
You must be signed in to change notification settings - Fork 2
/
qrdcmp.for
47 lines (47 loc) · 1.16 KB
/
qrdcmp.for
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
SUBROUTINE qrdcmp(a,n,np,c,d,sing)
use precision,only:p_
implicit none
INTEGER n,np
REAL(p_) a(np,np),c(n),d(n)
LOGICAL sing
INTEGER i,j,k
REAL(p_) scale,sigma,sum,tau
sing=.false.
scale=0.
do 17 k=1,n-1
do 11 i=k,n
scale=max(scale,abs(a(i,k)))
11 continue
if(scale.eq.0.)then
sing=.true.
c(k)=0.
d(k)=0.
else
do 12 i=k,n
a(i,k)=a(i,k)/scale
12 continue
sum=0.
do 13 i=k,n
sum=sum+a(i,k)**2
13 continue
sigma=sign(sqrt(sum),a(k,k))
a(k,k)=a(k,k)+sigma
c(k)=sigma*a(k,k)
d(k)=-scale*sigma
do 16 j=k+1,n
sum=0.
do 14 i=k,n
sum=sum+a(i,k)*a(i,j)
14 continue
tau=sum/c(k)
do 15 i=k,n
a(i,j)=a(i,j)-tau*a(i,k)
15 continue
16 continue
endif
17 continue
d(n)=a(n,n)
if(d(n).eq.0.)sing=.true.
return
END
C (C) Copr. 1986-92 Numerical Recipes Software ,4-#.