PROGRAM f08krfe ! F08KRF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : ddisna, nag_wp, x02ajf, x04daf, zgesdd ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nb = 64, nin = 5, nout = 6 ! .. Local Scalars .. REAL (KIND=nag_wp) :: eps, serrbd INTEGER :: i, ifail, info, lda, ldu, lwork, m, n ! .. Local Arrays .. COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:), u(:,:), work(:) COMPLEX (KIND=nag_wp) :: dummy(1,1) REAL (KIND=nag_wp), ALLOCATABLE :: rcondu(:), rcondv(:), rwork(:), & s(:), uerrbd(:), verrbd(:) INTEGER, ALLOCATABLE :: iwork(:) ! .. Intrinsic Functions .. INTRINSIC max, nint, real ! .. Executable Statements .. WRITE (nout,*) 'F08KRF Example Program Results' WRITE (nout,*) ! Skip heading in data file READ (nin,*) READ (nin,*) m, n lda = m ldu = m ALLOCATE (a(lda,n),u(ldu,m),rcondu(m),rcondv(m),rwork((5*m+ & 7)*m),s(m),uerrbd(m),verrbd(m),iwork(8*m)) ! Use routine workspace query to get optimal workspace. lwork = -1 ! The NAG name equivalent of zgesdd is f08krf CALL zgesdd('Overwrite A by V**H',m,n,a,lda,s,u,ldu,dummy,1,dummy, & lwork,rwork,iwork,info) ! Make sure that there is enough workspace for blocksize nb. lwork = max((2*m+2)*m+2*n+nb*(m+n),nint(real(dummy(1,1)))) ALLOCATE (work(lwork)) ! Read the m by n matrix A from data file READ (nin,*) (a(i,1:n),i=1,m) ! Compute the singular values and left and right singular vectors ! of A (A = U*S*(V**H), m.le.n) ! The NAG name equivalent of zgesdd is f08krf CALL zgesdd('Overwrite A by V**H',m,n,a,lda,s,u,ldu,dummy,1,work,lwork, & rwork,iwork,info) IF (info==0) THEN ! Print solution WRITE (nout,*) 'Singular values' WRITE (nout,99999) s(1:m) FLUSH (nout) ! ifail: behaviour on error exit ! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft ifail = 0 CALL x04daf('General',' ',m,m,u,ldu,'Left singular vectors',ifail) WRITE (nout,*) FLUSH (nout) CALL x04daf('General',' ',m,n,a,lda, & 'Conjugates of right singular vectors by row '// & '(first m rows of V**H)',ifail) ! Get the machine precision, EPS and compute the approximate ! error bound for the computed singular values. Note that for ! the 2-norm, S(1) = norm(A) eps = x02ajf() serrbd = eps*s(1) ! Call DDISNA (F08FLF) to estimate reciprocal condition ! numbers for the singular vectors CALL ddisna('Left',m,n,s,rcondu,info) CALL ddisna('Right',m,n,s,rcondv,info) ! Compute the error estimates for the singular vectors DO i = 1, m uerrbd(i) = serrbd/rcondu(i) verrbd(i) = serrbd/rcondv(i) END DO ! Print the approximate error bounds for the singular values ! and vectors WRITE (nout,*) WRITE (nout,*) 'Error estimate for the singular values' WRITE (nout,99998) serrbd WRITE (nout,*) WRITE (nout,*) 'Error estimates for the left singular vectors' WRITE (nout,99998) uerrbd(1:m) WRITE (nout,*) WRITE (nout,*) 'Error estimates for the right singular vectors' WRITE (nout,99998) verrbd(1:m) ELSE WRITE (nout,99997) 'Failure in ZGESDD. INFO =', info END IF 99999 FORMAT (3X,(8F8.4)) 99998 FORMAT (4X,1P,6E11.1) 99997 FORMAT (1X,A,I4) END PROGRAM f08krfe