Created
December 10, 2009 19:26
-
-
Save adamse/253582 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
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