In numerical analysis, Simpson's rule (named after Thomas Simpson) is a way to get an approximation of an integral:
Simpson's rule then follows by an easy (albeit tedious) calculation:
The error in approximating an integral by Simpson's rule is
with and some number between and
We see that Simpson's rule provides an adequate approximation if the interval of integration is small, which does not happen most of the time. The obvious solution is to split the interval of integration in small subintervals, apply Simpson's rule on each subinterval, and add up the results. In this way one obtains the composite Simpson's rule
where is the number of subintervals in which one splits with an even number, is the length of each subinterval, and for , in particular, and Alternatively, the above can be written as:
The maximum error associated with the composite Simpson's rule can be found using the following formula:
where is the "step length", given by
See also: Newton-Cotes formulas.
Here is an implementation of Simpson's rule in Python.
def simpson_rule(f, a, b): "Approximate the definite integral of f from a to b by Simpson's rule." c = (a + b) / 2.0 h3 = abs(b - a) / 6.0 return h3 * (f(a) + 4.0*f(c) + f(b)) from math import sin print simpson_rule(sin, 0, 1)
- Calculates integral of sin(x) from 0 to 1
Integrating sin x from 0 to 1 with this code gives 0.4598622... whereas the true value is 1 − cos 1 = 0.45969769413... .
Simpsonsche Formel | Regla de Simpson | Méthode de Simpson | Simpsonsreglan | Simpsono taisyklė | シンプソンの公式 | Metoda Simpsona | Fórmula de Simpson | Симпсоново правило
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Simpson's rule".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world