This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def comp_midpoint(f, a, b, n): | |
sum = 0 | |
h = (b - a) / n | |
x = h/2 | |
for i in range(n): | |
sum += f(x) * h | |
x += h | |
return sum | |
print comp_midpoint(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