Esempio n. 1
0
        public void LinearInterpolatorTests_CanExtrapolate()
        {
            IInterpolator1D interp = new LinearInterpolator(new double[] { 5, 10 }, new double[] { 5, 10 });

            Assert.Equal(0, interp.Interpolate(0.0));
            Assert.Equal(7.5, interp.Interpolate(7.5));
            Assert.Equal(100, interp.Interpolate(100));
            Assert.Equal(1, interp.FirstDerivative(0));
            Assert.Equal(1, interp.FirstDerivative(5));
            Assert.Equal(1, interp.FirstDerivative(100));
            Assert.Equal(0, interp.SecondDerivative(0));
            Assert.Equal(1, interp.SecondDerivative(5));
            Assert.Equal(0, interp.SecondDerivative(100));

            interp = new LinearInterpolatorFlatExtrap(new double[] { 5, 10 }, new double[] { 5, 10 });
            Assert.Equal(5, interp.Interpolate(0.0));
            Assert.Equal(7.5, interp.Interpolate(7.5));
            Assert.Equal(10, interp.Interpolate(100));
            Assert.Equal(0, interp.FirstDerivative(0));
            Assert.Equal(1, interp.FirstDerivative(5));
            Assert.Equal(0, interp.FirstDerivative(100));
            Assert.Equal(0, interp.SecondDerivative(0));
            Assert.Equal(0.5, interp.SecondDerivative(5));
            Assert.Equal(0, interp.SecondDerivative(100));
        }
Esempio n. 2
0
        public void CanInterpolateFact()
        {
            var interp = new LinearInterpolator();

            interp = new LinearInterpolator(new double[] { 0, 10 }, new double[] { 10, 10 });
            Assert.Equal(10.0, interp.Interpolate(100.0));
            var i2 = interp.Bump(1, 10, false);

            Assert.Equal(110.0, i2.Interpolate(100.0));
            interp.Bump(1, 10, true);
            Assert.Equal(110.0, interp.Interpolate(100.0));

            var interp2 = new LinearInterpolatorFlatExtrap();

            interp2 = new LinearInterpolatorFlatExtrap(new double[] { 0, 10 }, new double[] { 10, 10 });
            Assert.Equal(10.0, interp2.Interpolate(100.0));
            var i4 = interp2.Bump(1, 10, false);

            Assert.Equal(20, i4.Interpolate(100.0));
            interp2.Bump(1, 10, true);
            Assert.Equal(20, interp2.Interpolate(100.0));

            var interp3 = new LinearInterpolatorFlatExtrapNoBinSearch();

            interp3 = new LinearInterpolatorFlatExtrapNoBinSearch(new double[] { 0, 10 }, new double[] { 10, 10 });
            Assert.Equal(10.0, interp3.Interpolate(100.0));
            var i5 = interp3.Bump(1, 10, false);

            Assert.Equal(20, i5.Interpolate(100.0));
            interp3.Bump(1, 10, true);
            Assert.Equal(20, interp3.Interpolate(100.0));
        }