I am trying to write a procedure which takes in a predefined function procedure and performs the gaussian quadrature integration over some domain. I would like to integrate not only individual functions (say f(x)) but also products of 2 and 3 functions (f(x)*g(x))
I have successfully written the procedure which performs the Gaussian integration and have tested it to work with predefined function procedures. However, it does not work when I pass as input a product of two procedures. When I pass int = integral(S*phi,E_min,E_max,1)
(see below for the integral procedure) the error that I get is Function ‘s’ requires an argument list
To solve this I attempted to write a procedure which takes in 3 function procedures and outputs the product of them. The way I have done that is the following
real(dp) function prod(func1,func2,func3)
interface
function func1(E,on)
use f90_kind
real(dp),intent(in)::E
logical,intent(in)::on
real(dp)::func1
end function func1
function func2(E,on)
use f90_kind
real(dp),intent(in)::E
logical,intent(in)::on
real(dp)::func2
end function func2
function func3(E,on)
use f90_kind
real(dp),intent(in)::E
logical,intent(in)::on
real(dp)::func3
end function func3
end interface
prod = func1(E,on) * func2(E,on) * func3(E,on)
end function prod
Which results in Type mismatch in argument ‘e’ at (1); passed REAL(4) to REAL(8)
. And this is where I get stuck. How do I make my integration procedure function take in as input any product of two or more predefined function procedures?
Here is the Gaussian integration function procedure
real(dp) function integral(func,a,b,int_pts)
interface
function func(E,on)
use f90_kind
real(dp), intent(in) :: E
logical,intent(in) :: on
real(dp) :: func
end function func
end interface
real(dp),intent(in) :: a,b
integer, intent(in) :: int_pts
integer :: idx1, idx2
real(dp) :: dx,F1,F2,S,I,up_lim,low_lim
logical :: on
real(dp),allocatable,dimension(:) :: point,weight
integer, parameter :: nqp = 7
allocate(point(nqp))
allocate(weight(nqp))
call legendre_set(point,weight)
dx = (b-a)/int_pts
I = 0.0_dp
on = .false.
do idx1 = 1,int_pts
low_lim = a + (idx1-1)*dx
up_lim = a + idx1*dx
F1 = (up_lim - low_lim)/2.0_dp
F2 = (up_lim + low_lim)/2.0_dp
S = 0.0_dp
do idx2 = 1,nqp
S = S + weight(idx2) * func(F1*point(idx2)+F2,on)
!print *,"idx2 is",idx2,"func is",func(F1*point(idx2)+F2,on)
enddo
I = I + S * F1
!print *,"Sum is",S
enddo
integral = I
end function integral
which works fine when I call it with integral(S,E_min,E_max,1)
, where S is one such predefined function.
Thanks