PROGRAM f08zpfe ! F08ZPF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : dznrm2, nag_wp, zggglm ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nb = 64, nin = 5, nout = 6 ! .. Local Scalars .. REAL (KIND=nag_wp) :: rnorm INTEGER :: i, info, lda, ldb, lwork, m, n, p ! .. Local Arrays .. COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:), b(:,:), d(:), work(:), & x(:), y(:) ! .. Executable Statements .. WRITE (nout,*) 'F08ZPF Example Program Results' WRITE (nout,*) ! Skip heading in data file READ (nin,*) READ (nin,*) m, n, p lda = m ldb = m lwork = n + m + nb*(m+p) ALLOCATE (a(lda,n),b(ldb,p),d(m),work(lwork),x(n),y(p)) ! Read A, B and D from data file READ (nin,*) (a(i,1:n),i=1,m) READ (nin,*) (b(i,1:p),i=1,m) READ (nin,*) d(1:m) ! Solve the weighted least-squares problem ! minimize ||inv(B)*(d - A*x)|| (in the 2-norm) ! The NAG name equivalent of zggglm is f08zpf 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(1:n) ! Print residual vector y = inv(B)*(d - A*x) WRITE (nout,*) WRITE (nout,*) 'Residual vector' WRITE (nout,99998) y(1:p) ! Compute and print the square root of the residual sum of squares ! The NAG name equivalent of dznrm2 is f06jjf rnorm = dznrm2(p,y,1) WRITE (nout,*) WRITE (nout,*) 'Square root of the residual sum of squares' WRITE (nout,99997) rnorm 99999 FORMAT (3(' (',F9.4,',',F9.4,')':)) 99998 FORMAT (3(' (',1P,E9.2,',',1P,E9.2,')':)) 99997 FORMAT (1X,1P,E10.2) END PROGRAM f08zpfe