Created
December 26, 2011 02:08
-
-
Save duckworthd/1520395 to your computer and use it in GitHub Desktop.
erf() and erfi()
This file contains hidden or 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
private val a = 0.147 // constant for calculating erf/erfi | |
/** | |
* An approximation to the error function | |
*/ | |
def erf(x: Double) = { | |
val x2 = x*x | |
val inner = exp(-1*x2*(4/pi + a*x2) / | |
(1.0 + a*x2)) | |
signum(x)*sqrt(1.0 - inner) | |
} | |
def erfi(x: Double) = { | |
val x2 = x*x | |
val i1 = 2.0/(pi*a) + log(1-x2)/2.0 | |
val i2 = log(1-x2)/a | |
signum(x) * sqrt( sqrt(i1*i1 - i2) - i1 ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment