Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import math
def comp_trap(f, a, b, n):
h = (b - a) / n
sum = f(a) / 2
for i in xrange(1, n):
sum += 2 * f(a + i * h)
return sum * h / 2
print comp_trap(lambda x:math.sin(x), 0.0, math.pi / 2, 120)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.