Use appropriate quadrature formulae out of the trapezoidal and Simpson's rules to numerically integrate $\int_0^1\frac{dx}{1+x^2}$ with $h=0.2$. Hence obtain an approximate value of $\pi$. Justify the use of a particular quadrature formula.

Answer: answer In this problem trapezoidal rule gave better solution than Simpson's 1/3 rule. How can I justify?

  • $\begingroup$ You're more likely to receive a positive response from the community if you type your question out in MathJax and say what you've already tried. Here's a MathJax Tutorial if you need help! $\endgroup$
    – Aditya
    Jul 15, 2017 at 17:30
  • $\begingroup$ Putting aside any issues of one implementation being incorrect perhaps, the trapezoidal rule behaves in a way that seems to be incredibly good for smooth and periodic integrands. The explanation that I have seen for this uses the Euler-Maclaurin summation formula, which basically is a rigorous way of saying that the trapezoidal rule for a periodic function demonstrates "catastrophic cancellation" of the error. $\endgroup$
    – Ian
    Jul 15, 2017 at 17:53
  • $\begingroup$ (Cont.) Very loosely speaking, the error on a subinterval $I$ on one side of the half-period almost exactly cancels the error on the mirror image of $I$ through the half-period. Put another way a periodic function on its whole period is concave and convex about an equal portion of the time. $\endgroup$
    – Ian
    Jul 15, 2017 at 17:54
  • $\begingroup$ @Ian Anyway, this is not a periodic function. And here the (rightly applied) Simpson rule works far better than the trapezoidal rule. $\endgroup$
    – leonbloy
    Jul 15, 2017 at 18:13
  • $\begingroup$ @leonbloy Oh, I'm sorry, I somehow thought that the lower limit was $-1$ (in that case the periodic extension is $C^0$ and already the trapezoidal rule gains some performance). $\endgroup$
    – Ian
    Jul 15, 2017 at 19:03

1 Answer 1


The way you are applying the Simpson rule is wrong. With $h=0.2$ you get 6 points. The standard Simpson formula (that which you are using) requires an odd number of points (so that the sequence of coefficients in the sum is symmetric: $1,4,2,4, \cdots, 4 , 2 ,4,1$).

One of the possible solutions is suggested here. With that correction, I get $3.14136/4$, a much better approximation than the trapezoidal rule.

You can (you should) verify the correctness of your formula by considering what would happen to a constant function, say $f(x)=1$ - in which case any decent numerical integration scheme should be exact:

$$h \frac{1}{3}(1+4+2+4+2+1)=\frac{14}{15}\ne 1$$

  • $\begingroup$ The better way to think about the Simpson rule is to choose an arbitrary initial mesh that specifies the subintervals where the quadratic interpolants are taken, then you add the midpoints in. If you used an odd (resp. even) number of subintervals, then you had an even (resp. odd) number of endpoints, and you add an odd (resp. even) number of midpoints to get an odd total number of points. This avoids pitfalls like this, and is closer to how the method is derived as well. $\endgroup$
    – Ian
    Jul 15, 2017 at 19:05

Not the answer you're looking for? Browse other questions tagged .