示例#1
0
        public void GoldenSection_Maximum_In_0(double a, double b, double eps)
        {
            const double expectedValue = 0;
            var          goldenSection = new GoldenSection(MaximizationFunction);
            var          max           = goldenSection.FindMax(a, b, eps);

            Assert.True(Math.Abs(expectedValue - (max.LeftBound - max.RightBound) / 2) <= eps);
        }
示例#2
0
        static void Main(string[] args)
        {
            const double eps = 0.001;

            Console.WriteLine("Установление первоначальных границ");
            var boundFoundary = new UnconditionalOptimization(MaximizationFunction);

            boundFoundary.OnIteration           += BoundFoundary_OnIteration;
            var(startLeftBound, startRightBound) = boundFoundary.GetBoundForMaximization(5, .5);
            DisplayResult((startLeftBound, startRightBound), boundFoundary.Iterations, eps);

            Console.WriteLine("Уточнение границ методом Золотого сечения");
            var goldenSection = new GoldenSection(MaximizationFunction);

            goldenSection.OnIteration += BoundFoundary_OnIteration;
            var goldenSectionBounds = goldenSection.FindMax(startLeftBound, startRightBound, eps);

            DisplayResult(goldenSectionBounds, goldenSection.Iterations, eps);

            Console.WriteLine("Квадратичная апроксимация");
            var quadraticApproximation = new QuadraticApproximation(MaximizationFunction);

            quadraticApproximation.OnIteration += BoundFoundary_OnIteration;
            var quadApproxBounds = quadraticApproximation.Calculate(startLeftBound, startRightBound, eps);

            DisplayResult(quadApproxBounds, quadraticApproximation.Iterations, eps);

            Console.WriteLine("Метод Ньютона");
            var newtonsMethod = new NewtonsMethod(MaximizationFunctionDerivative1, MaximizationFunctionDerivative2);
            var rootNewtoon   = newtonsMethod.Newton(-9, eps);

            Console.WriteLine($"Корень {rootNewtoon}");
            Console.WriteLine();

            Console.ReadLine();
        }