Boole's rule

From HandWiki
Short description: Method of numerical integration

In mathematics, Boole's rule, named after George Boole, is a method of numerical integration.

Formula

Simple Boole's Rule

It approximates an integral: abf(x)dx by using the values of f at five equally spaced points:[1] x0=ax1=x0+hx2=x0+2hx3=x0+3hx4=x0+4h=b

It is expressed thus in Abramowitz and Stegun:[2] x0x4f(x)dx=2h45[7f(x0)+32f(x1)+12f(x2)+32f(x3)+7f(x4)]+error term where the error term is 8f(6)(ξ)h7945 for some number ξ between x0 and x4 where 945 = 1 × 3 × 5 × 7 × 9.

It is often known as Bode's rule, due to a typographical error that propagated from Abramowitz and Stegun.[3]

The following constitutes a very simple implementation of the method in Common Lisp which ignores the error term:

(defun integrate-booles-rule (f x1 x5)
  "Calculates the Boole's rule numerical integral of the function F in
   the closed interval extending from inclusive X1 to inclusive X5
   without error term inclusion."
  (declare (type (function (real) real) f))
  (declare (type real                   x1 x5))
  (let ((h (/ (- x5 x1) 4)))
    (declare (type real h))
    (let* ((x2 (+ x1 h))
           (x3 (+ x2 h))
           (x4 (+ x3 h)))
      (declare (type real x2 x3 x4))
      (* (/ (* 2 h) 45)
         (+ (*  7 (funcall f x1))
            (* 32 (funcall f x2))
            (* 12 (funcall f x3))
            (* 32 (funcall f x4))
            (*  7 (funcall f x5)))))))

Composite Boole's Rule

In cases where the integration is permitted to extend over equidistant sections of the interval [a,b], the composite Boole's rule might be applied. Given N divisions, the integrated value amounts to:[4]

x0xNf(x)dx=2h45(7(f(x0)+f(xN))+32(i{1,3,5,,N1}f(xi))+12(i{2,6,10,,N2}f(xi))+14(i{4,8,12,,N4}f(xi)))+error term

where the error term is similar to above. The following Common Lisp code implements the aforementioned formula:

(defun integrate-composite-booles-rule (f a b n)
  "Calculates the composite Boole's rule numerical integral of the
   function F in the closed interval extending from inclusive A to
   inclusive B across N subintervals."
  (declare (type (function (real) real) f))
  (declare (type real                   a b))
  (declare (type (integer 1 *)          n))
  (let ((h (/ (- b a) n)))
    (declare (type real h))
    (flet ((f[i] (i)
            (declare (type (integer 0 *) i))
            (let ((xi (+ a (* i h))))
              (declare (type real xi))
              (the real (funcall f xi)))))
      (* (/ (* 2 h) 45)
         (+ (*  7 (+ (f[i] 0) (f[i] n)))
            (* 32 (loop for i from 1 to (- n 1) by 2 sum (f[i] i)))
            (* 12 (loop for i from 2 to (- n 2) by 4 sum (f[i] i)))
            (* 14 (loop for i from 4 to (- n 4) by 4 sum (f[i] i))))))))

See also

Notes

References