コード例 #1
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);
        }
コード例 #2
0
ファイル: Solver.cs プロジェクト: 15831944/Essence
        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);
        }
コード例 #3
0
        /// <summary>
        ///     Resuelve el parametro de la clotoide dado los radios <c>r0</c> y <c>r1</c> Con una distancia <c>d</c> entre los
        ///     puntos.
        /// </summary>
        private static double SolveParam(double d, double r0, double r1)
        {
            Func <double, double> f = (a) =>
            {
                double fs0, fc0;
                ClothoUtils.Fresnel(a / (r0 * sqrtpi), out fs0, out fc0);

                double fs1, fc1;
                ClothoUtils.Fresnel(a / (r1 * sqrtpi), out fs1, out fc1);

                double fc10 = (fc1 - fc0);
                double fs10 = (fs1 - fs0);

                return(a * a * SysMath.PI * (fc10 * fc10 + fs10 * fs10) - d * d);
            };

            //UnivariateSolver solver = new BisectionSolver(DEFAULT_ABSOLUTE_ACCURACY);
            //UnivariateSolver solver = new SecantSolver(DEFAULT_ABSOLUTE_ACCURACY);
            UnivariateSolver solver = new BrentSolver(DEFAULT_ABSOLUTE_ACCURACY);
            int maxEval             = 50; // 30

            try
            {
                double v = solver.solve(maxEval, new DelegateUnivariateFunction(f), 0, SysMath.Min(SysMath.Abs(r0), SysMath.Abs(r1)) * ClothoUtils.MAX_L);
                return(v);
            }
            catch (TooManyEvaluationsException e)
            {
                Console.WriteLine(e);
                throw;
            }
        }