* F08ZNF 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=PMAX,LWORK=PMAX+NMAX+NB*(MMAX+NMAX) + ) * .. Local Scalars .. DOUBLE PRECISION RNORM INTEGER I, INFO, J, M, N, P * .. Local Arrays .. COMPLEX *16 A(LDA,NMAX), B(LDB,NMAX), C(MMAX), D(PMAX), + WORK(LWORK), X(NMAX) * .. External Functions .. DOUBLE PRECISION DZNRM2 EXTERNAL DZNRM2 * .. External Subroutines .. EXTERNAL ZGGLSE * .. Executable Statements .. WRITE (NOUT,*) 'F08ZNF 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, C and D from data file * READ (NIN,*) ((A(I,J),J=1,N),I=1,M) READ (NIN,*) ((B(I,J),J=1,N),I=1,P) READ (NIN,*) (C(I),I=1,M) READ (NIN,*) (D(I),I=1,P) * * Solve the equality-constrained least-squares problem * * minimize ||c - A*x|| (in the 2-norm) subject to B*x = D * CALL ZGGLSE(M,N,P,A,LDA,B,LDB,C,D,X,WORK,LWORK,INFO) * * Print least-squares solution * WRITE (NOUT,*) 'Constrained least-squares solution' WRITE (NOUT,99999) (X(I),I=1,N) * * Compute the square root of the residual sum of squares * RNORM = DZNRM2(M-N+P,C(N-P+1),1) WRITE (NOUT,*) WRITE (NOUT,*) 'Square root of the residual sum of squares' WRITE (NOUT,99998) RNORM ELSE WRITE (NOUT,*) + 'One or more of MMAX, NMAX and PMAX is too small' END IF STOP * 99999 FORMAT (4(' (',F7.4,',',F7.4,')',:)) 99998 FORMAT (1X,1P,E10.2) END