Search in sources :

Example 1 with ContinuedFraction

use of de.lab4inf.math.util.ContinuedFraction in project symja_android_library by axkr.

the class ProbabilityDistribution method cdfNormalCF.

/**
 * Cumulative distribution function of the normal distribution, using a continued fraction
 * approximation, formula 26.2.14 or 26.2.15 A &S.
 *
 * @param x the argument
 * @return cdf(x)
 */
public static double cdfNormalCF(final double x) {
    final double eps = 1.E-15;
    double p, q, r;
    final double z = abs(x);
    // calculate Q(x) via CF
    if (z > 1) {
        // formula 26.2.14 A&S for large x
        final ContinuedFraction cf = new NormalCFLargeX();
        r = cf.evaluate(z, eps);
        q = r * pdfNormal(x);
    } else {
        // formula 26.2.15 A&S for small x
        final ContinuedFraction cf = new NormalCFSmallX();
        r = cf.evaluate(z, eps);
        q = 0.5 - r * pdfNormal(x);
    }
    // using P(x) + Q(x) = 1 and P(-x) = Q(x)
    if (x > 0) {
        p = 1 - q;
    } else {
        p = q;
    }
    return p;
}
Also used : ContinuedFraction(de.lab4inf.math.util.ContinuedFraction)

Aggregations

ContinuedFraction (de.lab4inf.math.util.ContinuedFraction)1