public void TestInterpolationMethod_EquidistantBarycentricPolynomial()
        {
            double[] x = new double[] { 0.0, 3.0, 2.5, 1.0, 3.0 };

            IInterpolationMethod method = Interpolation.CreateOnEquidistantPoints(0.0, 4.0, x);

            Assert.That(method, Is.TypeOf(typeof(EquidistantPolynomialInterpolation)), "Type");

            for (int i = 0; i < 4; i++)
            {
                // verify the interpolated values exactly at the sample points.
                Assert.That(method.Interpolate(i), Is.EqualTo(x[i]), "A Exact Point " + i.ToString());
            }

            // Maple: "with(CurveFitting);"
            // Maple: "evalf(subs({x=0.1},PolynomialInterpolation([[0,0],[1,3],[2,2.5],[3,1],[4,3]], x)),20);"
            Assert.That(method.Interpolate(0.1), NumericIs.AlmostEqualTo(.48742500000000000000, 1e-15), "A 0.1");
            Assert.That(method.Interpolate(0.4), NumericIs.AlmostEqualTo(1.6968000000000000000, 1e-15), "A 0.4");
            Assert.That(method.Interpolate(1.1), NumericIs.AlmostEqualTo(3.0819250000000000000, 1e-15), "A 1.1");
            Assert.That(method.Interpolate(3.2), NumericIs.AlmostEqualTo(.940800000000000001, 1e-15), "A 3.2");
            Assert.That(method.Interpolate(4.5), NumericIs.AlmostEqualTo(7.265625000000000001, 1e-15), "A 4.5");
            Assert.That(method.Interpolate(10.0), NumericIs.AlmostEqualTo(592.50000000000000000, 1e-13), "A 10.0");
            Assert.That(method.Interpolate(-10.0), NumericIs.AlmostEqualTo(657.50000000000000000, 1e-12), "A -10.0");

            // Test Linear Case
            for (int k = 2; k < 7; k++)
            {
                double[] linx, liny, linxtest, linytest;
                BuildLinearCase(2, k, out linx, out liny, out linxtest, out linytest);
                IInterpolationMethod linearMethod = Interpolation.CreateOnEquidistantPoints(2, Math.Max(k, 3), liny);
                for (int i = 0; i < linxtest.Length; i++)
                {
                    Assert.That(linearMethod.Interpolate(linxtest[i]), NumericIs.AlmostEqualTo(linytest[i], 1e-12), String.Format("Linear k={0} i={1}", k, i));
                }
            }
        }
Ejemplo n.º 2
0
        public void TestInterpolationMethod_EquidistantBarycentricPolynomial()
        {
            double[] x = new double[] { 0.0, 3.0, 2.5, 1.0, 3.0 };

            IInterpolationMethod method = Interpolation.CreateOnEquidistantPoints(0.0, 4.0, x);

            Assert.IsInstanceOfType(typeof(EquidistantPolynomialInterpolation), method, "Type");

            for (int i = 0; i < 4; i++)
            {
                // verify the interpolated values exactly at the sample points.
                Assert.AreEqual(x[i], method.Interpolate(i), "A Exact Point " + i.ToString());
            }

            // Maple: "with(CurveFitting);"
            // Maple: "evalf(subs({x=0.1},PolynomialInterpolation([[0,0],[1,3],[2,2.5],[3,1],[4,3]], x)),20);"
            NumericAssert.AreAlmostEqual(.48742500000000000000, method.Interpolate(0.1), 1e-15, "A 0.1");
            NumericAssert.AreAlmostEqual(1.6968000000000000000, method.Interpolate(0.4), 1e-15, "A 0.4");
            NumericAssert.AreAlmostEqual(3.0819250000000000000, method.Interpolate(1.1), 1e-15, "A 1.1");
            NumericAssert.AreAlmostEqual(.940800000000000001, method.Interpolate(3.2), 1e-15, "A 3.2");
            NumericAssert.AreAlmostEqual(7.265625000000000001, method.Interpolate(4.5), 1e-15, "A 4.5");
            NumericAssert.AreAlmostEqual(592.50000000000000000, method.Interpolate(10.0), 1e-13, "A 10.0");
            NumericAssert.AreAlmostEqual(657.50000000000000000, method.Interpolate(-10.0), 1e-12, "A -10.0");
        }