Пример #1
0
        public void TestIntegralOfGaussian(double a, double b, double expected)
        {
            Assert.AreEqual(
                expected,
                Integrate.DoubleExponential((x) => Math.Exp(-x * x / 2), a, b),
                1e-10,
                "DET Integral of e^(-x^2 /2) from {0} to {1}", a, b);

            Assert.AreEqual(
                expected,
                Integrate.GaussKronrod((x) => Math.Exp(-x * x / 2), a, b),
                1e-10,
                "GK Integral of e^(-x^2 /2) from {0} to {1}", a, b);

            Assert.AreEqual(
                expected,
                Integrate.GaussLegendre((x) => Math.Exp(-x * x / 2), a, b, order: 128),
                1e-10,
                "GL Integral of e^(-x^2 /2) from {0} to {1}", a, b);
        }
Пример #2
0
        public void TestIntegralOfSinc(double a, double b, double expected, double factor)
        {
            Assert.AreEqual(
                expected,
                factor * Integrate.DoubleExponential((x) => 1 / (1 + x * x), a, b),
                1e-10,
                "DET Integral of sin(pi*x)/(pi*x) from {0} to {1}", a, b);

            Assert.AreEqual(
                expected,
                factor * Integrate.GaussKronrod((x) => 1 / (1 + x * x), a, b),
                1e-10,
                "GK Integral of sin(pi*x)/(pi*x) from {0} to {1}", a, b);

            Assert.AreEqual(
                expected,
                factor * Integrate.GaussLegendre((x) => 1 / (1 + x * x), a, b, order: 128),
                1e-10,
                "GL Integral of sin(pi*x)/(pi*x) from {0} to {1}", a, b);
        }
