Talk:Simpson's rule/Archive 1

Description of Simpson's rule
For the following description

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

$$ \int_{a}^{b} f(x) \, dx \approx \frac{b-a}{3n}\left[f(a) + 4f\left(\frac{a+b}{2}\right)+f(b)\right]$$

this is very confusing because it is written as though n can be varied in the equation. Obviously, though, n is fixed as being equal to 2. I think this should instead be written as

$$ \int_{a}^{b} f(x) \, dx \approx \frac{b-a}{6}\left[f(a) + 4f\left(\frac{a+b}{2}\right)+f(b)\right]$$

with no mention of n (or you should use the true general expression).


 * If n isn't used in the equation, then why is n mentioned at all in the introduction to the equation? That is, what is the purpose of the phrase "n is the number of samples"? —Preceding unsigned comment added by 134.147.191.99 (talk) 07:31, 8 July 2010 (UTC)
 * BeBold. Will remove. 141.24.172.12 (talk) 05:08, 13 July 2010 (UTC)

Actually, there is an error on this page: the 6 should be a 3 (see, for example, the MathWorld page on Simpson's rule). —Preceding unsigned comment added by Kurt.peek (talk • contribs) 07:04, 19 September 2010 (UTC)


 * No, the denominator is definitely 6, not 3. The MathWorld version is


 * $$\int_{x_1}^{x_2}f(x)\, dx \approx \frac{1}{3}h(f_0 + 4f_1 + f_2)$$


 * but note that


 * $$x_2 = x_1 + 2h$$
 * $$\Rightarrow h = \frac{x_2-x_1}{2}$$
 * $$\Rightarrow \int_{x_1}^{x_2}f(x)\, dx \approx \frac{x_2-x_1}{6}(f_0 + 4f_1 + f_2)$$


 * which is the same as our version:


 * $$ \int_{a}^{b} f(x) \, dx \approx \frac{b-a}{6}\left[f(a) + 4f\left(\frac{a+b}{2}\right)+f(b)\right]$$.


 * Try a simple function such as f(x) = 1 to check. Gandalf61 (talk) 09:16, 19 September 2010 (UTC)

Code Implementation
I put the matlab code in there because it WAS a different implementation. The python code is for the simpson's rule and the matlab code was for the composite simpsons rule. Two different things, and two very different implementations I personally think there should be a different page for each, maybe when they get a bit longer. Epachamo 22:53, 3 April 2006 (UTC) thanks I'm glad you did it helps for my emth lab;)Randomkeys 07:12, 31 July 2006 (UTC)

I put in a VBA for Excel example but it was removed because " VBA code example - too long; if VBA cannot pass function as argument then not suitable for illustrating this article) ". It was long, and could have been much shorter without comments, true enough. The second argument is false, however - it did pass in a function as an argument. Because VBA functions can't modify cell values directly, the text string for the function was used. It's just a different form of indirection. I sense bias here. Although there are *much* better ways to implement math code, some people get stuck having to work in Excel (or OpenOffice if they're lucky).DaveDixon (talk) 15:02, 13 August 2010 (UTC)


 * Half of your VBA example was taken up by your ReplaceVariable function, which uses string processing to mimic evaluation of a function argument. Clever, but distracting and nothing to do with the subject of the article. Wikipedia is not a programmer's cookbook. We already have 4 code samples in the article (3 more than we need, in my opinion), and we really don't need a 5th. Gandalf61 (talk) 15:48, 13 August 2010 (UTC)


 * ... and I have now been bold and trimmed the remaining code samples, keeping only the MATLAB implementation of the composite Simpson's rule. Gandalf61 (talk) 09:55, 14 August 2010 (UTC)

History of Simpson's rule
It would be nice to have a section on the history of Simpson's rule, if good references can be found. There's a little bit at Thomas Simpson. 165.189.91.148 17:31, 23 October 2006 (UTC)

Alternative method of finding composite Simpson's rule
There is an alternative method of finding the composite Simpson's rule - it can be calculated as a weighted average of the midpoint and trapezium rule. If you decide to use x strips for the Simpson's rule, then you estimate the integration using the midpoint and trapezium rule using x/2 strips. You can then find the Simpson's rule result by (2*M + T)/3 where M is the midpoint rule result and T is the trapezium rule result. Perhaps this could be added? —Preceding unsigned comment added by 84.65.170.151 (talk • contribs) 21:47, 2 November 2006


 * Hmmm. That's a rather mysterious derivation; where do the weights come from, and why would you expect that the resulting method is any better. On the other hand, you're right that Simpson = (2*M + T)/3; I guess one could add a statement to that effect. -- Jitse Niesen (talk) 04:16, 3 November 2006 (UTC)


 * Indeed, there is even a third way: One simply sets up a system of equations as follows:  You start with a rule saying Q(f) = a0*f(a) + a1*f((a+b)/2) + a2*f(b), and find the coefficients {ai} by solving Q(f) = a*x^2 + b*x + c.  This thus ensures that the quadrature rule is exact for polynomials up to and including degree 2, which of course means it must be Simpson's rule. Grokmoo 19:48, 3 November 2006 (UTC)


 * If you look at the error of the midpoint and trapezium rule, then the error reduces at the same rate. However, the midpoint rule normally has about half of the error of the trapezium rule (with the same number of strips), so we weight the two results accordingly.Mike Williamson 22:26, 3 November 2006 (UTC)


 * Those are both quite natural ways to arrive at Simpson's rule, and I think that they would make good additions to the article. -- Jitse Niesen (talk) 02:05, 4 November 2006 (UTC)
 * I removed that derivation. By the above, the weights should be 2 and -1, while in reality they are 2 and 1. The text was not rigurous enough, as it is was not clear what exactly the error was or why. And I am not sure we need such a derivation anway. Oleg Alexandrov (talk) 03:42, 6 November 2006 (UTC)


 * Why do you think we don't need this derivation (done properly, of course)? I think it's quite nice to show that Simpson's rule can be derived in multiple ways. -- Jitse Niesen (talk) 04:48, 6 November 2006 (UTC)
 * OK, if I see it done well I may change my mind. :) Oleg Alexandrov (talk) 04:51, 6 November 2006 (UTC)
 * This is what I had in mind. I wasn't going to include the error of midpoint and trapezium, but since Oleg asked for it &hellip; Anyway, I'm less sure now that it's a good addition. It also is a bit ORish. -- Jitse Niesen (talk) 07:49, 11 November 2006 (UTC)

