PROGRAM f08nffe ! F08NFF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : dgehrd, dgemm, dhseqr, dorghr, nag_wp, x04caf ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nin = 5, nout = 6 ! .. Local Scalars .. REAL (KIND=nag_wp) :: alpha, beta INTEGER :: i, ifail, info, lda, ldc, ldd, ldz, & lwork, n ! .. Local Arrays .. REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), c(:,:), d(:,:), tau(:), & wi(:), work(:), wr(:), z(:,:) ! .. Executable Statements .. WRITE (nout,*) 'F08NFF Example Program Results' ! Skip heading in data file READ (nin,*) READ (nin,*) n lda = n ldz = n ldc = n ldd = n lwork = 64*(n-1) ALLOCATE (a(lda,n),c(ldc,n),d(ldd,n),tau(n),wi(n),work(lwork),wr(n), & z(ldz,n)) ! Read A from data file READ (nin,*) (a(i,1:n),i=1,n) WRITE (nout,*) FLUSH (nout) ! Print Matrix A ! ifail: behaviour on error exit ! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft ifail = 0 CALL x04caf('General',' ',n,n,a,lda,'Matrix A',ifail) WRITE (nout,*) FLUSH (nout) ! Reduce A to upper Hessenberg form H = (Q**T)*A*Q ! The NAG name equivalent of dgehrd is f08nef CALL dgehrd(n,1,n,a,lda,tau,work,lwork,info) ! Copy A into Z z(1:n,1:n) = a(1:n,1:n) ! Form Q explicitly, storing the result in Z ! The NAG name equivalent of dorghr is f08nff CALL dorghr(n,1,n,z,ldz,tau,work,lwork,info) ! Calculate the Schur factorization of H = Y*T*(Y**T) and form ! Q*Y explicitly, storing the result in Z ! Note that A = Z*T*(Z**T), where Z = Q*Y ! The NAG name equivalent of dhseqr is f08pef CALL dhseqr('Schur form','Vectors',n,1,n,a,lda,wr,wi,z,ldz,work,lwork, & info) ! Compute Z*T*(Z**T) from the factorization of A alpha = 1._nag_wp beta = 0._nag_wp CALL dgemm('N','N',n,n,n,alpha,z,ldz,a,lda,beta,c,ldc) CALL dgemm('N','T',n,n,n,alpha,c,ldc,z,ldz,beta,d,ldd) ! Print solution ifail = 0 CALL x04caf('General',' ',n,n,d,ldd, & 'Matrix A recreated from factorization Z*T*Z^T',ifail) WRITE (nout,*) FLUSH (nout) END PROGRAM f08nffe