how to print the midpoint rule in python
I have the following code to calculate the midpoint of a function and then output the approximate area under the graph but I can't get it to print it is saying there is one missing required attribute of 'points', I'm not sure if this is something to do with the code itself or just trying to print the result. any ideas on how to fix this?
def midpoint(f, xmin, xmax, points):
h = float(xmax-xmin)/points
result = 0
for i in range(points):
result += f((xmin + h/ 2.0) + i*h)
result *= h
return result
print (midpoint(points,xmin,xmax))
You are missing the function input.
midpoint(f, xmin, xmax, points)
So you have to give f
You have:
midpoint(points, xmin, xmax)