Simpson's Rule - Maple Help

Simpson's Rule

 Calling Sequence ApproximateInt(f(x), x = a..b, method = simpson, opts) ApproximateInt(f(x), a..b, method = simpson, opts) ApproximateInt(Int(f(x), x = a..b), method = simpson, opts)

Parameters

 f(x) - algebraic expression in variable 'x' x - name; specify the independent variable a, b - algebraic expressions; specify the interval opts - equation(s) of the form option=value where option is one of boxoptions, functionoptions, iterations, method, outline, output, partition, pointoptions, refinement, showarea, showfunction, showpoints, subpartition, view, or Student plot options; specify output options

Description

 • The ApproximateInt(f(x), x = a..b, method = simpson, opts) command approximates the integral of f(x) from a to b by using Simpson's rule. The first two arguments (function expression and range) can be replaced by a definite integral.
 • If the independent variable can be uniquely determined from the expression, the parameter x need not be included in the calling sequence.
 • Given a partition $P=\left(a={x}_{0},{x}_{1},...,{x}_{N}=b\right)$ of the interval $\left(a,b\right)$, Simpson's rule approximates the integral on each subinterval $\left({x}_{i-1},{x}_{i}\right)$ by integrating the quadratic function that interpolates the three points $\left({x}_{i-1},f\left({x}_{i-1}\right)\right)$, $\left(\frac{{x}_{i-1}}{2}+\frac{{x}_{i}}{2},f\left(\frac{{x}_{i-1}}{2}+\frac{{x}_{i}}{2}\right)\right)$, and $\left({x}_{i},f\left({x}_{i}\right)\right)$.  This value is

$\frac{\left({x}_{i}-{x}_{i-1}\right)\left(f\left({x}_{i-1}\right)+4f\left(\frac{{x}_{i-1}}{2}+\frac{{x}_{i}}{2}\right)+f\left({x}_{i}\right)\right)}{6}$

 • In the case that the widths of the subintervals are equal, the approximation can be written as

$\frac{\left(b-a\right)\left(f\left({x}_{0}\right)+4f\left(\frac{{x}_{0}}{2}+\frac{{x}_{1}}{2}\right)+2f\left({x}_{1}\right)+4f\left(\frac{{x}_{1}}{2}+\frac{{x}_{2}}{2}\right)+2f\left({x}_{2}\right)+\mathrm{...}+f\left({x}_{N}\right)\right)}{6N}$

 Traditionally, Simpson's rule is written as: given N where N is an even integer and given equally spaced points $a={x}_{0},{x}_{1},{x}_{2},...,{x}_{N}=b$, an approximation to the integral ${\int }_{a}^{b}f\left(x\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}ⅆx$ is

$\frac{\left(b-a\right)\left(f\left({x}_{0}\right)+4f\left({x}_{1}\right)+2f\left({x}_{2}\right)+4f\left({x}_{3}\right)+2f\left({x}_{4}\right)+\mathrm{...}+f\left({x}_{N}\right)\right)}{3N}$

 • By default, the interval is divided into $10$ equal-sized subintervals.
 • For the options opts, see the ApproximateInt help page.
 • This rule can be applied interactively, through the ApproximateInt Tutor.

Examples

 > $\mathrm{polynomial}≔{\mathrm{CurveFitting}}_{\mathrm{PolynomialInterpolation}}\left(\left[{x}_{0},\frac{{x}_{0}+{x}_{1}}{2},{x}_{1}\right],\left[f\left(0\right),f\left(\frac{1}{2}\right),f\left(1\right)\right],z\right):$
 > $\mathrm{integrated}≔{∫}_{{x}_{0}}^{{x}_{1}}\mathrm{polynomial}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}ⅆz:$
 > $\mathrm{factor}\left(\mathrm{integrated}\right)$
 ${-}\frac{\left({{x}}_{{0}}{-}{{x}}_{{1}}\right){}\left({f}{}\left({0}\right){+}{f}{}\left({1}\right){+}{4}{}{f}{}\left(\frac{{1}}{{2}}\right)\right)}{{6}}$ (1)
 > $\mathrm{with}\left({\mathrm{Student}}_{\mathrm{Calculus1}}\right):$
 > $\mathrm{ApproximateInt}\left(\mathrm{sin}\left(x\right),x=0..5,\mathrm{method}=\mathrm{simpson}\right)$
 $\frac{{\mathrm{sin}}{}\left(\frac{{17}}{{4}}\right)}{{3}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{9}}{{2}}\right)}{{6}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{19}}{{4}}\right)}{{3}}{+}\frac{{\mathrm{sin}}{}\left({5}\right)}{{12}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{11}}{{4}}\right)}{{3}}{+}\frac{{\mathrm{sin}}{}\left({3}\right)}{{6}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{13}}{{4}}\right)}{{3}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{7}}{{2}}\right)}{{6}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{15}}{{4}}\right)}{{3}}{+}\frac{{\mathrm{sin}}{}\left({4}\right)}{{6}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{3}}{{4}}\right)}{{3}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{5}}{{4}}\right)}{{3}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{3}}{{2}}\right)}{{6}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{7}}{{4}}\right)}{{3}}{+}\frac{{\mathrm{sin}}{}\left({2}\right)}{{6}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{9}}{{4}}\right)}{{3}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{5}}{{2}}\right)}{{6}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{1}}{{4}}\right)}{{3}}{+}\frac{{\mathrm{sin}}{}\left(\frac{{1}}{{2}}\right)}{{6}}{+}\frac{{\mathrm{sin}}{}\left({1}\right)}{{6}}$ (2)
 > $\mathrm{ApproximateInt}\left(x\left(x-2\right)\left(x-3\right),x=0..5,\mathrm{method}=\mathrm{simpson},\mathrm{output}=\mathrm{plot}\right)$
 > $\mathrm{ApproximateInt}\left(\mathrm{tan}\left(x\right)-2x,x=-1..1,\mathrm{method}=\mathrm{simpson},\mathrm{output}=\mathrm{plot},\mathrm{partition}=50\right)$

To play the following animation in this help page, right-click (Control-click, on Mac) the plot to display the context menu.  Select Animation > Play.

 > $\mathrm{ApproximateInt}\left(\mathrm{ln}\left(x\right),1..100,\mathrm{method}=\mathrm{simpson},\mathrm{output}=\mathrm{animation}\right)$