program main use numinteg implicit none real*8, external :: f, g, h real*8 :: integral, err real*8 :: a, b real*8, parameter :: acc = 0.001, eps = 0.001 ! Integration limit: a = 1d-20 ! Can't use 0 - Algoritm will fail? b = 1.d0 print *, "=======================================" print *, " Integrating f(x) = x^2 from 0 to 1: " ! Run Integration algorithm: numcalls = 0 call integrate(f, a, b, acc, eps, integral, err) ! Write results: print *, " Integral = ", integral print *, " Error = ", err print *, " Number of function calls = ", numcalls print *, "=======================================" print *, " Integrating g(x) = ln(x)/sqrt(x) from 0 to 1: " ! Run Integration algorithm: numcalls = 0 call integrate(g, a, b, acc, eps, integral, err) ! Write results: print *, " Integral = ", integral print *, " Error = ", err print *, " Number of function calls = ", numcalls print *, "=======================================" print *, " Integrating h(x) = 2*sin(x)+4*cos(x) from 0 to pi: " ! Run Integration algorithm: numcalls = 0 call integrate(h, 0.0_8, 3.1415926_8, acc, eps, integral, err) ! Write results: print *, " Integral = ", integral print *, " Error = ", err print *, " Number of function calls = ", numcalls end program main !============================================ ! Functions to be integrated: real*8 function f(x) use numinteg, only : numcalls implicit none real*8, intent(in) :: x f = x**2 numcalls = numcalls + 1 end function real*8 function g(x) use numinteg, only : numcalls implicit none real*8, intent(in) :: x g = log(x)/sqrt(x) numcalls = numcalls + 1 end function real*8 function h(x) use numinteg, only : numcalls implicit none real*8, intent(in) :: x h = 2*sin(x) + 4*cos(x) numcalls = numcalls + 1 end function