* G02AAF Example Program Text * Mark 22 Release. NAG Copyright 2008. * .. Parameters .. INTEGER NMAX, LDG, LDX, NOUT PARAMETER (NMAX=4,LDG=5,LDX=NMAX,NOUT=6) * .. Local Scalars .. DOUBLE PRECISION ERRTOL, NRMGRD INTEGER FEVAL, I, IFAIL, ITER, J, MAXIT, MAXITS, N * .. Local Arrays .. DOUBLE PRECISION G(LDG,NMAX), X(LDX,NMAX) * .. External Subroutines .. EXTERNAL G02AAF * .. Executable Statements .. WRITE (NOUT,*) 'G02AAF Example Program Results' WRITE (NOUT,*) * * Set up matrix G N = 4 DO 40 J = 1, N DO 20 I = 1, N G(I,J) = 0.0 20 CONTINUE G(J,J) = 2.0D0 40 CONTINUE DO 60 J = 2, N G(J-1,J) = -1.0D0 G(J,J-1) = -1.0D0 60 CONTINUE * * Set up method parameters ERRTOL = 1.0D-7 MAXITS = 200 MAXIT = 10 * IFAIL = 1 CALL G02AAF(G,LDG,N,ERRTOL,MAXITS,MAXIT,X,LDX,ITER,FEVAL,NRMGRD, + IFAIL) * IF (IFAIL.EQ.0) THEN WRITE (NOUT,*) ' Nearest Correlation Matrix' WRITE (NOUT,99999) ((X(I,J),J=1,NMAX),I=1,NMAX) WRITE (NOUT,*) WRITE (NOUT,99998) ' Number of Newton steps taken:', ITER WRITE (NOUT,99997) ' Number of function evaluations:', FEVAL IF (NRMGRD.GT.ERRTOL) THEN WRITE (NOUT,99996) ' Norm of gradient of last Newton step:', + NRMGRD END IF ELSE WRITE (NOUT,99995) IFAIL END IF WRITE (NOUT,*) * 99999 FORMAT (2X,4F11.5) 99998 FORMAT (A,I11) 99997 FORMAT (A,I9) 99996 FORMAT (A,E11.3) 99995 FORMAT (' ** G02AAF returned with IFAIL = ',I5) END