Program g02anfe
! G02ANF Example Program Text
! Mark 28.3 Release. NAG Copyright 2022.
! .. Use Statements ..
Use nag_library, Only: g02anf, nag_wp, x04caf
! .. Implicit None Statement ..
Implicit None
! .. Parameters ..
Integer, Parameter :: nin = 5, nout = 6
! .. Local Scalars ..
Real (Kind=nag_wp) :: alpha, eigmin, eigtol, errtol, norm
Integer :: i, ifail, iter, k, ldg, ldx, n
! .. Local Arrays ..
Real (Kind=nag_wp), Allocatable :: g(:,:), x(:,:)
! .. Executable Statements ..
Write (nout,*) 'G02ANF Example Program Results'
Write (nout,*)
Flush (nout)
! Skip heading in data file
Read (nin,*)
! Read in the problem sizes
Read (nin,*) n, k
ldg = n
ldx = n
Allocate (g(ldg,n),x(ldx,n))
! Read in the matrix G
Read (nin,*)(g(i,1:n),i=1,n)
! Use the defaults for EIGTOL and ERRTOL
eigtol = -1.E0_nag_wp
errtol = -1.E0_nag_wp
! Calculate nearest correlation matrix
ifail = 0
Call g02anf(g,ldg,n,k,errtol,eigtol,x,ldx,alpha,iter,eigmin,norm,ifail)
ifail = 0
! Display the symmetrised input matrix
Call x04caf('General',' ',n,n,g,ldg,'Symmetrised Input Matrix G',ifail)
Write (nout,*)
Flush (nout)
! Display results
ifail = 0
Call x04caf('General',' ',n,n,x,ldx, &
'Nearest Perturbed Correlation Matrix X',ifail)
Write (nout,*)
Write (nout,99999) 'K: ', k
Write (nout,*)
Write (nout,99999) 'Number of iterations taken:', iter
Write (nout,*)
Write (nout,99998) 'ALPHA: ', alpha
Write (nout,*)
Write (nout,99998) 'Norm value: ', norm
Write (nout,*)
Write (nout,99998) 'Smallest eigenvalue of A:', eigmin
99999 Format (1X,A,I9)
99998 Format (1X,A,F16.4)
End Program g02anfe