Jump to content

Simpson's rule

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Gregie156 (talk | contribs) at 12:17, 29 January 2010 (cleaned up the matlab code a bit.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Simpson's rule can be derived by approximating the integrand f (x) (in blue) by the quadratic interpolant P (x) (in red).

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

.

The method is credited to the mathematician Thomas Simpson (1710–1761) of Leicestershire, England.

Derivation

Simpson's rule can be derived in various ways.

Quadratic interpolation

One derivation replaces the integrand by the quadratic polynomial 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) calculation shows that

[1]

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. It follows 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 .[2]

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].

Note that Simpson's rule provides exact results for any polynomial of degree three or less, since the error term involves the fourth derivative of f.

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 in subintervals, with an even number. Then, the composite Simpson's rule is given by

where for with ; in particular, and . 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 [3]

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:[4]

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:

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.[5]

MATLAB implementation

Simpson's rule can be implemented in MATLAB as follows:

function [I]=simpson(f,a,b,J,N)
%does a simpson integration of the function f.
%f is the function to be integrated. 
%a,b are the indexes of the segment to be integrated
%J is the scale of the index (the jacobian). N is the number of subsections.

	h=(b-a)/N;  %h is the length of each segment
	n=0:N-1;	
	P=f(a+round(n*h))+4*f(a+round(h*(n+0.5)))+f(a+round(h*(n+1)));
	I=sum(P)*h*J/6;
end

Python implementation

Here is an implementation of the Composite Simpson's rule in Python.

def simpson(f, a, b, N=100):
    "Approximate the definite integral of f from a to b, using Composite Simpson's rule"
    h = float(b-a)/N # this is factored out of the loop just for efficiency
    return  h/3 * ( f(a) + sum(2**(k%2+1) * f(a + h*k) for k in range(1,N)) + f(b) )

See also

Notes

  1. ^ Atkinson, p. 256; Süli and Mayers, §7.2
  2. ^ Atkinson, equation (5.1.15); Süli and Mayers, Theorem 7.2
  3. ^ Atkinson, pp. 257+258; Süli and Mayers, §7.5
  4. ^ Press (1989), p. 122
  5. ^ Matthews (2004)

References

  • Atkinson, Kendall A. (1989). An Introduction to Numerical Analysis (2nd edition ed.). John Wiley & Sons. ISBN 0-471-50023-2. {{cite book}}: |edition= has extra text (help)
  • Burden, Richard L. and Faires, J. Douglas (2000). Numerical Analysis (7th edition ed.). Brooks/Cole. ISBN 0-534-38216-9. {{cite book}}: |edition= has extra text (help)CS1 maint: multiple names: authors list (link)
  • Matthews, John H. (2004). "Simpson's 3/8 Rule for Numerical Integration". Numerical Analysis - Numerical Methods Project. California State University, Fullerton. Retrieved 11 November 2008.
  • Press, William H., Brian P. Flannery, William T. Vetterling, and Saul A. Teukolsky (1989). Numerical Recipes in Pascal: The Art of Scientific Computing. Cambridge University Press. ISBN 0521375169.{{cite book}}: CS1 maint: multiple names: authors list (link)
  • Süli, Endre and Mayers, David (2003). An Introduction to Numerical Analysis. Cambridge University Press. ISBN 0-521-81026-4 (hardback), ISBN 0-521-00794-1 (paperback). {{cite book}}: Check |isbn= value: invalid character (help)CS1 maint: multiple names: authors list (link)
  • Kaw, Autar; Kalu, Egwu (2008), Numerical Methods with Applications (1st ed.), [1] {{citation}}: External link in |publisher= (help).

External links


Code for Simpson's rule at PlanetMath.