# Why trapezoidal rule is giving better answers for some functions than Simpson's 1/3 rule? [duplicate]

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: In this problem trapezoidal rule gave better solution than Simpson's 1/3 rule. How can I justify?

## marked as duplicate by Parcly Taxel, José Carlos Santos, user370967, user91500, GlorfindelJul 16 '17 at 9:36

• 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! – Aditya Jul 15 '17 at 17:30
• 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. – Ian Jul 15 '17 at 17:53
• (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. – Ian Jul 15 '17 at 17:54
• @Ian Anyway, this is not a periodic function. And here the (rightly applied) Simpson rule works far better than the trapezoidal rule. – leonbloy Jul 15 '17 at 18:13
• @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). – Ian Jul 15 '17 at 19:03

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 must be exact:
$$h \frac{1}{3}(1+4+2+4+2+1)=\frac{14}{15}\ne 1$$