Skip to content

Instantly share code, notes, and snippets.

@adamse
Created December 10, 2009 19:26
Show Gist options
  • Save adamse/253582 to your computer and use it in GitHub Desktop.
Save adamse/253582 to your computer and use it in GitHub Desktop.
from math import exp, sqrt, pi, floor
def estimateArea(n = 1, s = 1, m = 0):
# n: Number of standard deviations from mean
# s: Standard deviation
# m: Mean
# Delta x
dx = 0.00001
# Probability Density Function; p(x)
p = lambda x: (1 / sqrt(2 * pi * (s**2))) * exp(-(x - m)**2 / (2 * s**2))
# Giving an estimation slightly too high
nmax = range(0, int(floor((n * s) / dx))-1)
Amax = 2 * dx * sum([p(m + (i) * dx) for i in nmax])
# Giving an estimation slightly too low
nmin = range(1, int(floor((n * s) / dx)))
Amin = 2 * dx * sum([p(m + (i) * dx) for i in nmin])
return Amax, Amin, Amax - Amin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment