* F04KLF Example Program Text * Mark 20 Revised. NAG Copyright 2001. * .. Parameters .. INTEGER NIN, NOUT PARAMETER (NIN=5,NOUT=6) INTEGER NMAX, MMAX, PMAX, LDA, LDB, LWORK PARAMETER (NMAX=10,MMAX=10,PMAX=10,LDA=MMAX,LDB=MMAX, + LWORK=NMAX+MMAX+64*(MMAX+PMAX)) * .. Local Scalars .. INTEGER I, IFAIL, J, M, N, P * .. Local Arrays .. COMPLEX *16 A(LDA,NMAX), B(LDB,PMAX), D(MMAX), WORK(LWORK), + X(NMAX), Y(PMAX) * .. External Subroutines .. EXTERNAL F04KLF * .. Intrinsic Functions .. INTRINSIC AIMAG, DBLE * .. Executable Statements .. WRITE (NOUT,*) 'F04KLF Example Program Results' * 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) * IFAIL = 1 * CALL F04KLF(M,N,P,A,LDA,B,LDB,D,X,Y,WORK,LWORK,IFAIL) * * Print least-squares solution * IF (IFAIL.EQ.0) THEN WRITE (NOUT,*) WRITE (NOUT,*) 'Least-squares solution' WRITE (NOUT,99999) (' (',DBLE(X(I)),',',AIMAG(X(I)),')',I=1, + N) ELSE WRITE (NOUT,99998) IFAIL END IF END IF * 99999 FORMAT ((3X,4(A,F7.4,A,F7.4,A,:))) 99998 FORMAT (1X,/1X,' ** F04KLF returned with IFAIL = ',I5) END