I'm helping a friend of mine to do her homework, but i need help understanding some results (sorry but i took numeric methods class a looooong time ago)

So, the task is to fit a cubic spline over some mountain shaped function f(x), then calculate the area using Simpson's rule. From what i know, Simpson's rule is exact for degree <= 3, so:

Area(Simpson over splines, n = 2) should equal Area (Integrate over splines)

But i'm getting different results when using n = 2 (number of intervals). I'm using the following function, over the interval [0, 1]

$$1.0 - cos((sin(pi * x^{1.5})))$$

By using Simpson' rule with n = 2, i get 0.2502099, but the integral says that the area is 0.2059441 (which i get if i use n = 20, for example). Why this is happening, and how can i fix it?

Here are the (x, y) points used to fit the Spline:

x        y
0.000000 0.000000
0.111111 0.006731
0.222222 0.051774
0.333333 0.157254
0.444444 0.304818
0.555556 0.429594
0.666667 0.451576
0.777778 0.328222
0.888889 0.116309
1.000000 0.000000

I'm using Python, and i can post the code if needed! Thanks for your help!

  • $\begingroup$ Well, Simpson's rule is not exact for cubic polynomials. $\endgroup$
    – fang
    Commented Nov 30, 2014 at 8:25
  • $\begingroup$ No? why not? I thought the error bound was depends on the 4th derivative, which is zero por poly(3). $\endgroup$
    – Fernando
    Commented Nov 30, 2014 at 17:03
  • $\begingroup$ My understanding is Simpson's rule is derived from approximating the integrand by a quadratic function. Therefore, the approximation can only be accurate when the integrand itself is quadratic. But the Wiki page did say that Simpson's rule is exact for polynomial of degree 3 or less. So, I could be wrong and I need to do more study in this. $\endgroup$
    – fang
    Commented Nov 30, 2014 at 18:14
  • $\begingroup$ OK. I did prove that the Simpson's rule is exact for cubic polynomial. $\endgroup$
    – fang
    Commented Nov 30, 2014 at 18:41
  • $\begingroup$ Look like you have to post your codes for everybody to see in order to spot any problem. BTW, does your cubic spline contain single segment or multiple segments? $\endgroup$
    – fang
    Commented Nov 30, 2014 at 18:44

1 Answer 1


If your cubic spline contains multiple segments, that means it is piecewise continuous. Each segment of the cubic spline is actually a different cubic polynomial and it is probably only C1 continuous (at best C2) at the segment joints. So, when you use Simpson's rule with n=2, all the 3 evaluations of the function value could be done against different cubic polynomials. That is the reason you do not get the same value as when using n=20. You can try to use the 3-point Simpson rule (i.e., n=2) for each segment in the spline then sum up all the result.


You must log in to answer this question.

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