public void CheckNaturalSplineMinMaxValuesPerformance() { //first generate the test data and spline double amplitude = 100; double ofset = 0; double period = 10; double decay = 0.1; double minX = -50; double maxX = 50; int points = 100000; var data = GenerateSplineData(amplitude, period, decay, minX, maxX, ofset, points); CubicSpline it = CubicSpline.InterpolateBoundaries(data.Item1, data.Item2, SplineBoundaryCondition.Natural, 0, SplineBoundaryCondition.Natural, 0); //start the time and calculate the min max values var t = DateTime.Now; var minMax = it.Extrema(); Assert.IsTrue(minMax.Item2.AlmostEqual(ofset, 0.3), "Expexted max value near ofset."); Assert.IsTrue(minMax.Item1.AlmostEqual(ofset + period / 2, 0.3) || minMax.Item1.AlmostEqual(ofset - period / 2, 0.3), "Expexted min value near ofset +- period/2."); //spit out the time it took to calculate Console.WriteLine("Extrema took: " + (DateTime.Now - t).TotalMilliseconds.ToString("000.00") + " ms for " + points.ToString() + " points."); //determine if the values are correct var sp = it.StationaryPoints(); foreach (var x in sp) { //check that the stationary point falls roughly at a half period Assert.IsTrue(Math.Abs((Math.Abs((x - ofset) * 2 / period) - Math.Round(Math.Abs(x - ofset) * 2 / period, 0))).AlmostEqual(0, 0.3), "Stationary point found outside of period/2 for x=" + x.ToString()); } }
public void NaturalSplineGetHorizontalDerivativeTValues() { CubicSpline it = CubicSpline.InterpolateBoundaries(_x, _z, SplineBoundaryCondition.SecondDerivative, -4.0, SplineBoundaryCondition.SecondDerivative, 4.0); var horizontalDerivatives = it.StationaryPoints(); //readonly double[] _x = { -4, -3, -2, -1, 0, 1, 2, 3, 4 }; //readonly double[] _z = { -7, 2, 5, 0, -3, -1, -4, 0, 6 }; Assert.AreEqual(4, horizontalDerivatives.Length, "Incorrect number of points with derivative value equal to 0"); Assert.IsTrue(horizontalDerivatives[0] >= -3 && horizontalDerivatives[0] <= -2, "Spline returns wrong t value: " + horizontalDerivatives[0] + " for first point"); Assert.IsTrue(horizontalDerivatives[1] >= -1 && horizontalDerivatives[1] <= 0, "Spline returns wrong t value: " + horizontalDerivatives[1] + " for second point"); Assert.IsTrue(horizontalDerivatives[2] >= 0 && horizontalDerivatives[2] <= 1, "Spline returns wrong t value: " + horizontalDerivatives[2] + " for third point"); Assert.IsTrue(horizontalDerivatives[3] >= 2 && horizontalDerivatives[3] <= 3, "Spline returns wrong t value: " + horizontalDerivatives[3] + " for fourth point"); Console.WriteLine("GetHorizontalDerivativeTValues checked out ok for cubic spline."); }