FORTRAN 90 Lecturer : Rafel Hekmat Hameed University of Babylon Subject : Fortran 90 College of Engineering Year : Second B.Sc. Mechanical Engineering Dep. Numerical Integration Numerical integration is the study of how the numerical value of an integral can be found. Also called quadrature, which refers to finding a square whose area is the same as the area under a curve, it is one of the classical topics of numerical analysis. Simpson’s 1/3 Rule Simpson’s rule is a numerical method that approximates the value of a definite integral by using quadratic polynomials. Let’s first derive a formula for the area under a parabola of equation y = ax2 + bx + c passing through the three points: (−h, y0), (0, y1), (h, y2). ୦ ൌ න ሺ ଶ ሻ ି୦ య మ ଷ ଶ ୦ ൌ ሺ ୶ ୶ ሻቚ ϭ ି୦ ൌ ʹଷ ʹ ͵ ൌ ሺʹଶ ሻ ͵ Since the points (−h, y0), (0, y1), (h, y2) are on the parabola, they satisfy y = ax2 + bx + c. Therefore, ൌ ଶ െ ଵ ൌ ଶ ൌ ଶ Observe that y0 + 4y1 + y2 = (ah2 − bh + c) + 4c + (ah2 + bh + c) = 2 ah2 + 6 c. Therefore, the area under the parabola is ο ሺ Ͷଵ ଶ ሻ ൌ ሺ Ͷଵ ଶ ሻ ൌ ͵ ͵ We consider the definite integral ୠ න ሺሻ ୟ We assume that f(x) is continuous on [a, b] and we divide [a, b] into an even number n of subintervals of equal length െ ο ൌ Using the n+1 points x0 = a , x1 = a + x , x2 = a + 2x , . . . , xn = a + nx = b. Compute the value of f(x) at these points. y0 = f(x0), y1 = f(x1), y2 = f(x2), . . . , yn = f(xn). Ϯ We can estimate the integral by adding the areas under the parabolic arcs through three successive points. ୠ න ሺሻ ൎ ୟ ο ο ο ሺ Ͷଵ ଶ ሻ ሺଵ Ͷଶ ଷ ሻ ڮ ሺ୬ିଶ Ͷ୬ିଵ ୬ ሻ ͵ ͵ ͵ By simplifying, we obtain Simpson’s rule formula. ୠ න ሺሻ ൎ ୟ ο ሺ Ͷଵ ʹଶ Ͷଷ ʹݕସ ڮ Ͷݕିଵ ݕ ሻ ͵ ସ Example. Use Simpson’s rule with n = 6 to estimate ଵ ξͳ ݔଷ For n = 6, we have x = (4−1)/ 6 = 0.5. We compute the values of y0, y1, y2, . . . , y6. x 1 1.5 2 2.5 3 3.5 4 ࢟ ൌ ඥ ࢞ ξʹ ξͶǤ͵ͷ ͵ ξͳǤʹͷ ξʹͺ ξͶ͵Ǥͺͷ ξͷ Therefore, ସ Ǥͷ ሺξʹ ͶξͶǤ͵ͷ ʹሺ͵ሻ ͶξͳǤʹͷ ʹξʹͺ ͶξͶ͵Ǥͺͷ ξͷ ͵ ൎ ͳʹǤͺͳ න ඥͳ ݔଷ ݀ ݔൎ ଵ program simpson_rule implicit none integer:: i ; real::a , b , n , dx , sum , f , x f(x)=sqrt (1+x**3 read(*,*) a,b,n ; dx=(b-a)/n sum=f(a)+f(b) do i=1,n-1 ; x=a+(i*dx) If (i/2*2.ne.i) then sum=sum+4*f(x) else ; endif ; sum=sum+2*f(x) enddo sum=sum*dx/3.0 print*, "for n =",n ," ", "Integral =", sum end ϯ