PROGRAM trap1
!
! Author: Br. David Carlson
!
! Date: January 1, 2000
!
! Revised: April 22, 2004; April 18, 2016
!
! This program finds the approximate value of the integral of ln(x+1) from 1/4 to 3/4.
! The trapezoidal rule is used.
IMPLICIT NONE
INTEGER, PARAMETER::num = 100 ! Number of strips of area to sum up.
REAL::a, b, pi, delta, sum, area, x
INTEGER::k
! Function used:
REAL::f
WRITE (*, *) 'Program to integrate ln(x+1) from 1/4 to 3/4.'
a = 0.25
b = 0.75
delta = (b - a) / num
x = a + delta ! Note the a.
sum = (f(a) + f(b)) / 2.0
DO k = 1, num - 1
sum = sum + f(x)
x = x + delta
END DO
area = delta * sum
WRITE (*, 100) area
100 FORMAT (1X, 'The trapezoidal rule gives an integral value of: ', E17.7)
END PROGRAM
! Given: x a real value
! Task: Compute f(x) and return it.
! Return: Computed value in function name.
REAL FUNCTION f(x)
IMPLICIT NONE
REAL, INTENT(IN)::x
f = LOG(x + 1)
END FUNCTION