MODULE e04cbfe_data ! Global data for E04CBF Example Program ! Mark 22 Release. NAG Copyright 2009. ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nout = 6 ! .. Local Scalars .. LOGICAL :: monitoring END MODULE e04cbfe_data MODULE e04cbfe_callbacks ! User-supplied callbacks for e04cbfe ! .. Use Statements .. USE nag_precisions, ONLY : wp ! .. Implicit None Statement .. IMPLICIT NONE CONTAINS SUBROUTINE funct(n,xc,fc,iuser,ruser) ! .. Use Statements .. USE nag_precisions, ONLY : wp ! .. Implicit None Statement .. IMPLICIT NONE ! .. Scalar Arguments .. REAL (kind=wp), INTENT (OUT) :: fc INTEGER, INTENT (IN) :: n ! .. Array Arguments .. REAL (kind=wp), INTENT (INOUT) :: ruser(*) REAL (kind=wp), INTENT (IN) :: xc(n) INTEGER, INTENT (INOUT) :: iuser(*) ! .. Intrinsic Functions .. INTRINSIC exp ! .. Executable Statements .. fc = exp(xc(1))*(4.0E0_wp*xc(1)*(xc(1)+xc(2))+2.0E0_wp*xc(2)*(xc(2)+ & 1.0E0_wp)+1.0E0_wp) RETURN END SUBROUTINE funct SUBROUTINE monit(fmin,fmax,sim,n,ncall,serror,vratio,iuser,ruser) ! .. Use Statements .. USE nag_precisions, ONLY : wp USE e04cbfe_data, ONLY : monitoring, nout ! .. Implicit None Statement .. IMPLICIT NONE ! .. Scalar Arguments .. REAL (kind=wp), INTENT (IN) :: fmax, fmin, serror, vratio INTEGER, INTENT (IN) :: n, ncall ! .. Array Arguments .. REAL (kind=wp), INTENT (INOUT) :: ruser(*) REAL (kind=wp), INTENT (IN) :: sim(n+1,n) INTEGER, INTENT (INOUT) :: iuser(*) ! .. Executable Statements .. IF (monitoring) THEN WRITE (nout,*) WRITE (nout,99999) ncall WRITE (nout,99998) fmin WRITE (nout,99997) WRITE (nout,99996) sim(1:(n+1),1:n) WRITE (nout,99995) serror WRITE (nout,99994) vratio END IF RETURN 99999 FORMAT (1X,'There have been',I5,' function calls') 99998 FORMAT (1X,'The smallest function value is',F10.4) 99997 FORMAT (1X,'The simplex is') 99996 FORMAT (1X,2F10.4) 99995 FORMAT (1X,'The standard deviation in function values at the ', & 'vertices of the simplex is',F10.4) 99994 FORMAT (1X,'The linearized volume ratio of the current simplex', & ' to the starting one is',F10.4) END SUBROUTINE monit END MODULE e04cbfe_callbacks PROGRAM e04cbfe ! E04CBF Example Program Text ! .. Use Statements .. USE nag_f77_x_chapter, ONLY : x02ajf USE nag_f77_e_chapter, ONLY : e04cbf USE nag_precisions, ONLY : wp USE e04cbfe_callbacks, ONLY : funct, monit USE e04cbfe_data, ONLY : monitoring, nout ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: n = 2 ! .. Local Scalars .. REAL (kind=wp) :: f, tolf, tolx INTEGER :: ifail, maxcal ! .. Local Arrays .. REAL (kind=wp) :: ruser(1), x(n) INTEGER :: iuser(1) ! .. Intrinsic Functions .. INTRINSIC sqrt ! .. Executable Statements .. WRITE (nout,*) 'E04CBF Example Program Results' ! Set MONITORING to .TRUE. to obtain monitoring information monitoring = .FALSE. x(1:n) = (/ -1.0E0_wp, 1.0E0_wp/) tolf = sqrt(x02ajf()) tolx = sqrt(tolf) maxcal = 100 ifail = 0 CALL e04cbf(n,x,f,tolf,tolx,funct,monit,maxcal,iuser,ruser,ifail) WRITE (nout,*) WRITE (nout,99999) f WRITE (nout,99998) x(1:n) 99999 FORMAT (1X,'The final function value is',F12.4) 99998 FORMAT (1X,'at the point',2F12.4) END PROGRAM e04cbfe