I made a function in Python which calculates a definite integral according to the Trapezoidal rule: Trapezoidal rule formula
That's the code:
from math import ceil
def Trapez_rule(f, a, b, n):
'''Calculates an estimation of a definite integral of a function f(x), between the boundries a, b, by dividing the area to n equal areas'''
sum = (f(a) + f(b)) / 2
for i in range(ceil((b * n))):
sum += f(a + i / n)
sum *= (b - a) / n
return sum
The answer it gives is 10 times higher that it should have returned. I can't find the source of the problem.
I went ahead and fixed your code, and also renamed the function to fit with the official style guide PEP-8.