Trapezodial Rule | FORTRAN 95

Fortran Programming - Bottom Science

Fortran Code

PROGRAM trapezoidal
IMPLICIT NONE
INTEGER::i,n
REAL::x0,xn,h,s,f

PRINT *,'================'
PRINT *,'Program for TRAPEZOIDAL RULE [www.BottomScience.com]'
PRINT *,'================'

PRINT *,'Enter value of x0?'
READ(*,*)x0

PRINT *,'Enter value of xn?'
READ(*,*)xn

PRINT *,'Number of values?'
READ(*,*)n

h=(xn-x0)/n
s=f(x0)+f(xn)

DO i=1,n-1
  s=s+(2*f(x0+(i*h)))
END DO
s=(h*s)/2

PRINT *,"Value of integral is",s

END PROGRAM

REAL function f(x1)
REAL::x1
  f=0.2+(25*x1)-200*(x1**2)+675*(x1**3)-900*(x1**4)+400*(x1**5)
return
end function

Leave a Reply

Your email address will not be published.