Rev 86632 | 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)c Fortran modernized to F77, 2024-05 BDRccc dqrdc2 uses the following functions and subprograms.cc blas daxpy,ddot,dscal,dnrm2c fortran abs,max,min,sqrtcsubroutine dqrdc2(x,ldx,n,p,tol,k,qraux,jpvt,work)integer ldx,n,pinteger jpvt(p)double precision x(ldx,p),qraux(p),work(p,2),tolcc internal variablescinteger i,j,l,lup,kdouble precision dnrm2,tt,tttdouble precision ddot,nrmxl,tccc compute the norms of the columns of x.cif (n .gt. 0) thenc avoid accessing element beyond the bounddo 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.0d0end do ! jend ifcc perform the householder reduction of x.clup = min(n,p)k = p + 1do 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.cdoif (l .ge. k .or. qraux(l) .ge. work(l,2)*tol) exitdo i=1,nt = x(i,l)do j=l+1,px(i,j-1) = x(i,j)end do ! jx(i,p) = tend do ! ii = jpvt(l)t = qraux(l)tt = work(l,1)ttt = work(l,2)do j=l+1,pjpvt(j-1) = jpvt(j)qraux(j-1) = qraux(j)work(j-1,1) = work(j,1)work(j-1,2) = work(j,2)end do ! jjpvt(p) = iqraux(p) = twork(p,1) = ttwork(p,2) = tttk = k - 1end do ! (no index)if (l .ne. n) thencc compute the householder transformation for column l.cnrmxl = dnrm2(n-l+1,x(l,l),1)if (nrmxl .ne. 0.0d0) thenif (x(l,l) .ne. 0.0d0) nrmxl = sign(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.cif (p .ge. l+1) thendo j = l+1, 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) .ne. 0.0d0) thentt = 1.0d0 - (abs(x(l,j))/qraux(j))**2tt = max(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.if (dabs(t) .ge. 1d-6) thenqraux(j) = qraux(j)*sqrt(t)elseqraux(j) = dnrm2(n-l,x(l+1,j),1)work(j,1) = qraux(j)end ifend ifend do ! jend ifcc Save the transformation.cqraux(l) = x(l,l)x(l,l) = -nrmxlend ifend ifend do ! lk = min(k - 1, n)returnend