The composite simpson's rule subdivides the interval into n equal subintervals, with n even.
Then $$\int_a^b f(x) dx \approx \frac{h}{3}[f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + ... + 2f(x_{n-2}) + 4f(x_{n-1}) + f(x_n)] $$
(where $x_0 = a$ and $x_n=b$, $h=(b-a)/n$)
So what to do if given n equal intervals, with n odd?
One solution I implemented is to calculate using Simpson's rule for all but the last interval and use the trapezoid rule for the last interval. This seems to work well enough.
But I started thinking, how would I calculate the last interval using Simpson's rule as well?
Consider
$$\begin{aligned} I_1 &= \frac{h}{3}[f(x_{n-3}) + 4f(x_{n-2}) + f(x_{n-1})] \\ I_2 &= \frac{h}{3}[f(x_{n-2}) + 4f(x_{n-1}) + f(x_n)] \\ \end{aligned}$$
$x_n$ is the end of the integral interval. $I_1$ would be the sum corresponding to the last subinterval such that the total number of subintervals considered is even. $I_2$ is Simpson's rule applied to the final, odd subinterval, but half of the subinterval overlaps with $I_1$.
Is there a way to identify what's common to $I_1$ and $I_2$ and subtract it out? Just staring at it, I can't easily see what is the common part. Is it as simple as $(1/2)(h/3)[5f(x_{n-2}) + 5f(x_{n-1})]$?
Solve[ Thread[0 == Coefficient[ Series[x h/3 (f[0] + 4 f[h] + f[2 h]) + y h/3 (f[h] + 4 f[2 h] + f[3 h]), {h, 0, 6}] - Integrate[Series[f[h], {h, 0, 6}], {h, 0, 3 h}], h, {1, 2}]], {x, y}]– Kirill Nov 26 '16 at 22:47