- #1
Tiiba
- 54
- 0
I'm having very unusual problems posting in the math forum.
I am trying to write a program that would calculate phi, the CDF of the standard normal curve, in Python. I tried calculating the erf using a series to do it, as described by Wikipedia. But mine diverges, when it should approach 1.
Something seems to be wrong with erfterm, because it's giving very large results. What gives? Is the equation at Wikipedia wrong? Or did I copy it wrong? Or is my computer wrong?
I am trying to write a program that would calculate phi, the CDF of the standard normal curve, in Python. I tried calculating the erf using a series to do it, as described by Wikipedia. But mine diverges, when it should approach 1.
PHP:
def erfterm(x, n):
num = (-1.0)**n * x**(2*n+1)
denum = fact(n) * (2*n+1)
return num/denum
def erf(x):
#By Maclaurin series
def term(n):
num = (-1.0)**n * x**(2*n+1)
denum = fact(n) * (2*n+1)
return num/denum
return sum([erfterm(x, i) for i in range(25)]) *(2 * sqrt(pi))
Something seems to be wrong with erfterm, because it's giving very large results. What gives? Is the equation at Wikipedia wrong? Or did I copy it wrong? Or is my computer wrong?