Пример #1
0
        /// <summary>
        /// Power series for incomplete beta integral; formerly named <tt>pseries</tt>.
        /// Use when b*x is small and x not too close to 1.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static double powerSeries(double a, double b, double x) throws ArithmeticException
        internal static double powerSeries(double a, double b, double x)
        {
            double s, t, u, v, n, t1, z, ai;

            ai = 1.0 / a;
            u  = (1.0 - b) * x;
            v  = u / (a + 1.0);
            t1 = v;
            t  = u;
            n  = 2.0;
            s  = 0.0;
            z  = MACHEP * ai;
            while (Math.Abs(v) > z)
            {
                u  = (n - b) * x / n;
                t *= u;
                v  = t / (a + n);
                s += v;
                n += 1.0;
            }
            s += t1;
            s += ai;

            u = a * Math.Log(x);
            if ((a + b) < MAXGAM && Math.Abs(u) < MAXLOG)
            {
                t = GammaFunctions.gamma(a + b) / (GammaFunctions.gamma(a) * GammaFunctions.gamma(b));
                s = s * t * Math.Pow(x, a);
            }
            else
            {
                t = GammaFunctions.logGamma(a + b) - GammaFunctions.logGamma(a) - GammaFunctions.logGamma(b) + u + Math.Log(s);
                if (t < MINLOG)
                {
                    s = 0.0;
                }
                else
                {
                    s = Math.Exp(t);
                }
            }
            return(s);
        }