Rev 71593 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
C Dqrdc2 is a *modification* of Linpack's dqrdc ('DQRDC') for Rcc dqrdc2 uses householder transformations to compute the qrc factorization of an n by p matrix x. a limited columnc pivoting strategy based on the 2-norms of the reduced columnsc moves columns with near-zero norm to the right-hand edge ofc the x matrix. this strategy means that sequential onec degree-of-freedom effects can be computed in a natural way.cc i am very nervous about modifying linpack code in this way.c if you are a computational linear algebra guru and you reallyc understand how to solve this problem please feel free toc suggest improvements to this code.cc Another change was to compute the rank.cc on entrycc x double precision(ldx,p), where ldx .ge. n.c x contains the matrix whose decomposition is to bec computed.cc ldx integer.c ldx is the leading dimension of the array x.cc n integer.c n is the number of rows of the matrix x.cc p integer.c p is the number of columns of the matrix x.cc tol double precisionc tol is the nonnegative tolerance used toc determine the subset of the columns of xc included in the solution.cc jpvt integer(p).c integers which are swapped in the same way as thec the columns of x during pivoting. on entry thesec should be set equal to the column indices of thec columns of the x matrix (typically 1 to p).cc work double precision(p,2).c work is a work array.cc on returncc x x contains in its upper triangle the upperc triangular matrix r of the qr factorization.c below its diagonal x contains information fromc which the orthogonal part of the decompositionc can be recovered. note that if pivoting hasc been requested, the decomposition is not thatc of the original matrix x but that of xc with its columns permuted as described by jpvt.cc k integer.c k contains the number of columns of x judgedc to be linearly independent, i.e., "the rank"cc qraux double precision(p).c qraux contains further information required to recoverc the orthogonal part of the decomposition.cc jpvt jpvt(j) contains the index of the column of thec original matrix that has been interchanged intoc the j-th column. Consequently, jpvt[] codes ac permutation of 1:p; it is called 'pivot' in Rcc original (dqrdc.f) linpack version dated 08/14/78 .c g.w. stewart, university of maryland, argonne national lab.cC This version dated 22 August 1995C Ross Ihakacc bug fixes 29 September 1999 BDR (p > n case, inaccurate ranks)ccc dqrdc2 uses the following functions and subprograms.cc blas daxpy,ddot,dscal,dnrm2c fortran dabs,dmax1,min0,dsqrtcsubroutine dqrdc2(x,ldx,n,p,tol,k,qraux,jpvt,work)integer ldx,n,pinteger jpvt(*)double precision x(ldx,*),qraux(*),work(p,2),tolcc internal variablescinteger i,j,l,lp1,lup,kdouble precision dnrm2,tt,tttdouble precision ddot,nrmxl,tccc compute the norms of the columns of x.cdo 70 j = 1, pqraux(j) = dnrm2(n,x(1,j),1)work(j,1) = qraux(j)work(j,2) = qraux(j)if(work(j,2) .eq. 0.0d0) work(j,2) = 1.0d070 continuecc perform the householder reduction of x.clup = min0(n,p)k = p + 1do 200 l = 1, lupcc previous version only cycled l to lupcc cycle the columns from l to p left-to-right until onec with non-negligible norm is located. a column is consideredc to have become negligible if its norm has fallen belowc tol times its original norm. the check for l .le. kc avoids infinite cycling.c80 continueif (l .ge. k .or. qraux(l) .ge. work(l,2)*tol) go to 120lp1 = l+1do 100 i=1,nt = x(i,l)do 90 j=lp1,px(i,j-1) = x(i,j)90 continuex(i,p) = t100 continuei = jpvt(l)t = qraux(l)tt = work(l,1)ttt = work(l,2)do 110 j=lp1,pjpvt(j-1) = jpvt(j)qraux(j-1) = qraux(j)work(j-1,1) = work(j,1)work(j-1,2) = work(j,2)110 continuejpvt(p) = iqraux(p) = twork(p,1) = ttwork(p,2) = tttk = k - 1go to 80120 continueif (l .eq. n) go to 190cc compute the householder transformation for column l.cnrmxl = dnrm2(n-l+1,x(l,l),1)if (nrmxl .eq. 0.0d0) go to 180if (x(l,l) .ne. 0.0d0) nrmxl = dsign(nrmxl,x(l,l))call dscal(n-l+1,1.0d0/nrmxl,x(l,l),1)x(l,l) = 1.0d0 + x(l,l)cc apply the transformation to the remaining columns,c updating the norms.clp1 = l + 1if (p .lt. lp1) go to 170do 160 j = lp1, pt = -ddot(n-l+1,x(l,l),1,x(l,j),1)/x(l,l)call daxpy(n-l+1,t,x(l,l),1,x(l,j),1)if (qraux(j) .eq. 0.0d0) go to 150tt = 1.0d0 - (dabs(x(l,j))/qraux(j))**2tt = dmax1(tt,0.0d0)t = ttcc modified 9/99 by BDR. Re-compute norms if there is large reductionc The tolerance here is on the squared normc In this version we need accurate norms, so re-compute often.c work(j,1) is only updated in one case: looks like a bug -- no longer usedcc tt = 1.0d0 + 0.05d0*tt*(qraux(j)/work(j,1))**2c if (tt .eq. 1.0d0) go to 130if (dabs(t) .lt. 1d-6) go to 130qraux(j) = qraux(j)*dsqrt(t)go to 140130 continueqraux(j) = dnrm2(n-l,x(l+1,j),1)work(j,1) = qraux(j)140 continue150 continue160 continue170 continuecc save the transformation.cqraux(l) = x(l,l)x(l,l) = -nrmxl180 continue190 continue200 continuek = min0(k - 1, n)returnend