Пример #3
0
        public void TestIntegrateFacade()
        {
            // TargetFunctionA
            // integral_(0)^(10) exp(-x/5) (2 + sin(2 x)) dx = 9.1082

            Assert.AreEqual(
                TargetAreaA,
                Integrate.OnClosedInterval(TargetFunctionA, StartA, StopA),
                1e-5,
                "Interval, Target 1e-08");

            Assert.AreEqual(
                TargetAreaA,
                Integrate.OnClosedInterval(TargetFunctionA, StartA, StopA, 1e-10),
                1e-10,
                "Interval, Target 1e-10");

            // TargetFunctionB
            // integral_(0)^(1) integral_(0)^(10) exp(-x/5) (2 + sin(2 y)) dx dy = 11.7079

            Assert.AreEqual(
                Integrate.OnRectangle(TargetFunctionB, StartA, StopA, StartB, StopB),
                TargetAreaB,
                1e-12,
                "Rectangle, order 32");

            Assert.AreEqual(
                Integrate.OnRectangle(TargetFunctionB, StartA, StopA, StartB, StopB, 22),
                TargetAreaB,
                1e-10,
                "Rectangle, Order 22");

            // TargetFunctionC
            // integral_(-oo)^(oo) 1/(1 + x^2) dx = pi

            Assert.AreEqual(
                TargetAreaC,
                Integrate.DoubleExponential(TargetFunctionC, StartC, StopC),
                1e-5,
                "DoubleExponential, 1/(1 + x^2)");

            Assert.AreEqual(
                TargetAreaC,
                Integrate.DoubleExponential(TargetFunctionC, StartC, StopC, 1e-10),
                1e-10,
                "DoubleExponential, 1/(1 + x^2)");

            // TargetFunctionD
            // integral_(0)^(1) log(x) dx = -1

            Assert.AreEqual(
                TargetAreaD,
                Integrate.DoubleExponential(TargetFunctionD, StartD, StopD),
                1e-10,
                "DoubleExponential, log(x)");

            Assert.AreEqual(
                TargetAreaD,
                Integrate.GaussLegendre(TargetFunctionD, StartD, StopD, order: 1024),
                1e-10,
                "GaussLegendre, log(x), order 1024");

            Assert.AreEqual(
                TargetAreaD,
                Integrate.GaussKronrod(TargetFunctionD, StartD, StopD, 1e-10, order: 15),
                1e-10,
                "GaussKronrod, log(x), order 15");
            Assert.AreEqual(
                TargetAreaD,
                Integrate.GaussKronrod(TargetFunctionD, StartD, StopD, 1e-10, order: 21),
                1e-10,
                "GaussKronrod, log(x), order 21");
            Assert.AreEqual(
                TargetAreaD,
                Integrate.GaussKronrod(TargetFunctionD, StartD, StopD, 1e-10, order: 31),
                1e-10,
                "GaussKronrod, log(x), order 31");
            Assert.AreEqual(
                TargetAreaD,
                Integrate.GaussKronrod(TargetFunctionD, StartD, StopD, 1e-10, order: 41),
                1e-10,
                "GaussKronrod, log(x), order 41");
            Assert.AreEqual(
                TargetAreaD,
                Integrate.GaussKronrod(TargetFunctionD, StartD, StopD, 1e-10, order: 51),
                1e-10,
                "GaussKronrod, log(x), order 51");
            Assert.AreEqual(
                TargetAreaD,
                Integrate.GaussKronrod(TargetFunctionD, StartD, StopD, 1e-10, order: 61),
                1e-10,
                "GaussKronrod, log(x), order 61");

            double error, L1;
            var    Q = Integrate.GaussKronrod(TargetFunctionD, StartD, StopD, out error, out L1, 1e-10, order: 15);

            Assert.AreEqual(
                Math.Abs(TargetAreaD),
                Math.Abs(L1),
                1e-10,
                "GaussKronrod, L1");

            // TargetFunctionE
            // integral_(0)^(1) log^2(x) dx = 2

            Assert.AreEqual(
                TargetAreaE,
                Integrate.DoubleExponential(TargetFunctionE, StartE, StopE),
                1e-10,
                "DoubleExponential, log^2(x)");

            Assert.AreEqual(
                TargetAreaE,
                Integrate.GaussLegendre(TargetFunctionE, StartE, StopE, order: 128),
                1e-5,
                "GaussLegendre, log^2(x), order 128");

            Assert.AreEqual(
                TargetAreaE,
                Integrate.GaussKronrod(TargetFunctionE, StartE, StopE, 1e-10, order: 15),
                1e-10,
                "GaussKronrod, log^2(x), order 15");

            // TargetFunctionF
            // integral_(0)^(oo) exp(-x) cos(x) dx = 1/2

            Assert.AreEqual(
                TargetAreaF,
                Integrate.DoubleExponential(TargetFunctionF, StartF, StopF),
                1e-10,
                "DoubleExponential, e^(-x) cos(x)");

            Assert.AreEqual(
                TargetAreaF,
                Integrate.GaussLegendre(TargetFunctionF, StartF, StopF, order: 128),
                1e-10,
                "GaussLegendre, e^(-x) cos(x), order 128");

            Assert.AreEqual(
                TargetAreaF,
                Integrate.GaussKronrod(TargetFunctionF, StartF, StopF, 1e-10, order: 15),
                1e-10,
                "GaussKronrod, e^(-x) cos(x), order 15");

            // TargetFunctionG
            // integral_(0)^(1) sqrt(x)/sqrt(1 - x^2) dx = 1.19814

            Assert.AreEqual(
                TargetAreaG,
                Integrate.DoubleExponential(TargetFunctionG, StartG, StopG),
                1e-5,
                "DoubleExponential, sqrt(x)/sqrt(1 - x^2)");

            Assert.AreEqual(
                TargetAreaG,
                Integrate.GaussLegendre(TargetFunctionG, StartG, StopG, order: 128),
                1e-10,
                "GaussLegendre, sqrt(x)/sqrt(1 - x^2), order 128");

            Assert.AreEqual(
                TargetAreaG,
                Integrate.GaussKronrod(TargetFunctionG, StartG, StopG, 1e-10, order: 15),
                1e-10,
                "GaussKronrod, sqrt(x)/sqrt(1 - x^2), order 15");
        }