* F08ZPF Example Program Text * Mark 17 Release. NAG Copyright 1995. * .. Parameters .. INTEGER NIN, NOUT PARAMETER (NIN=5,NOUT=6) INTEGER MMAX, NB, NMAX, PMAX PARAMETER (MMAX=10,NB=64,NMAX=10,PMAX=10) INTEGER LDA, LDB, LWORK PARAMETER (LDA=MMAX,LDB=MMAX,LWORK=NMAX+MMAX+NB*(MMAX+PMAX) + ) * .. Local Scalars .. DOUBLE PRECISION RNORM INTEGER I, INFO, J, M, N, P * .. Local Arrays .. COMPLEX *16 A(LDA,NMAX), B(LDB,PMAX), D(MMAX), WORK(LWORK), + X(NMAX), Y(PMAX) * .. External Functions .. DOUBLE PRECISION DZNRM2 EXTERNAL DZNRM2 * .. External Subroutines .. EXTERNAL ZGGGLM * .. Executable Statements .. WRITE (NOUT,*) 'F08ZPF Example Program Results' WRITE (NOUT,*) * Skip heading in data file READ (NIN,*) READ (NIN,*) M, N, P IF (M.LE.MMAX .AND. N.LE.NMAX .AND. P.LE.PMAX) THEN * * Read A, B and D from data file * READ (NIN,*) ((A(I,J),J=1,N),I=1,M) READ (NIN,*) ((B(I,J),J=1,P),I=1,M) READ (NIN,*) (D(I),I=1,M) * * Solve the weighted least-squares problem * * minimize ||inv(B)*(d - A*x)|| (in the 2-norm) * CALL ZGGGLM(M,N,P,A,LDA,B,LDB,D,X,Y,WORK,LWORK,INFO) * * Print least-squares solution * WRITE (NOUT,*) 'Weighted least-squares solution' WRITE (NOUT,99999) (X(I),I=1,N) * * Print residual vector y = inv(B)*(d - A*x) * WRITE (NOUT,*) WRITE (NOUT,*) 'Residual vector' WRITE (NOUT,99998) (Y(I),I=1,P) * * Compute and print the square root of the residual sum of * squares * RNORM = DZNRM2(P,Y,1) * WRITE (NOUT,*) WRITE (NOUT,*) 'Square root of the residual sum of squares' WRITE (NOUT,99997) RNORM ELSE WRITE (NOUT,*) + 'One or more of MMAX, NMAX and PMAX is too small' END IF * 99999 FORMAT (3(' (',F9.4,',',F9.4,')',:)) 99998 FORMAT (3(' (',1P,E9.2,',',1P,E9.2,')',:)) 99997 FORMAT (1X,1P,E10.2) END