1 subroutine covar(n,r,ldr,ipvt,tol,wa)
5 double precision r(ldr,n),wa(n)
10 c given an m by n matrix a, the problem is to determine
11 c the covariance matrix corresponding to a, defined as
16 c this
subroutine completes the solution of the problem
17 c
if it is provided with the necessary information from the
18 c qr factorization, with column pivoting, of a. that is,
if
19 c a*p = q*r,
where p is a permutation matrix, q has orthogonal
20 c columns, and r is an upper triangular matrix with diagonal
21 c elements of nonincreasing magnitude,
then covar expects the
22 c full upper triangle of r and the permutation matrix p.
23 c the covariance matrix is
then computed as
28 c
if a is nearly rank deficient, it may be desirable to compute
29 c the covariance matrix corresponding to the linearly independent
30 c columns of a. to define the numerical rank of a,
covar uses
31 c the tolerance tol.
If l is the largest
integer such that
33 c abs(r(l,l)) .gt. tol*abs(r(1,1)) ,
35 c
then covar computes the covariance matrix corresponding to
36 c the first l columns of r. for k greater than l, column
37 c and row ipvt(k) of the covariance matrix are set to zero.
39 c the
subroutine statement is
41 c
subroutine covar(n,r,ldr,ipvt,tol,wa)
46 c n is a positive
integer input variable set to the order of r.
48 c r is an n by n array. on input, the full upper triangle must
49 c contain the full upper triangle of the matrix r. on
50 c output r
contains the square symmetric covariance
53 c ldr is a positive
integer input variable not less than n
54 c which specifies the leading dimension of the array r.
56 c ipvt is an
integer input array of length n which defines the
57 c permutation matrix p such that a*p = q*r. column j of p
58 c is column ipvt(j) of the identity matrix.
60 c tol is a nonnegative input variable used to define the
61 c numerical rank of a in the manner described above.
63 c wa is a work array of length n
67 c fortran-supplied ... dabs
69 c argonne national laboratory. minpack project. march 1980.
70 c burton s. garbow, kenneth e. hillstrom, jorge j. more
73 integer i,ii,j,jj,k,km1,l
75 double precision one,temp,tolr,zero
76 data one,zero /1.0d0,0.0d0/
78 c----------------------------------------------------------------------
79 c form the inverse of r in the full upper triangle of r.
80 c----------------------------------------------------------------------
81 tolr = tol*dabs(r(1,1))
84 if (dabs(r(k,k)) .le. tolr)
goto 50
92 r(i,k) = r(i,k) - temp*r(i,j)
100 c----------------------------------------------------------------------
101 c form the full upper triangle of the inverse of(r transpose)*r
102 c in the full upper triangle of r
103 c----------------------------------------------------------------------
111 r(i,j) = r(i,j) + temp*r(i,k)
123 c----------------------------------------------------------------------
124 c form the full lower triangle of the covariance matrix
125 c in the strict lower triangle of r and in wa
126 c----------------------------------------------------------------------
131 if (sing) r(i,j) = zero
133 if (ii .gt. jj) r(ii,jj) = r(i,j)
134 if (ii .lt. jj) r(jj,ii) = r(i,j)
139 c----------------------------------------------------------------------
140 c symmetrize the covariance matrix in r.
141 c----------------------------------------------------------------------
subroutine covar(n, r, ldr, ipvt, tol, wa)