Simpson's Rule - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : Education : Student Package : Calculus 1 : Visualization : Integration : Student/Calculus1/Simpson

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{1}{2}{x}_{i-1}+\frac{1}{2}{x}_{i},f\left(\frac{1}{2}{x}_{i-1}+\frac{1}{2}{x}_{i}\right)\right)$, and $\left({x}_{i},f\left({x}_{i}\right)\right)$.  This value is

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

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

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

 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 ${∫}_{a}^{b}f\left(x\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}ⅆx$ is

$\frac{1}{3}\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)}{N}$

 • 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{{1}}{{6}}{}\left({{x}}_{{0}}{-}{{x}}_{{1}}\right){}\left({f}{}\left({1}\right){+}{4}{}{f}{}\left(\frac{{1}}{{2}}\right){+}{f}{}\left({0}\right)\right)$ (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{{1}}{{6}}{}{\mathrm{sin}}{}\left(\frac{{9}}{{2}}\right){+}\frac{{1}}{{3}}{}{\mathrm{sin}}{}\left(\frac{{19}}{{4}}\right){+}\frac{{1}}{{12}}{}{\mathrm{sin}}{}\left({5}\right){+}\frac{{1}}{{6}}{}{\mathrm{sin}}{}\left({3}\right){+}\frac{{1}}{{3}}{}{\mathrm{sin}}{}\left(\frac{{13}}{{4}}\right){+}\frac{{1}}{{6}}{}{\mathrm{sin}}{}\left(\frac{{7}}{{2}}\right){+}\frac{{1}}{{3}}{}{\mathrm{sin}}{}\left(\frac{{15}}{{4}}\right){+}\frac{{1}}{{6}}{}{\mathrm{sin}}{}\left({4}\right){+}\frac{{1}}{{3}}{}{\mathrm{sin}}{}\left(\frac{{17}}{{4}}\right){+}\frac{{1}}{{3}}{}{\mathrm{sin}}{}\left(\frac{{5}}{{4}}\right){+}\frac{{1}}{{6}}{}{\mathrm{sin}}{}\left(\frac{{3}}{{2}}\right){+}\frac{{1}}{{3}}{}{\mathrm{sin}}{}\left(\frac{{7}}{{4}}\right){+}\frac{{1}}{{6}}{}{\mathrm{sin}}{}\left({2}\right){+}\frac{{1}}{{3}}{}{\mathrm{sin}}{}\left(\frac{{9}}{{4}}\right){+}\frac{{1}}{{6}}{}{\mathrm{sin}}{}\left(\frac{{5}}{{2}}\right){+}\frac{{1}}{{3}}{}{\mathrm{sin}}{}\left(\frac{{11}}{{4}}\right){+}\frac{{1}}{{6}}{}{\mathrm{sin}}{}\left(\frac{{1}}{{2}}\right){+}\frac{{1}}{{3}}{}{\mathrm{sin}}{}\left(\frac{{3}}{{4}}\right){+}\frac{{1}}{{3}}{}{\mathrm{sin}}{}\left(\frac{{1}}{{4}}\right){+}\frac{{1}}{{6}}{}{\mathrm{sin}}{}\left({1}\right)$ (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 Macintosh) 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)$

## Was this information helpful?

 Please add your Comment (Optional) E-mail Address (Optional) What is ? This question helps us to combat spam