c_trapz_ab_func Function

function c_trapz_ab_func(f, a, b, N) result(int)

Arguments

Type IntentOptional Attributes Name
function f(x)
Arguments
Type IntentOptional Attributes Name
real(kind=8) :: x
Return Value complex(kind=8)
real(kind=8), optional :: a
real(kind=8), optional :: b
integer, optional :: N

Return Value complex(kind=8)


Calls

proc~~c_trapz_ab_func~~CallsGraph proc~c_trapz_ab_func c_trapz_ab_func linspace linspace proc~c_trapz_ab_func->linspace

Source Code

function c_trapz_ab_func(f,a,b,N) result(int)
  interface
     function f(x)
       real(8)    :: x
       complex(8) :: f
     end function f
  end interface
  real(8),optional                 :: a,b
  integer,optional                 :: N
  real(8)                          :: dh,a_,b_
  integer                          :: L,i
  real(8),dimension(:),allocatable :: xx
  complex(8)                       :: int
  L  = 100;if(present(N))L =N
  a_ = 0d0;if(present(a))a_=a
  b_ = 1d0;if(present(b))b_=b
  !
  int=0.d0
  allocate(xx(L))
  xx = linspace(a_,b_,L,mesh=dh)
  do i=1,L-1
     int = int+( f(xx(i+1)) + f(xx(i)) )
  enddo
  int = int*dh/2d0
  deallocate(xx)
end function c_trapz_ab_func