Could it be possible that the algorithm isn't complete if n is odd? In that case, I think the formula doesn't take the last subinterval into account.
To see it, you can try:
This is great! Just once question. Is there a way to keep the "box" around the figure so as to sort of frame it? Here is my code
Any suggestions would be greatly appreciated. Thanks.