public void TestInterpolationMethod_RationalWithPoles() { double[] t = new double[] { 0, 1, 3, 4, 5 }; double[] x = new double[] { 0, 3, 1000, -1000, 3 }; RationalInterpolation method = new RationalInterpolation(); method.Init(t, x); for(int i = 0; i < t.Length; i++) { Assert.AreEqual(x[i], method.Interpolate(t[i]), "Exact Point " + i.ToString()); } // Maple: "with(CurveFitting);" // Maple: "evalf(subs({x=0.1},RationalInterpolation([[0,0],[1,3],[3,1000],[4,-1000], [5,3]], x)),20);" NumericAssert.AreAlmostEqual(.19389203383553566255, method.Interpolate(0.1), 1e-14, "A 0.1"); NumericAssert.AreAlmostEqual(.88132900698869875369, method.Interpolate(0.4), 1e-14, "A 0.4"); NumericAssert.AreAlmostEqual(3.5057665681580626913, method.Interpolate(1.1), 1e-15, "A 1.1"); NumericAssert.AreAlmostEqual(1548.7666642693586902, method.Interpolate(3.01), 1e-13, "A 3.01"); NumericAssert.AreAlmostEqual(3362.2564334253633516, method.Interpolate(3.02), 1e-13, "A 3.02"); NumericAssert.AreAlmostEqual(-22332.603641443806014, method.Interpolate(3.03), 1e-12, "A 3.03"); NumericAssert.AreAlmostEqual(-440.30323769822443789, method.Interpolate(3.1), 1e-14, "A 3.1"); NumericAssert.AreAlmostEqual(-202.42421196280566349, method.Interpolate(3.2), 1e-14, "A 3.2"); NumericAssert.AreAlmostEqual(21.208249625210155439, method.Interpolate(4.5), 1e-14, "A 4.5"); NumericAssert.AreAlmostEqual(-4.8936986959784751517, method.Interpolate(10.0), 1e-13, "A 10.0"); NumericAssert.AreAlmostEqual(-3.6017584308603731307, method.Interpolate(-10.0), 1e-13, "A -10.0"); }
public void TestInterpolationMethod_RationalWithPoles() { double[] t = new double[] { 0, 1, 3, 4, 5 }; double[] x = new double[] { 0, 3, 1000, -1000, 3 }; RationalInterpolation method = new RationalInterpolation(); method.Init(t, x); for(int i = 0; i < t.Length; i++) { Assert.That(method.Interpolate(t[i]), Is.EqualTo(x[i]), "Exact Point " + i.ToString()); } // Maple: "with(CurveFitting);" // Maple: "evalf(subs({x=0.1},RationalInterpolation([[0,0],[1,3],[3,1000],[4,-1000], [5,3]], x)),20);" Assert.That(method.Interpolate(0.1), NumericIs.AlmostEqualTo(.19389203383553566255, 1e-14), "A 0.1"); Assert.That(method.Interpolate(0.4), NumericIs.AlmostEqualTo(.88132900698869875369, 1e-14), "A 0.4"); Assert.That(method.Interpolate(1.1), NumericIs.AlmostEqualTo(3.5057665681580626913, 1e-15), "A 1.1"); Assert.That(method.Interpolate(3.01), NumericIs.AlmostEqualTo(1548.7666642693586902, 1e-13), "A 3.01"); Assert.That(method.Interpolate(3.02), NumericIs.AlmostEqualTo(3362.2564334253633516, 1e-13), "A 3.02"); Assert.That(method.Interpolate(3.03), NumericIs.AlmostEqualTo(-22332.603641443806014, 1e-12), "A 3.03"); Assert.That(method.Interpolate(3.1), NumericIs.AlmostEqualTo(-440.30323769822443789, 1e-14), "A 3.1"); Assert.That(method.Interpolate(3.2), NumericIs.AlmostEqualTo(-202.42421196280566349, 1e-14), "A 3.2"); Assert.That(method.Interpolate(4.5), NumericIs.AlmostEqualTo(21.208249625210155439, 1e-14), "A 4.5"); Assert.That(method.Interpolate(10.0), NumericIs.AlmostEqualTo(-4.8936986959784751517, 1e-13), "A 10.0"); Assert.That(method.Interpolate(-10.0), NumericIs.AlmostEqualTo(-3.6017584308603731307, 1e-13), "A -10.0"); // Test Linear Case for(int k = 2; k < 6; k++) { double[] linx, liny, linxtest, linytest; BuildLinearCase(2, k, out linx, out liny, out linxtest, out linytest); IInterpolationMethod linearMethod = Interpolation.CreateRational(linx, liny); for(int i = 0; i < linxtest.Length; i++) { // very weak test, but rational with poles is incredibly bad in the linear case Assert.That(linearMethod.Interpolate(linxtest[i]), Is.Not.NaN, String.Format("Linear k={0} i={1}", k, i)); } } }