!.....Solute one-dimension integration............... program main !a, b are boundary !n is the number to divide the region !dx = (b-a)/(n-1) implicit real (a-h,o-z) implicit integer (i-n) real,external :: integrate a=0. b=3.14159 n=101 write(*,*) integrate(a,b,n,dx) stop end !......................................... function integrate(a,b,n,dx) real:: a,b,dx real,allocatable :: x(:),f(:) integer :: i,j,n real :: integrate real,external :: func dx=(b-a)/(n-1) allocate(x(n),f(n)) x(1) = a f(1) = func(x(1)) do i=2,n x(i) = x(i-1)+dx f(i) = func(x(i)) end do integrate = sum(f)*dx - 0.5*(f(1)+f(n))*dx return end !............................................. function func(x) real :: x real :: func func = sin(x) return end