PROGRAM f08yefe ! F08YEF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : dggsvp, dtgsja, f06raf, nag_wp, x02ajf, x04cbf ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nin = 5, nout = 6 ! .. Local Scalars .. REAL (KIND=nag_wp) :: eps, tola, tolb INTEGER :: i, ifail, info, irank, j, k, l, lda, & ldb, ldq, ldu, ldv, m, n, ncycle, p ! .. Local Arrays .. REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), alpha(:), b(:,:), beta(:), & q(:,:), tau(:), u(:,:), v(:,:), & work(:) INTEGER, ALLOCATABLE :: iwork(:) CHARACTER (1) :: clabs(1), rlabs(1) ! .. Intrinsic Functions .. INTRINSIC max, real ! .. Executable Statements .. WRITE (nout,*) 'F08YEF Example Program Results' WRITE (nout,*) FLUSH (nout) ! Skip heading in data file READ (nin,*) READ (nin,*) m, n, p lda = m ldb = p ldq = n ldu = m ldv = p ALLOCATE (a(lda,n),alpha(n),b(ldb,n),beta(n),q(ldq,n),tau(n),u(ldu,m), & v(ldv,p),work(m+3*n+p),iwork(n)) ! Read the m by n matrix A and p by n matrix B from data file READ (nin,*) (a(i,1:n),i=1,m) READ (nin,*) (b(i,1:n),i=1,p) ! Compute tola and tolb as ! tola = max(m,n)*norm(A)*macheps ! tolb = max(p,n)*norm(B)*macheps eps = x02ajf() tola = real(max(m,n),kind=nag_wp)*f06raf('One-norm',m,n,a,lda,work)*eps tolb = real(max(p,n),kind=nag_wp)*f06raf('One-norm',p,n,b,ldb,work)*eps ! Compute the factorization of (A, B) ! (A = U1*S*(Q1**T), B = V1*T*(Q1**T)) ! The NAG name equivalent of dggsvp is f08vef CALL dggsvp('U','V','Q',m,p,n,a,lda,b,ldb,tola,tolb,k,l,u,ldu,v,ldv,q, & ldq,iwork,tau,work,info) ! Compute the generalized singular value decomposition of (A, B) ! (A = U*D1*(0 R)*(Q**T), B = V*D2*(0 R)*(Q**T)) ! The NAG name equivalent of dtgsja is f08yef CALL dtgsja('U','V','Q',m,p,n,k,l,a,lda,b,ldb,tola,tolb,alpha,beta,u, & ldu,v,ldv,q,ldq,work,ncycle,info) IF (info==0) THEN ! Print solution irank = k + l WRITE (nout,*) 'Number of infinite generalized singular values (K)' WRITE (nout,99999) k WRITE (nout,*) 'Number of finite generalized singular values (L)' WRITE (nout,99999) l WRITE (nout,*) ' Effective Numerical rank of (A**T B**T)**T (K+L)' WRITE (nout,99999) irank WRITE (nout,*) WRITE (nout,*) 'Finite generalized singular values' WRITE (nout,99998) (alpha(j)/beta(j),j=k+1,irank) WRITE (nout,*) FLUSH (nout) ! ifail: behaviour on error exit ! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft ifail = 0 CALL x04cbf('General',' ',m,m,u,ldu,'1P,E12.4', & 'Orthogonal matrix U','Integer',rlabs,'Integer',clabs,80,0,ifail) WRITE (nout,*) FLUSH (nout) CALL x04cbf('General',' ',p,p,v,ldv,'1P,E12.4', & 'Orthogonal matrix V','Integer',rlabs,'Integer',clabs,80,0,ifail) WRITE (nout,*) FLUSH (nout) CALL x04cbf('General',' ',n,n,q,ldq,'1P,E12.4', & 'Orthogonal matrix Q','Integer',rlabs,'Integer',clabs,80,0,ifail) WRITE (nout,*) FLUSH (nout) CALL x04cbf('Upper triangular','Non-unit',irank,irank, & a(1,n-irank+1),lda,'1P,E12.4', & 'Non singular upper triangular matrix R','Integer',rlabs, & 'Integer',clabs,80,0,ifail) WRITE (nout,*) WRITE (nout,*) 'Number of cycles of the Kogbetliantz method' WRITE (nout,99999) ncycle ELSE WRITE (nout,99997) 'Failure in DTGSJA. INFO =', info END IF 99999 FORMAT (1X,I5) 99998 FORMAT (3X,8(1P,E12.4)) 99997 FORMAT (1X,A,I4) END PROGRAM f08yefe