Beispiel #1
0
            protected void UpdateInterpolation()
            {
                int count = _keyFrames.Count;
                var xs    = new double[count];
                var ys    = new double[count];

                for (int i = 0; i < count; ++i)
                {
                    xs[i] = (double)_keyFrames[i].time;
                    ys[i] = (double)_keyFrames[i].value;
                }
                if (count <= 1)
                {
                    _interpolation = StepInterpolation.Interpolate(xs, ys);
                }
                else if (count <= 2)
                {
                    _interpolation = LinearSpline.Interpolate(xs, ys);
                }
                else if (count <= 3)
                {
                    _interpolation = MathNet.Numerics.Interpolate.Polynomial(xs, ys);
                }
                else if (count <= 4)
                {
                    _interpolation = CubicSpline.InterpolateNatural(xs, ys);
                }
                else
                {
                    _interpolation = CubicSpline.InterpolateAkima(xs, ys);
                }
            }
        public void FitsAtSamplePoints()
        {
            IInterpolation ip = new StepInterpolation(_t, _y);

            for (int i = 0; i < _y.Length; i++)
            {
                Assert.AreEqual(_y[i], ip.Interpolate(_t[i]), "A Exact Point " + i);
            }
        }
        public void FirstDerivative()
        {
            IInterpolation ip = new StepInterpolation(_t, _y);

            Assert.That(ip.Differentiate(-3.0), Is.EqualTo(0.0));
            Assert.That(ip.Differentiate(-2.0), Is.EqualTo(double.NaN));
            Assert.That(ip.Differentiate(-1.5), Is.EqualTo(0.0));
            Assert.That(ip.Differentiate(-1.0), Is.EqualTo(double.NaN));
            Assert.That(ip.Differentiate(-0.5), Is.EqualTo(0.0));
            Assert.That(ip.Differentiate(0.0), Is.EqualTo(double.NaN));
            Assert.That(ip.Differentiate(0.5), Is.EqualTo(0.0));
            Assert.That(ip.Differentiate(1.0), Is.EqualTo(double.NaN));
            Assert.That(ip.Differentiate(2.0), Is.EqualTo(double.NaN));
            Assert.That(ip.Differentiate(3.0), Is.EqualTo(double.NaN));
            Assert.That(ip.Differentiate(4.0), Is.EqualTo(0.0));
        }
        public void DefiniteIntegral()
        {
            IInterpolation ip = new StepInterpolation(_t, _y);

            Assert.That(ip.Integrate(-3.0, -2.0), Is.EqualTo(0.0));
            Assert.That(ip.Integrate(-2.0, -1.0), Is.EqualTo(1.0));
            Assert.That(ip.Integrate(-1.0, 0.0), Is.EqualTo(2.0));
            Assert.That(ip.Integrate(0.0, 1.0), Is.EqualTo(-1.0));
            Assert.That(ip.Integrate(1.0, 2.0), Is.EqualTo(0.0));
            Assert.That(ip.Integrate(2.0, 3.0), Is.EqualTo(1.0));
            Assert.That(ip.Integrate(3.0, 4.0), Is.EqualTo(0.0));
            Assert.That(ip.Integrate(0.0, 4.0), Is.EqualTo(0.0));
            Assert.That(ip.Integrate(-3.0, -1.0), Is.EqualTo(1.0));
            Assert.That(ip.Integrate(-3.0, 4.0), Is.EqualTo(3.0));
            Assert.That(ip.Integrate(0.5, 1.5), Is.EqualTo(-0.5));
            Assert.That(ip.Integrate(-1.5, -0.5), Is.EqualTo(1.5));
            Assert.That(ip.Integrate(3.0, 4.0), Is.EqualTo(0.0));
        }
Beispiel #5
0
 /// <summary>
 /// Create a step-interpolation based on arbitrary points.
 /// </summary>
 /// <param name="points">The sample points t.</param>
 /// <param name="values">The sample point values x(t).</param>
 /// <returns>
 /// An interpolation scheme optimized for the given sample points and values,
 /// which can then be used to compute interpolations and extrapolations
 /// on arbitrary points.
 /// </returns>
 /// <remarks>
 /// if your data is already sorted in arrays, consider to use
 /// MathNet.Numerics.Interpolation.StepInterpolation.InterpolateSorted
 /// instead, which is more efficient.
 /// </remarks>
 public static IInterpolation Step(IEnumerable <double> points, IEnumerable <double> values)
 {
     return(StepInterpolation.Interpolate(points, values));
 }
 public virtual double Interpolate_Step(double[] x, double[] y, double xValue)
 {
     return(StepInterpolation.Interpolate(x, y).Interpolate(xValue));
 }
 public void FewSamples()
 {
     Assert.That(() => StepInterpolation.Interpolate(new double[0], new double[0]), Throws.ArgumentException);
     Assert.That(StepInterpolation.Interpolate(new[] { 1.0 }, new[] { 2.0 }).Interpolate(1.0), Is.EqualTo(2.0));
 }