Simpson's rule over cubic splines

1.5k Views Asked by At

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!

1

There are 1 best solutions below

0
On BEST ANSWER

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.