Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var lb = 0.01f;
            var ub = 0.0001f;

            Console.WriteLine("Bisection methods:");
            Console.WriteLine("#5");
            Console.WriteLine(BisectionMethod.Evaluate(Function_5, 2, 3, lb));
            Console.WriteLine(BisectionMethod.Evaluate(Function_5, 2, 3, ub));
            Console.WriteLine("#9");
            Console.WriteLine(BisectionMethod.Evaluate(Function_9, 0, (float)Math.PI * (3f / 2f), lb));
            Console.WriteLine(BisectionMethod.Evaluate(Function_9, 0, (float)Math.PI * (3f / 2f), ub));
            Console.WriteLine("#11");
            Console.WriteLine(BisectionMethod.Evaluate(Function_11, 0.000000000001f, 2, lb));
            Console.WriteLine(BisectionMethod.Evaluate(Function_11, 0.000000000001f, 2, ub));
            Console.WriteLine("#15");
            Console.WriteLine(BisectionMethod.Evaluate(Function_15, 0.2f, 2f, lb));
            Console.WriteLine(BisectionMethod.Evaluate(Function_15, 0.2f, 2f, ub));
            Console.WriteLine("Newton method");
            Console.WriteLine("#5");
            Console.WriteLine(NewtonMethod.Evaluate(Function_5, 2, 3, lb));
            Console.WriteLine(NewtonMethod.Evaluate(Function_5, 2, 3, ub));
            Console.WriteLine("#9");
            Console.WriteLine(NewtonMethod.Evaluate(Function_9, 0, (float)Math.PI * (3f / 2f), lb));
            Console.WriteLine(NewtonMethod.Evaluate(Function_9, 0, (float)Math.PI * (3f / 2f), ub));
            Console.WriteLine("#11");
            Console.WriteLine(NewtonMethod.Evaluate(Function_11, 0.000000000001f, 2, lb));
            Console.WriteLine(NewtonMethod.Evaluate(Function_11, 0.000000000001f, 2, ub));
            Console.WriteLine("#15");
            Console.WriteLine(NewtonMethod.Evaluate(Function_15, 0.2f, 2f, lb));
            Console.WriteLine(NewtonMethod.Evaluate(Function_15, 0.2f, 2f, ub));
        }
Exemplo n.º 2
0
 public void IsNewtonMethodCorrect()
 {
     Assert.That(NewtonMethod.Evaluate(new[] { 0d, 2, 3 }, new[] { 1d, 2, 1 }),
                 Is.EqualTo(new Polynomial(0, 1.5, -0.5)));
     Assert.That(NewtonMethod.Evaluate(new [] { -1, 0, 0.5, 1 }, new [] { 0, 2, 9d / 8, 0 }),
                 Is.EqualTo(new Polynomial(2, -1, -2, 1)));
     Assert.That(NewtonMethod.Evaluate(new [] { -2d, 0, 1 }, new [] { -4d, -1, -3 }),
                 Is.EqualTo(new Polynomial(11, -5d / 6, -7d / 6)));
 }
Exemplo n.º 3
0
        public void Function_15_Test()
        {
            var a = 0.2f;
            var b = 2f;
            var expectedResult = 2f;
            var result1        = NewtonMethod.Evaluate(Function_15, a, b, accuracyLowerBound);
            var result2        = NewtonMethod.Evaluate(Function_15, a, b, accuracyUpperBound);

            Assert.GreaterOrEqual(result2.Iterations, expectedResult);

            Console.WriteLine(result1);
            Console.WriteLine(result2);
        }
Exemplo n.º 4
0
        public void Function_11_Test()
        {
            var a = 0.000000000001f;
            var b = 2f;
            var expectedResult = 0f;
            var result1        = NewtonMethod.Evaluate(Function_11, a, b, accuracyLowerBound);
            var result2        = NewtonMethod.Evaluate(Function_11, a, b, accuracyUpperBound);

            Assert.LessOrEqual(result2.Value, expectedResult);

            Console.WriteLine(result1);
            Console.WriteLine(result2);
        }
Exemplo n.º 5
0
        public void Function_9_Test()
        {
            var   a       = 0f;
            float b       = (float)Math.PI * (3f / 2f);
            var   result1 = NewtonMethod.Evaluate(Function_9, a, b, accuracyLowerBound);
            var   result2 = NewtonMethod.Evaluate(Function_9, a, b, accuracyUpperBound);

            Assert.LessOrEqual(result2.Value, result1.Value);
            Assert.GreaterOrEqual(result2.Iterations, result1.Iterations);

            Console.WriteLine(result1);
            Console.WriteLine(result2);
        }
Exemplo n.º 6
0
        public void Test_Function()
        {
            var a       = 1.6f;
            var b       = 6f;
            var result1 = NewtonMethod.Evaluate(TestFunction, a, b, accuracyLowerBound);
            var result2 = NewtonMethod.Evaluate(TestFunction, a, b, accuracyUpperBound);

            Assert.LessOrEqual(result2.Value, result1.Value);
            Assert.GreaterOrEqual(result2.Iterations, result1.Iterations);

            Console.WriteLine(result1);
            Console.WriteLine(result2);
        }