erf

image The "error function" or cumulative distribution function is encountered in probability and can be used to compute the probability that a Gaussian random number falls within a given range. This algorithm was taken from the article in the link given immediately below.

http://www4.ncsu.edu/unity/users/p/pfackler/www/ECG790C/accuratecumnorm.pdf

Downloaderf(x)   Returns the value of erf(x) where 'erf' is the "error function".
/*
**  Usage:
**      erf(x)
**
**  Arguments:
**      x       a real value
**
**  Returns:
**      the value of erf(x) where 'erf' is the "error function"
**
**  Comments:
**      The "error function" or cumulative distribution function is encountered
**      in probability and can be used to compute the probability that a
**      Gaussian random number falls within a given range.  This algorithm was
**      taken from the article in the link given immediately below.
**
**  http://www4.ncsu.edu/unity/users/p/pfackler/www/ECG790C/accuratecumnorm.pdf
**
**  GMLscripts.com
*/

{
    var xAbs, c, e, b;
    xAbs = abs(argument0) * sqrt(2);
    if (xAbs > 37)
    c = 0;
    else {
        e = exp(-xAbs*xAbs / 2);
        if (xAbs < 7.07106781186547) {
            b = 0.0352624965998911 * xAbs + 0.700383064443688;
            b = b * xAbs + 6.37396220353165;
            b = b * xAbs + 33.912866078383;
            b = b * xAbs + 112.079291497871;
            b = b * xAbs + 221.213596169931;
            b = b * xAbs + 220.206867912376;
            c = e*b;
            b = 0.0883883476483184 * xAbs + 1.75566716318264;
            b = b * xAbs + 16.064177579207;
            b = b * xAbs + 86.7807322029461;
            b = b * xAbs + 296.564248779674;
            b = b * xAbs + 637.333633378831;
            b = b * xAbs + 793.826512519948;
            b = b * xAbs + 440.413735824752;
            c /= b;
        }
        else {
            b = xAbs + 0.65;
            b = xAbs + 4 / b;
            b = xAbs + 3 / b;
            b = xAbs + 2 / b;
            b = xAbs + 1 / b;
            c = e / b / 2.506628274631;
        }
    }
    if (argument0 > 0)
    return 1 - 2*c;
    else
    return 2*c - 1;
}

Click if you've used this script[Please Login]
Projects: 4

 Contributors: Yourself, brac37

 History:
Aug 23, 2007 - Yourself submits original script
May 23, 2008 - brac37 corrects a few important typos


comments powered by Disqus