Skip to content

Instantly share code, notes, and snippets.

@jxnl
Created November 18, 2016 17:34
Show Gist options
  • Save jxnl/f3de3635d522612958584c5db42cdd4d to your computer and use it in GitHub Desktop.
Save jxnl/f3de3635d522612958584c5db42cdd4d to your computer and use it in GitHub Desktop.
def simpson(a, b, f, N):
return (1.0 / 3.0) * (2 * (((b - a) / N) * sum(f(v) for v in [i * ((b - a) \
/ (2. * N)) for i in range(2 * N + 1)][1:2 * N + 1:2])) + (((b - a) / N) * \
((f(a) + f(b)) / 2.0 + sum (f(v * ((b - a) / N) + a) for v in xrange(1, N)))
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment