* F08BNF Example Program Text * Mark 21 Release. NAG Copyright 2004. * .. Parameters .. INTEGER NIN, NOUT PARAMETER (NIN=5,NOUT=6) INTEGER MMAX, NB, NMAX PARAMETER (MMAX=16,NB=64,NMAX=8) INTEGER LDA, LWORK PARAMETER (LDA=MMAX,LWORK=NB*(NMAX+1)) * .. Local Scalars .. DOUBLE PRECISION RCOND INTEGER I, INFO, J, M, N, RANK * .. Local Arrays .. COMPLEX *16 A(LDA,NMAX), B(MMAX), WORK(LWORK) DOUBLE PRECISION RWORK(2*NMAX) INTEGER JPVT(NMAX) * .. External Subroutines .. EXTERNAL F06DBF, ZGELSY * .. Executable Statements .. WRITE (NOUT,*) 'F08BNF Example Program Results' WRITE (NOUT,*) * Skip heading in data file READ (NIN,*) READ (NIN,*) M, N IF (M.LE.MMAX .AND. N.LE.NMAX .AND. M.GE.N) THEN * * Read A and B from data file * READ (NIN,*) ((A(I,J),J=1,N),I=1,M) READ (NIN,*) (B(I),I=1,M) * * Initialize JPVT to be zero so that all columns are free * CALL F06DBF(N,0,JPVT,1) * * Choose RCOND to reflect the relative accuracy of the input data * RCOND = 0.01D0 * * Solve the least squares problem min( norm2(b - Ax) ) for the x * of minimum norm. * CALL ZGELSY(M,N,1,A,LDA,B,M,JPVT,RCOND,RANK,WORK,LWORK,RWORK, + INFO) * * Print solution * WRITE (NOUT,*) 'Least squares solution' WRITE (NOUT,99999) (B(I),I=1,N) * * Print the effective rank of A * WRITE (NOUT,*) WRITE (NOUT,*) 'Tolerance used to estimate the rank of A' WRITE (NOUT,99998) RCOND WRITE (NOUT,*) 'Estimated rank of A' WRITE (NOUT,99997) RANK ELSE WRITE (NOUT,*) 'MMAX and/or NMAX too small, and/or M.LT.N' END IF * 99999 FORMAT (4(' (',F7.4,',',F7.4,')',:)) 99998 FORMAT (1X,1P,E10.2) 99997 FORMAT (1X,I6) END