matlab implementation
I changed the article earlier to comment that the matlab function "quad" does composite simpson's rule, and my change was reverted. I don't necessarily disagree with the revert (this isn't a matlab tutorial), but I don't see why the matlab and python code is in the article in the first place then. Why not just write psuedo-code? The only purpose of matlab or python code is so that someone can easily implement it -- in which case, you would implement the builtin matlab function.

Hence, I say keep the coding to high level psuedo-code. Maybe there's a wikipedia-wide convention on this, but I say if wikipedia is more than a user's manual for various software, then we should keep algorithms and coding separate. Lavaka 20:40, 4 March 2007 (UTC)
 * Implementing both the Simpson's rule and its composite version in pseudocode is a good idea I think, if somebody's willing to do the work. Oleg Alexandrov (talk) 03:47, 5 March 2007 (UTC)


 * In my opinion, it is a bit silly to have implementations in different languages in the same article, because that makes it hard to compare them. Generally, I would agree with using pseudocode. Having a (pseudo)implementation helps when trying to understand algorithm. However, in this case the algorithm is so simple that it can be described in one formula, so I don't see what an algorithm would add to the article. Therefore, I think we should just delete both implementations.
 * I assume you already know this, but Matlab's quad does more than the composite Simpson's rule as described in this article. It automatically adapts the lengths of the subintervals. -- Jitse Niesen (talk) 04:23, 10 March 2007 (UTC)

Composite Simpsons's rule
Composite Simpson's rule: The explanation on what n is is not clear, i have tried deriving the equation: $$ \int_{a}^{d} f(x) \, dx \approx \frac{b-a}{6}\left[f(a)+4f\left(\frac{a+b}{2}\right)+f(b)\right]$$

$$+\frac{c-b}{6}\left[f(b)+4f\left(\frac{b+c}{2}\right)+f(c)\right]$$

$$+\frac{d-c}{6}\left[f(c) + 4f\left(\frac{c+d}{2}\right)+f(d)\right].$$

$$\frac{d-c}{6}=\frac{c-b}{6}=\frac{b-a}{6}=\frac{d-a}{6n}$$  If we say n=3 in the above example

so $$\int_{a}^{d} f(x) \, dx \approx \frac{d-a}{6n}\left(\left[f(a)+4f\left(\frac{a+b}{2}\right)+f(b)\right]+\left[f(b)+4f\left(\frac{b+c}{2}\right)+f(c)\right]+\left[f(c)+4f\left(\frac{c+d}{2}\right)+f(d)\right]\right)$$

$$\int_{a}^{d} f(x) \, dx \approx \frac{d-a}{6n}\left(f(a)+4f\left(\frac{a+b}{2}\right)+2f(b)+4f\left(\frac{b+c}{2}\right)+2f(c)+4f\left(\frac{c+d}{2}\right)+f(d)\right)$$

$$ h=\frac{d-a}{n}$$

$$\int_{a}^{d} f(x) \, dx \approx \frac{h}{6}\left(f(a)+4f\left(\frac{a+b}{2}\right)+2f(b)+4f\left(\frac{b+c}{2}\right)+2f(c)+4f\left(\frac{c+d}{2}\right)+f(d)\right)$$

or to put it as in the main article:

$$\int_a^b f(x) \, dx\approx \frac{h}{6}\bigg[f(x_0)+4f(x_1)+2f(x_2)+4f(x_3)+2f(x_4)+\cdots+4f(x_{n-1})+f(x_n)\bigg].$$

So, in my opinion, either what n is needs to be carefully defined, or the equation should be changed to be h/6 instead of h/3

--Richtea2007 16:21, 27 April 2007 (UTC)


 * In your example, n = 6, as can be seen by comparing the last two of your equations: $$x_0=a$$, $$x_1 = (a+b)/2$$, &hellip;, $$x_5 = (c+d)/2$$, $$x_6 = d$$. I agree that the article did not clearly define n. It used to say that the interval [a,b] is divided in n subintervals, while it is probably clearer to say that it's divided in $$n/2$$ subintervals. I changed that. Thanks for your comment. -- Jitse Niesen (talk) 03:25, 28 April 2007 (UTC)

Although it works both ways, it would be right to take h/6 with n=3, as there are actually 3 subintervals, and the 6 comes from the coefficents 1(f(a))+4(f((a+b)/2)+1(f(b)=6. I don't see a reason to take h/3, as it is h/6 in all the other examples. —Preceding unsigned comment added by 85.103.74.156 (talk) 20:01, 15 May 2008 (UTC)

I believe the Composite Simpson rule, as it stands now, is wrong... or at least, it is wrong the description when talking about the "n" sub-intervals. Clearly, for n=2 we recover the initial Simpson's rule written at the top of the page, while there is no mention there of the fact that the interval is split into 2 sub-intervals. This needs to be changed. — Preceding unsigned comment added by 2001:700:300:1470:BD9C:E9FC:6B6F:41AE (talk) 15:21, 27 October 2014 (UTC)

Another Simpson's rule...
$$ d = oh!$$ ♥♥ ΜÏΠЄSΓRΘΠ€ ♥♥ slurp me! 20:56, 3 June 2007 (UTC)

Hey sorry to sound like an idiot but are you sure it's not named after Edward Simpson? I think it is Thomas but a lecturer said that it was Edward

Greenharpoon 10:36, 27 June 2007 (UTC)Greenharpoon

Python example bug?
The python example includes the line: h3 = abs(b - a) / 6.0 However, the function given uses (b - a)/6, not |b-a|/6. I believe the Python code is simply wrong, but am I missing something? -Ahruman (talk) 14:24, 28 February 2008 (UTC)


 * You have to decide first what is meant by a definite integral from a to b when b is less than a. Depending on what you decide, either answer may be OK.  Apparently the python programmer took one interpretation, and the other guy another. Dicklyon (talk) 16:04, 28 February 2008 (UTC)


 * When you integrate from a to b with a>b, you get a negative result. The python code is wrong and I am correcting it. Good catch.--Hirak 99 (talk) 14:33, 4 September 2008 (UTC)

Simpson's 3/8 rule
The error term of simpson's 3/8 rule is not mentioned. Or is it? It's hard to read the weird stuff near the bottom, it looks like batch files. Does anyone know the error term in simpson's 3/8 rule? -srn347


 * You right, it was not mentioned. I added the error term. The "weird stuff near the bottom" shows how one could program Simpson's rule on a computer using a particular programming language called Python. -- Jitse Niesen (talk) 12:20, 12 January 2009 (UTC)

Thx. Wow, the 3/8 method is way more accurate! Is there something about this signing thing I am doing wrong? -srn347 —Preceding unsigned comment added by 68.7.25.121 (talk) 19:59, 16 January 2009 (UTC)

The definition of "h" might be a bit confusing here... although it should be "obvious" that it's 1/3 the spacing between "a" and "b" from the equality, one might easily just assume it's the spacing between "a" and "b". Maybe this is the confusing result of a "blend" between describing the rule for 4 evenly spaced points, vs. describing the rule for the region "a" to "b" where the evenly spaced points are found implicitly? —Preceding unsigned comment added by 142.103.140.90 (talk) 03:11, 15 September 2010 (UTC)

Incorrect "Averaging the midpoint and the trapezium rules" section
I believe the section "Averaging the midpoint and the trapezium rules" is incorrect as stated in the article because it applies only if the Midpoint and Trapezium rules are done with half as many points. i.e. S(2n)=(1/3)T(n)+(2/3)M(n). See http://www.humboldt.edu/~mef2/book/ch5/CH5DSIMP.htm. D dc  c  05:26, 25 January 2009 (UTC)

Does the page require a python code example?
I'm sure that the code is handy for some things, but does this page require it. Personally if code is going to be added to a page like this then it should be done in pseudo code so that it easily understandable (Even though python is :). But having said that i don't think that it is necessary on the page, its gonna be posted on other websites if someone wanted a python program to perform Simpson rule. IMBlackMath (talk) 06:33, 18 March 2009 (UTC)

I agree, I don't see a need for code, I seriously doubt the vast majority of people care about how it is implemented in Python, or any programming language for that matter. Since no one else has objected since you asked about it, I'm removing it. 76.122.102.100 (talk) 23:19, 6 October 2009 (UTC)

A: This page absolutely REQUIRES the python code. It is the only working example people have that will execute on free software; whereas, MOST people have no way to run the Matlab code. —Preceding unsigned comment added by 128.138.64.169 (talk) 01:34, 3 February 2010 (UTC)

While I personally like Python as a form of pseudo code, the above statement that the MATLAB code cannot be run with free software is not true. GNU Octave is a mature free software replacement for MATLAB with mostly compatible syntax. Tukss (talk) 01:21, 17 April 2010 (UTC)

Error and 3/8 rule considerations
Today, the error was corrected from


 * $$ \left|\frac{(b-a)^5}{180} f^{(4)}(\xi)\right|, $$

to


 * $$ \left|\frac{(b-a)^5}{2880} f^{(4)}(\xi)\right|, $$

which caused me some confusion, since I spent yesterday studying this for my test and it suddenly changed on me. So I went after the reason, and this is what I found out: If you rewrite the formula as


 * $$ \left|\frac{(b-a)h^4}{180} f^{(4)}(\xi)\right|, $$ where
 * $$ \left|h = \frac{(b-a)}{2n}\right|, $$

that is, h is the step, the distance between two known points of the equation. I think the latter notation is an advantage because it gives the error both for the simple (n = 1) and the composite Simpson's rule, and also the possibility of writing it as a function of the number of intervals taken:


 * $$ \left|\frac{(b-a)}{2880n^4} f^{(4)}(\xi)\right|, $$

and there so appears the 2880 that has been causing me doubts. I also removed the minus (-) sign from inside the modules in my formulas because I don't understand the purpose of inserting a minus (-) sign inside a module, so I suggest it's removed or clarified... But I will leave the topic for discussion.

Moreover, I'm not sure of what calculations were made to come from the quadratic to the cubic (or 3/8) error formula, but I think it relates to the quadratic formula, in which case correction might be necessary to maintain consistency (as in to use the same logic for all formulas in the article). Though I'm not sure of the latter, I had to study the topic for my test, and I believe the composite cubic rule could be added to the article, it is as follows:


 * $$\int_a^b f(x) \, dx\approx

\frac{3h}{8}\bigg[f(x_0)+3f(x_1)+3f(x_2)+2f(x_3)+3f(x_4)+3f(x_5)+2f(x_6)+\cdots+3f(x_{n-1})+f(x_n)\bigg],$$ or


 * $$\int_a^b f(x) \, dx\approx

\frac{3h}{8}\bigg[\sum_{j=0}^{(n/3)-1}f(x_{3j}) + 3f(x_{3j + 1}) + 3f(x_{3j + 2})+ f(x_{3j + 3}) \bigg].$$

My sum notation slightly differs from that used elsewhere in the article, so I leave to those in charge to decide whether to change either one. If mine is to be used, please check if it is correct, as I just wrote it for the first time. The quadratic composite using my notation would be


 * $$\int_a^b f(x) \, dx\approx

\frac{h}{3}\bigg[\sum_{j=0}^{(n/2)-1}f(x_{2j}) + 4f(x_{2j + 1}) + f(x_{2j + 2}) \bigg],$$

which also needs checking. Phew! There you go, this was one big post. Cheers from Brazil --Monsieur.lefou (talk) 10:16, 9 November 2009 (UTC)
 * EDIT: I had to make some corrections in the two sums above --Monsieur.lefou (talk) 23:25, 9 November 2009 (UTC)

Compare: Kepler- rule
I think, that Simpson's integration rule given in this articel is the same rule, one would find under "kepler rule" or - in German - "Kepler'sche Fassregel". (Compare eg. the German "wikipedia" with the Article [| Kepler'sche Fassregel].) But there is another possibility of numerical integration, of which I belive it is also known as a "Simpson rule". Consider therefore the area between the coordinate-axis and a given function $$f(x):\R\to\R$$ within an intervall $$[a,b]$$. Than one might find the numerical expression for the integral $$A=\int_{a}^{b}f(x)dx$$:
 * $$A=\frac{h}{3}[y_{0}+4y_{1}+2y_{2}+4y_{3}+2y_{4}+...+4y_{n-1}+y_{n}]$$

As far as I know is this known as the Simpson rule.

The "Kepler'sche Fassregel" (Kepler rule) can be written as
 * $$ A\approx \frac{b-a}{6} [f(a)+f(b)+4r(\frac{a+b}{2})^{2}+4s(\frac{a+b}{2})+4t]$$

where $$[a,b]$$ is the integration intervall and the function $$f(x)$$ is approximated by a parabola $$g(x)=rx^{2}+sx+t$$ and there are three points $$a,b,\frac{a+b}{2}$$, so that
 * $$f(a)=g(a)=ra^{2}+sa+t$$
 * $$f(b)=g(b)=rb^{2}+sb+t$$
 * $$f(\frac{a+b}{2})=g(\frac{a+b}{2})=r(\frac{a+b}{2})^{2}+s(\frac{a+b}{2})+t$$

Therefore my question: What IS the Simpson integration rule, how is it definde. Or is it even the same as the Kepler rule? 77.80.22.56 (talk) 13:17, 22 April 2010 (UTC)

Smoothness implies smallness?
I write about the statement made in the text, "If the interval of integration [a,b] 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 [a,b]." I think I understand the intent of this passage, but it is not clearly stated. Usually when we say that (a,b) is in some vague sense "small", we mean that the measure of the interval meas[(a,b)]<δ for some parameter δ, but this is not really the case here. It is possible in some well-constructed cases to get a very good approximation to the integral even for wildly oscillating functions over "large" intervals, but what the author meant I believe is that it is possible to reduce the error term by applying the rule over smaller intervals and summing the results. Not sure exactly how to rewrite this, but it did bother me when I browsed through. jgoldfar (talk) 20:15, 22 November 2010 (UTC)

I agree with Jgoldfar. As I understand things, what is really meant is that the function looks locally like a parabola. The text does not make the shortcomings of simpson's rule clear.

$$ \int_{-h}^{h} \max(0, x) dx = \frac{h^2}{2} $$ but Simpson's rule approximates it as $$ h^2/3 $$. The relative error 50% and NEVER GETS BETTER as the interval shrinks. Using a composite rule does not necessarily solve the problem, either. The trapezoid rule, on the other hand, nails things perfectly. — Preceding unsigned comment added by Uscitizenjason (talk • contribs) 02:10, 28 July 2011 (UTC)

Outdated Application
The reference that claims that Simpson's rule is used to approximate integrals is from 1918 (see the first few pages of the book). This source does not reflect modern use of Simpson's rule and should be reconsidered for its use in this article. Although I have no source to back this claim up, it is highly likely that business would provide their workers with calculators to accurately compute integrals and maximize efficiency, so Simpson's rule is likely not used.

70.247.245.144 (talk) 03:04, 20 April 2012 (UTC)

averaging the midpoint and trapezoid formulas: 4th order terms
I believe that the 4th order terms of the error functions normally differ in the midpoint and trapezoid approximations. I have changed the function O that appeared in both to O1 and O2. Do correct this if I am mistaken. hgilbert (talk) 16:57, 20 August 2012 (UTC)


 * In fact, the O notation in that section is a rather special notation. This was not explained in the article. I added a short explanation; let me know if that helps. -- Jitse Niesen (talk) 09:23, 21 August 2012 (UTC)

Proposed addition
The composite Simpson's rule can be put in a more compact form as here below, which better fits practical numerical calculation whether by MS EXCEL, WOLFRAM or a simple calculator.

Bruno Consolini



Simpson <=> Kepler?
Did anyone notice, that this is NOT the Simpson rule but Kepler? — Preceding unsigned comment added by 46.223.59.197 (talk) 19:29, 10 February 2015 (UTC)

C Implementation
Has it been tested by anyone? Comparing floating-point values (x == b) is totally weird. In general case this condition is never met, which results in missing the last element and greater then theoretical error. 37.145.50.224 (talk) 13:46, 24 January 2016 (UTC)