Created
March 19, 2015 00:51
-
-
Save lettergram/fa41959d825281a9e231 to your computer and use it in GitHub Desktop.
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_simpson(f, a, b, n): | |
h = (b - a) / n | |
sum = f(a) + f(b) | |
for i in range(1, n, 2): | |
sum += 4 * f(a + i * h) | |
for i in range(2, n-1, 2): | |
sum += 2 * f(a + i * h) | |
return sum * h / 3 | |
print comp_simpson(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