示例#1
0
        public static double Solve(Func <double, double> f, double min, double max, Type solverType, double absoluteAccuracy, int maxEval)
        {
            UnivariateSolver solver;

            switch (solverType)
            {
            case Type.BrentSolver:
            {
                solver = new BrentSolver(absoluteAccuracy);
                break;
            }

            case Type.BisectionSolver:
            {
                solver = new BisectionSolver(absoluteAccuracy);
                break;
            }

            case Type.SecantSolver:
            {
                solver = new SecantSolver(absoluteAccuracy);
                break;
            }

            default:
            {
                throw new IndexOutOfRangeException();
            }
            }
            double v = solver.Solve(maxEval, new DelegateUnivariateFunction(f), min, max);

            return(v);
        }
示例#2
0
        private static UnivariateSolver GetSolver(Type type, double error = DEFAULT_ABSOLUTE_ACCURACY)
        {
            UnivariateSolver univariateSolver;

            switch (type)
            {
            case Type.Brent:
                univariateSolver = new BrentSolver(error);
                break;

            case Type.Bisection:
                univariateSolver = new BisectionSolver(error);
                break;

            case Type.Secant:
                univariateSolver = new SecantSolver(error);
                break;

            case Type.RegulaFalsi:
                univariateSolver = new RegulaFalsiSolver(error);
                break;

            case Type.Ridders:
                univariateSolver = new RiddersSolver(error);
                break;

            default:
                throw new IndexOutOfRangeException();
            }
            return(univariateSolver);
        }