* F08BEF Example Program Text * Mark 16 Release. NAG Copyright 1992. * .. Parameters .. INTEGER NIN, NOUT PARAMETER (NIN=5,NOUT=6) INTEGER MMAX, NMAX, LDA, LDB, LDX, NRHMAX, LWORK PARAMETER (MMAX=8,NMAX=8,LDA=MMAX,LDB=MMAX,LDX=MMAX, + NRHMAX=NMAX,LWORK=64*NMAX) DOUBLE PRECISION ZERO PARAMETER (ZERO=0.0D0) * .. Local Scalars .. DOUBLE PRECISION TOL INTEGER I, IFAIL, INFO, J, K, M, N, NRHS * .. Local Arrays .. DOUBLE PRECISION A(LDA,NMAX), B(LDB,NRHMAX), TAU(NMAX), + WORK(LWORK), X(LDX,NRHMAX) INTEGER JPVT(NMAX) * .. External Subroutines .. EXTERNAL DGEQPF, DORMQR, DTRSV, F06DBF, F06FBF, X04CAF * .. Intrinsic Functions .. INTRINSIC ABS * .. Executable Statements .. WRITE (NOUT,*) 'F08BEF Example Program Results' * Skip heading in data file READ (NIN,*) READ (NIN,*) M, N, NRHS IF (M.LE.MMAX .AND. N.LE.NMAX .AND. M.GE.N .AND. NRHS.LE.NRHMAX) + THEN * * Read A and B from data file * READ (NIN,*) ((A(I,J),J=1,N),I=1,M) READ (NIN,*) ((B(I,J),J=1,NRHS),I=1,M) * * Initialize JPVT to be zero so that all columns are free * CALL F06DBF(N,0,JPVT,1) * * Compute the QR factorization of A * CALL DGEQPF(M,N,A,LDA,JPVT,TAU,WORK,INFO) * * Choose TOL to reflect the relative accuracy of the input data * TOL = 0.01D0 * * Determine which columns of R to use * DO 20 K = 1, N IF (ABS(A(K,K)).LE.TOL*ABS(A(1,1))) GO TO 40 20 CONTINUE * * Compute C = (Q**T)*B, storing the result in B * 40 K = K - 1 * CALL DORMQR('Left','Transpose',M,NRHS,N,A,LDA,TAU,B,LDB,WORK, + LWORK,INFO) * * Compute least-squares solution by backsubstitution in R*B = C * DO 60 I = 1, NRHS * CALL DTRSV('Upper','No transpose','Non-Unit',K,A,LDA,B(1,I), + 1) * * Set the unused elements of the I-th solution vector to zero * CALL F06FBF(N-K,ZERO,B(K+1,I),1) * 60 CONTINUE * * Unscramble the least-squares solution stored in B * DO 100 I = 1, N DO 80 J = 1, NRHS X(JPVT(I),J) = B(I,J) 80 CONTINUE 100 CONTINUE * * Print least-squares solution * WRITE (NOUT,*) IFAIL = 0 * CALL X04CAF('General',' ',N,NRHS,X,LDX, + 'Least-squares solution',IFAIL) * END IF END