Skip to content

Instantly share code, notes, and snippets.

@lettergram
Created March 19, 2015 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lettergram/c775ec3e5fe6c80803c2 to your computer and use it in GitHub Desktop.
Save lettergram/c775ec3e5fe6c80803c2 to your computer and use it in GitHub Desktop.
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