I've been trying to do some Simpson's modelling to approximate integrals and although my code runs fine, it doesn't seem to give the correct answer. I'm new-ish to coding so I understand it's probably a dumb mistake but I can't figure out what's wrong. f(x) has already been defined and seems to work, it's just this integral approximation that's a bit dodgey.
def integrate_numeric(xmin, xmax, N):
'''
Numerical integral of f from xmin to xmax using Simpson's rule with
N panels.
'''
h = (xmax - xmin)/2*N
# Odd sum
oddtotal = 0
for i in range(1, N, 2):
oddtotal += f(xmin + (i*h))
f_odd = oddtotal
# Even sum
eventotal = 0
for i in range(2, N, 2):
eventotal += f(xmin + (i*h))
f_even = eventotal
return (h/3)*(f(xmin)+(4*f_odd)+(2*f_even)+f(xmax))