示例#1
0
        public static double SolveB(double a, double x, double p, double q, double guess, double step, double lower, double upper)
        {
            Func <double, double> f;

            if (p <= q)
            {
                f = b => Math2.Ibeta(a, b, x) - p;
            }
            else
            {
                f = b => Math2.Ibetac(a, b, x) - q;
            }

#if EXTRA_DEBUG
            Debug.WriteLine("IBetaInvB(a={0}, guess?={1}, x={2}) == p({3}), q({4}); range = [{5}, {6}]", a, guess, x, p, q, lower, upper);
#endif

            RootResults r = RootFinder.Toms748Bracket(f, guess, step, FunctionShape.Unknown, lower, upper, _tol, Policies.MaxRootIterations);
            if (r == null)
            {
                Policies.ReportRootNotFoundError("Invalid parameter in root solver");
                return(double.NaN);
            }
            if (!r.Success)
            {
                Policies.ReportRootNotFoundError("Root not found after {0} iterations", r.Iterations);
                return(double.NaN);
            }

#if EXTRA_DEBUG
            Debug.WriteLine("Result = {0};  Toms748 iterations: {1}", r.SolutionX, r.Iterations);
#endif

            return(r.SolutionX);
        }