* F08AAF 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=NMAX+NB*MMAX) * .. Local Scalars .. DOUBLE PRECISION RNORM INTEGER I, INFO, J, M, N * .. Local Arrays .. DOUBLE PRECISION A(LDA,NMAX), B(MMAX), WORK(LWORK) * .. External Functions .. DOUBLE PRECISION DNRM2 EXTERNAL DNRM2 * .. External Subroutines .. EXTERNAL DGELS * .. Executable Statements .. WRITE (NOUT,*) 'F08AAF 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) * * Solve the least squares problem min( norm2(b - Ax) ) for x * CALL DGELS('No transpose',M,N,1,A,LDA,B,M,WORK,LWORK,INFO) * * Print solution * WRITE (NOUT,*) 'Least squares solution' WRITE (NOUT,99999) (B(I),I=1,N) * * Compute and print estimate of the square root of the residual * sum of squares * RNORM = DNRM2(M-N,B(N+1),1) WRITE (NOUT,*) WRITE (NOUT,*) 'Square root of the residual sum of squares' WRITE (NOUT,99998) RNORM ELSE WRITE (NOUT,*) 'MMAX and/or NMAX too small, and/or M.LT.N' END IF STOP * 99999 FORMAT (1X,7F11.4) 99998 FORMAT (3X,1P,E11.2) END