! D01ARF Example Program Text ! Mark 23 Release. NAG Copyright 2011. MODULE d01arfe_mod ! D01ARF Example Program Module: ! Parameters and User-defined Routines ! .. Use Statements .. USE nag_library, ONLY : nag_wp ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: maxrul = 0, nout = 6 CONTAINS FUNCTION f1(x) ! .. Implicit None Statement .. IMPLICIT NONE ! .. Function Return Value .. REAL (KIND=nag_wp) :: f1 ! .. Scalar Arguments .. REAL (KIND=nag_wp), INTENT (IN) :: x ! .. Executable Statements .. f1 = 4.0E0_nag_wp/(1.0E0_nag_wp+x*x) RETURN END FUNCTION f1 FUNCTION f2(x) ! .. Implicit None Statement .. IMPLICIT NONE ! .. Function Return Value .. REAL (KIND=nag_wp) :: f2 ! .. Scalar Arguments .. REAL (KIND=nag_wp), INTENT (IN) :: x ! .. Executable Statements .. f2 = x**0.125E0_nag_wp RETURN END FUNCTION f2 END MODULE d01arfe_mod PROGRAM d01arfe ! D01ARF Example Main Program ! .. Use Statements .. USE nag_library, ONLY : d01arf, nag_wp USE d01arfe_mod, ONLY : f1, f2, maxrul, nout ! .. Implicit None Statement .. IMPLICIT NONE ! .. Local Scalars .. REAL (KIND=nag_wp) :: a, absacc, acc, ans, b, relacc INTEGER :: ifail, iparm, n ! .. Local Arrays .. REAL (KIND=nag_wp) :: alpha(390) ! .. Executable Statements .. WRITE (nout,*) 'D01ARF Example Program Results' relacc = 0.0E0_nag_wp absacc = 1.0E-5_nag_wp ! Definite integral of F1(x) - no expansion iparm = 0 a = 0.0E0_nag_wp b = 1.0E0_nag_wp WRITE (nout,*) WRITE (nout,*) 'Definite integral of 4/(1+x*x) over (0,1)' ifail = -1 CALL d01arf(a,b,f1,relacc,absacc,maxrul,iparm,acc,ans,n,alpha,ifail) SELECT CASE (ifail) CASE (:-1) GO TO 20 CASE (0,1) WRITE (nout,99999) 'Estimated value of the integral =', ans WRITE (nout,99998) 'Estimated absolute error =', acc WRITE (nout,99997) 'Number of points used =', n END SELECT ! Definite integral of F2(x) - with expansion iparm = 1 a = 1.0E0_nag_wp b = 2.0E0_nag_wp WRITE (nout,*) WRITE (nout,*) 'Definite integral of x**(1/8) over (1,2)' ifail = -1 CALL d01arf(a,b,f2,relacc,absacc,maxrul,iparm,acc,ans,n,alpha,ifail) SELECT CASE (ifail) CASE (:-1) GO TO 20 CASE (0,1) WRITE (nout,99999) 'Estimated value of the integral =', ans WRITE (nout,99998) 'Estimated absolute error =', acc WRITE (nout,99997) 'Number of points used =', n END SELECT ! Indefinite integral of F2(x) iparm = 2 a = 1.2E0_nag_wp b = 1.8E0_nag_wp WRITE (nout,*) WRITE (nout,*) 'Indefinite integral of x**(1/8) over (1.2,1.8)' ifail = 0 CALL d01arf(a,b,f2,relacc,absacc,maxrul,iparm,acc,ans,n,alpha,ifail) WRITE (nout,99999) 'Estimated value of the integral =', ans 20 CONTINUE 99999 FORMAT (1X,A,F9.5) 99998 FORMAT (1X,A,E10.2) 99997 FORMAT (1X,A,I4) END PROGRAM d01arfe