Logo Search packages:      
Sourcecode: quantlib version File versions  Download package

Real QuantLib::incompleteBetaFunction ( Real  a,
Real  b,
Real  x,
Real  accuracy = 1e-16,
Integer  maxIteration = 100 
)

Incomplete Beta function.

Incomplete Beta function

The implementation of the algorithm was inspired by "Numerical Recipes in C", 2nd edition, Press, Teukolsky, Vetterling, Flannery, chapter 6

Definition at line 67 of file beta.cpp.

References QL_REQUIRE.

                                                      {

    QL_REQUIRE(a > 0.0, "a must be greater than zero");
    QL_REQUIRE(b > 0.0, "b must be greater than zero");


    if (x == 0.0)
        return 0.0;
    else if (x == 1.0)
        return 1.0;
    else
        QL_REQUIRE(x>0.0 && x<1.0, "x must be in [0,1]");

    Real result = std::exp(GammaFunction().logValue(a+b) -
        GammaFunction().logValue(a) - GammaFunction().logValue(b) +
        a*std::log(x) + b*std::log(1.0-x));

    if (x < (a+1.0)/(a+b+2.0))
        return result *
            betaContinuedFraction(a, b, x, accuracy, maxIteration)/a;
    else
        return 1.0 - result *
            betaContinuedFraction(b, a, 1.0-x, accuracy, maxIteration)/b;
    }


Generated by  Doxygen 1.6.0   Back to index