! E04BBA Example Program Text ! Mark 23 Release. NAG Copyright 2011. MODULE e04bbae_mod ! E04BBA 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,iuser,ruser) ! 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 ! .. Array Arguments .. REAL (KIND=nag_wp), INTENT (INOUT) :: ruser(*) INTEGER, INTENT (INOUT) :: iuser(*) ! .. Intrinsic Functions .. INTRINSIC cos, sin ! .. Executable Statements .. fc = sin(xc)/xc gc = (cos(xc)-fc)/xc RETURN END SUBROUTINE funct END MODULE e04bbae_mod PROGRAM e04bbae ! E04BBA Example Main Program ! .. Use Statements .. USE nag_library, ONLY : e04bba, nag_wp USE e04bbae_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 ! .. Local Arrays .. REAL (KIND=nag_wp) :: ruser(1) INTEGER :: iuser(1) ! .. Executable Statements .. WRITE (nout,*) 'E04BBA Example Program Results' ! E1 and E2 are set to zero so that E04BBA 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 e04bba(funct,e1,e2,a,b,maxcal,x,f,g,iuser,ruser,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 e04bbae