! E04BBF Example Program Text ! Mark 23 Release. NAG Copyright 2011. MODULE e04bbfe_mod ! E04BBF Example Program Module: ! Parameters and User-defined Routines ! .. Use Statements .. USE nag_library, ONLY : nag_wp ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nout = 6 CONTAINS SUBROUTINE funct(xc,fc,gc) ! Routine to evaluate F(x) and dF/dx at any point in (A, B) ! .. Implicit None Statement .. IMPLICIT NONE ! .. Scalar Arguments .. REAL (KIND=nag_wp), INTENT (OUT) :: fc, gc REAL (KIND=nag_wp), INTENT (IN) :: xc ! .. Intrinsic Functions .. INTRINSIC cos, sin ! .. Executable Statements .. fc = sin(xc)/xc gc = (cos(xc)-fc)/xc RETURN END SUBROUTINE funct END MODULE e04bbfe_mod PROGRAM e04bbfe ! E04BBF Example Main Program ! .. Use Statements .. USE nag_library, ONLY : e04bbf, nag_wp USE e04bbfe_mod, ONLY : funct, nout ! .. Implicit None Statement .. IMPLICIT NONE ! .. Local Scalars .. REAL (KIND=nag_wp) :: a, b, e1, e2, f, g, x INTEGER :: ifail, maxcal ! .. Executable Statements .. WRITE (nout,*) 'E04BBF Example Program Results' ! E1 and E2 are set to zero so that E04BBF will reset them to ! their default values e1 = 0.0_nag_wp e2 = 0.0_nag_wp ! The minimum is known to lie in the range (3.5, 5.0) a = 3.5_nag_wp b = 5.0_nag_wp ! Allow 30 calls of FUNCT maxcal = 30 ifail = -1 CALL e04bbf(funct,e1,e2,a,b,maxcal,x,f,g,ifail) SELECT CASE (ifail) CASE (0,2) WRITE (nout,*) WRITE (nout,99999) 'The minimum lies in the interval', a, ' to', b WRITE (nout,99999) 'Its estimated position is', x, ',' WRITE (nout,99998) 'where the function value is ', f WRITE (nout,99997) 'and the gradient is ', g, ' (machine dependent)' WRITE (nout,99996) maxcal, ' calls of FUNCT were required' END SELECT 99999 FORMAT (1X,A,F11.8,A,F11.8) 99998 FORMAT (1X,A,F7.4) 99997 FORMAT (1X,A,1P,E8.1,A) 99996 FORMAT (1X,I2,A) END PROGRAM e04bbfe