! E04ABF Example Program Text ! Mark 23 Release. NAG Copyright 2011. MODULE e04abfe_mod ! E04ABF 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) ! Routine to evaluate F(x) at any point in (A, B) ! .. Implicit None Statement .. IMPLICIT NONE ! .. Scalar Arguments .. REAL (KIND=nag_wp), INTENT (OUT) :: fc REAL (KIND=nag_wp), INTENT (IN) :: xc ! .. Intrinsic Functions .. INTRINSIC sin ! .. Executable Statements .. fc = sin(xc)/xc RETURN END SUBROUTINE funct END MODULE e04abfe_mod PROGRAM e04abfe ! E04ABF Example Main Program ! .. Use Statements .. USE nag_library, ONLY : e04abf, nag_wp USE e04abfe_mod, ONLY : funct, nout ! .. Implicit None Statement .. IMPLICIT NONE ! .. Local Scalars .. REAL (KIND=nag_wp) :: a, b, e1, e2, f, x INTEGER :: ifail, maxcal ! .. Executable Statements .. WRITE (nout,*) 'E04ABF Example Program Results' ! E1 and E2 are set to zero so that E04ABF 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 e04abf(funct,e1,e2,a,b,maxcal,x,f,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) maxcal, 'function evaluations were required' END SELECT 99999 FORMAT (1X,A,F11.8,A,F11.8) 99998 FORMAT (1X,A,F7.4) 99997 FORMAT (1X,I2,1X,A) END PROGRAM e04abfe