Math-305, Numerical Methods & Matrices
Simpson's - 1/3 Rule to Approximate a Proper Integral

Dr. K. G. TeBeest

      
      
      *****************************************************************

      SIMPSON's - 1/3 RULE ALGORITHM (pseudocode)

      To approximate the integral of a function f(x) on interval [a,b]
      using n subintervals.

      INPUT:

         f(x)  -  the function to be integrated
          a    -  left endpoint of interval
          b    -  right endpoint of interval
          n    -  the number of subintervals to divide interval [a,b]
                  NOTE:  n must be divisible by 2

      *****************************************************************

      1.  enter:  f(x), a, b, n

      2.  set  SECTIONS = n/2
          set  h = (b-a) / n
          set  APPROX = 0.0
          
      3.  Repeat steps (a-d) for i from 1 to SECTIONS:

          a.  set  x0 = a + 2 * (i-1) * h
          b.  set  x1 = x0 + h
          c.  set  x2 = x1 + h
          d.  set  APPROX = APPROX + f(x0) + 4 * f(x1) + f(x2)

      4.  set  INTEGRAL = APPROX * h/3

      5.  print INTEGRAL



      COMMENT:  Make sure you print the result in floating point (decimal) form;
                you may need to use the Maple "evalf" command.



Return