Simpson's rule

For Simpson's voting rule, see Minimax Condorcet. For Simpson's rules used in Ship Stability, see Simpson's rules.
Simpson's rule can be derived by approximating the integrand f (x) (in blue) by the quadratic interpolant P(x) (in red).
An animation showing how Simpson's rule approximation improves with more strips.

In numerical analysis, Simpson's rule is a method for numerical integration, the numerical approximation of definite integrals. Specifically, it is the following approximation:

for points that are equally spaced. For unequally spaced points, please see Cartwright.[1]

Simpson's rule also corresponds to the three-point Newton-Cotes quadrature rule.

The method is credited to the mathematician Thomas Simpson (1710–1761) of Leicestershire, England. Kepler used similar formulas over 100 years prior. For this reason the method is sometimes called Kepler's rule, or Keplersche Fassregel in German.

Derivation

Simpson's rule can be derived in various ways.

Quadratic interpolation

One derivation replaces the integrand by the quadratic polynomial (i.e. parabola) which takes the same values as at the end points a and b and the midpoint m = (a + b) / 2. One can use Lagrange polynomial interpolation to find an expression for this polynomial,

An easy (albeit tedious) integration by substitution shows that

[2]

This calculation can be carried out more easily if one first observes that (by scaling) there is no loss of generality in assuming that and .

Averaging the midpoint and the trapezoidal rules

Another derivation constructs Simpson's rule from two simpler approximations: the midpoint rule

and the trapezoidal rule

The errors in these approximations are

respectively, where denotes a term asymptotically proportional to . The two terms are not equal; see Big O notation for more details. It follows from the above formulas for the errors of the midpoint and trapezoidal rule that the leading error term vanishes if we take the weighted average

This weighted average is exactly Simpson's rule.

Using another approximation (for example, the trapezoidal rule with twice as many points), it is possible to take a suitable weighted average and eliminate another error term. This is Romberg's method.

Undetermined coefficients

The third derivation starts from the ansatz

The coefficients α, β and γ can be fixed by requiring that this approximation be exact for all quadratic polynomials. This yields Simpson's rule.

Error

The error in approximating an integral by Simpson's rule is

where is some number between and .[3]

The error is asymptotically proportional to . However, the above derivations suggest an error proportional to . Simpson's rule gains an extra order because the points at which the integrand is evaluated are distributed symmetrically in the interval [a, b].

Since the error term is proportional to the fourth derivative of f at , this shows that Simpson's rule provides exact results for any polynomial f of degree three or less, since the fourth derivative of such a polynomial is zero at all points.

Composite Simpson's rule

If the interval of integration is in some sense "small", then Simpson's rule will provide an adequate approximation to the exact integral. By small, what we really mean is that the function being integrated is relatively smooth over the interval . For such a function, a smooth quadratic interpolant like the one used in Simpson's rule will give good results.

However, it is often the case that the function we are trying to integrate is not smooth over the interval. Typically, this means that either the function is highly oscillatory, or it lacks derivatives at certain points. In these cases, Simpson's rule may give very poor results. One common way of handling this problem is by breaking up the interval into a number of small subintervals. Simpson's rule is then applied to each subinterval, with the results being summed to produce an approximation for the integral over the entire interval. This sort of approach is termed the composite Simpson's rule.

Suppose that the interval is split up into subintervals, with an even number. Then, the composite Simpson's rule is given by

where for with ; in particular, and . This composite rule with corresponds with the regular Simpson's Rule of the preceding section. The above formula can also be written as

The error committed by the composite Simpson's rule is bounded (in absolute value) by

where is the "step length", given by [4]

This formulation splits the interval in subintervals of equal length. In practice, it is often advantageous to use subintervals of different lengths, and concentrate the efforts on the places where the integrand is less well-behaved. This leads to the adaptive Simpson's method.

Alternative extended Simpson's rule

This is another formulation of a composite Simpson's rule: instead of applying Simpson's rule to disjoint segments of the integral to be approximated, Simpson's rule is applied to overlapping segments, yielding:[5]

The formula above is obtained by combining the original composite Simpson's rule with the one consisting in using Simpson's 3/8 rule in the extreme subintervals and the standard 3-point rule in the remaining subintervals. The result is then obtained by taking the mean of the two formulas.

Simpson's 3/8 rule

Simpson's 3/8 rule is another method for numerical integration proposed by Thomas Simpson. It is based upon a cubic interpolation rather than a quadratic interpolation. Simpson's 3/8 rule is as follows:

where b - a = 3h. The error of this method is:

where is some number between and . Thus, the 3/8 rule is about twice as accurate as the standard method, but it uses one more function value. A composite 3/8 rule also exists, similarly as above.[6]

A further generalization of this concept for interpolation with arbitrary degree polynomials are the Newton–Cotes formulas.

Simpson's 3/8 rule (for n intervals)

Defining,

we have

Note, we can only use this if is a multiple of three.

A simplified version of Simpson's rules is used in naval architecture. The 3/8th rule is also called Simpson's Second Rule.

Sample implementation

An implementation of the composite Simpson's rule in Python:

#!/usr/bin/env python3
from __future__ import division  # Python 2 compatibility

def simpson(f, a, b, n):
    """Approximates the definite integral of f from a to b by the
    composite Simpson's rule, using n subintervals (with n even)"""

    if n % 2:
        raise ValueError("n must be even (received n=%d)" % n)

    h = (b - a) / n
    s = f(a) + f(b)

    for i in range(1, n, 2):
        s += 4 * f(a + i * h)
    for i in range(2, n-1, 2):
        s += 2 * f(a + i * h)

    return s * h / 3

# Demonstrate that the method is exact for polynomials up to 3rd order
print(simpson(lambda x:x**3, 0.0, 10.0, 2))       # 2500.0
print(simpson(lambda x:x**3, 0.0, 10.0, 100000))  # 2500.0

print(simpson(lambda x:x**4, 0.0, 10.0, 2))       # 20833.3333333
print(simpson(lambda x:x**4, 0.0, 10.0, 100000))  # 20000.0

Note that this function is available in SciPy as scipy.integrate.simps.

See also

Notes

  1. Cartwright, Kenneth V. (2016). "Simpson's Rule Integration with MS Excel and Irregularly-spaced Data" (PDF). Journal of Mathematical Science and Mathematics Education. 11 (2): 34–42.
  2. Atkinson, p. 256; Süli and Mayers, §7.2
  3. Atkinson, equation (5.1.15); Süli and Mayers, Theorem 7.2
  4. Atkinson, pp. 257+258; Süli and Mayers, §7.5
  5. Press (1989), p. 122
  6. Matthews (2004)

References

External links

This article incorporates material from Code for Simpson's rule on PlanetMath, which is licensed under the Creative Commons Attribution/Share-Alike License.

This article is issued from Wikipedia - version of the 10/27/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.