24double betaIncSum(
double x,
double a,
double b);
25double betaInc1(
double x,
double a,
double b);
27#define BETAI_ACCURACY 1e-10
40 fprintf(stderr,
"lgamma function not implemented on vxWorks\n");
43 return exp(lgamma(a) + lgamma(b) - lgamma(a + b));
47double lnBetaComp(
double a,
double b) {
49 fprintf(stderr,
"lgamma function not implemented on vxWorks\n");
52 return lgamma(a) + lgamma(b) - lgamma(a + b);
67double betaInc(
double a,
double b,
double x) {
68 double xLimit, sum, lnBab = 0;
74 xLimit = (a + 1) / (a + b - 2);
81 lnBab = lnBetaComp(a, b);
83 sum = exp(a * log(x) + b * log(1 - x) - lnBab) * betaIncSum(a, b, x) / a;
89#define MAXIMUM_ITERATIONS 10000
91double betaIncSum(
double a,
double b,
double x) {
93 double A0, B0, A_1, B_1, A1, B1, d;
94 double m, aM1, aP1, aPb, mT2;
98 B0 = 1 - (a + b) / (a + 1) * x;
105 d = m * (b - m) * x / ((aM1 + mT2) * (a + mT2));
113 d = -(a + m) * (aPb + m) * x / ((a + mT2) * (aP1 + mT2));
129 }
while (fabs(f1 - f2) > BETAI_ACCURACY && m < MAXIMUM_ITERATIONS);
139double betaInc1(
double a,
double b,
double x) {
140 double xp, sum, term;
148 }
while (term > BETAI_ACCURACY);
149 return (sum + 1) * pow(x, a) * pow(1 - x, b) / (a *
betaComp(a, b));
double betaComp(double a, double b)
Compute the complete beta function component.
double betaInc(double a, double b, double x)
Compute the incomplete beta function.