Fortran Trapezoidal rule
- Some trapezium rule is a method of estimating the area under a curve.
- We have known that the area under a curve is given by integration, so the trapezium rule gives a method of estimating integrals.
- That is useful if we come across integrals that we don’t call whence to evaluate.
Q. Write a Program using the Trapezoidal rule to Calculate the area under a curve…?
PROGRAM TRULY
C
C PROGRAM TO DEMONSTRATE THE APPLICATION OF THE TRAPEZOIDAL RULE
C
C THIS PROGRAM NUMERICALLY INTEGRATES GIVEN EXPRESSION WITHIN
C SPECIFIED LIMITS OF INTEGRATION
C AS INTEGRAL OF A FUNCTION IS EQUAL TO THE AREA UNDER THE CURVE
C WE CAN ALSO USE THE PROGRAM TO CALCULATE THE AREA UNDER A CURVE
C
F(X)=3.12*X**3+1.54*X**2-6.23
C
WRITE(*,*)'LIMITS OF INTEGRATION(A,B)'
READ(*,*)A,B
WRITE(*,*)'NUMBER OF STRIPES'
READ(*,*)NS
C STRIP SIZE
H=(B-A)/NS
AREA=F(A)+F(B)
DO 100 X=A+H,B-H,H
AREA=AREA+2.0*F(X)
100 CONTINUE
AREA=AREA*H/2.0
WRITE(*,*)'AREA UNDER THE CURVE=',AREA
STOP
END
#OUTPUT
LIMIT OF INTEGRATION (A, B)
0 6
NUMBER OF STRIPS
6
AREA UNDER THE CURVE = 159.00000