Program f08ubfe
! F08UBF Example Program Text
! Mark 30.2 Release. NAG Copyright 2024.
! .. Use Statements ..
Use nag_library, Only: dsbgvx, nag_wp, x04caf
! .. Implicit None Statement ..
Implicit None
! .. Parameters ..
Real (Kind=nag_wp), Parameter :: zero = 0.0E+0_nag_wp
Integer, Parameter :: nin = 5, nout = 6
Character (1), Parameter :: uplo = 'U'
! .. Local Scalars ..
Real (Kind=nag_wp) :: abstol, vl, vu
Integer :: i, ifail, il, info, iu, j, ka, kb, &
ldab, ldbb, ldq, ldz, m, n
! .. Local Arrays ..
Real (Kind=nag_wp), Allocatable :: ab(:,:), bb(:,:), q(:,:), w(:), &
work(:), z(:,:)
Integer, Allocatable :: iwork(:), jfail(:)
! .. Intrinsic Procedures ..
Intrinsic :: max, min
! .. Executable Statements ..
Write (nout,*) 'F08UBF Example Program Results'
Write (nout,*)
! Skip heading in data file
Read (nin,*)
Read (nin,*) n, ka, kb
ldab = ka + 1
ldbb = kb + 1
ldq = n
ldz = n
m = n
Allocate (ab(ldab,n),bb(ldbb,n),q(ldq,n),w(n),work(7*n),z(ldz,m), &
iwork(5*n),jfail(n))
! Read the lower and upper bounds of the interval to be searched,
! and read the upper or lower triangular parts of the matrices A
! and B from data file
Read (nin,*) vl, vu
If (uplo=='U') Then
Read (nin,*)((ab(ka+1+i-j,j),j=i,min(n,i+ka)),i=1,n)
Read (nin,*)((bb(kb+1+i-j,j),j=i,min(n,i+kb)),i=1,n)
Else If (uplo=='L') Then
Read (nin,*)((ab(1+i-j,j),j=max(1,i-ka),i),i=1,n)
Read (nin,*)((bb(1+i-j,j),j=max(1,i-kb),i),i=1,n)
End If
! Set the absolute error tolerance for eigenvalues. With abstol
! set to zero, the default value is used instead
abstol = zero
! Solve the generalized symmetric eigenvalue problem
! A*x = lambda*B*x
! The NAG name equivalent of dsbgvx is f08ubf
Call dsbgvx('Vectors','Values in range',uplo,n,ka,kb,ab,ldab,bb,ldbb,q, &
ldq,vl,vu,il,iu,abstol,m,w,z,ldz,work,iwork,jfail,info)
If (info>=0 .And. info<=n) Then
! Print solution
Write (nout,99999) 'Number of eigenvalues found =', m
Write (nout,*)
Write (nout,*) 'Eigenvalues'
Write (nout,99998) w(1:m)
Flush (nout)
! ifail: behaviour on error exit
! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
ifail = 0
Call x04caf('General',' ',n,m,z,ldz,'Selected eigenvectors',ifail)
If (info>0) Then
Write (nout,99999) 'INFO eigenvectors failed to converge, INFO =', &
info
Write (nout,*) 'Indices of eigenvectors that did not converge'
Write (nout,99997) jfail(1:m)
End If
Else If (info>n .And. info<=2*n) Then
i = info - n
Write (nout,99996) 'The leading minor of order ', i, &
' of B is not positive definite'
Write (nout,99999) 'Failure in DSBGVX. INFO =', info
End If
99999 Format (1X,A,I5)
99998 Format (3X,(8F8.4))
99997 Format (3X,(8I8))
99996 Format (1X,A,I4,A)
End Program f08ubfe