/// <summary>
 /// Create an Akima cubic spline interpolation based on arbitrary points.
 /// Akima splines are cubic splines which are stable to outliers.
 /// </summary>
 /// <param name="points">The sample points t. Supports both lists and arrays.</param>
 /// <param name="values">The sample point values x(t). Supports both lists and arrays.</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>
 public static IInterpolationMethod CreateAkimaCubicSpline(
     IList<double> points,
     IList<double> values)
 {
     AkimaSplineInterpolation method = new AkimaSplineInterpolation();
     method.Init(points, values);
     return method;
 }
        CreateAkimaCubicSpline(
            IList <double> points,
            IList <double> values)
        {
            AkimaSplineInterpolation method = new AkimaSplineInterpolation();

            method.Init(points, values);
            return(method);
        }
Esempio n. 3
0
        /// <summary>
        /// Run example
        /// </summary>
        /// <seealso cref="http://en.wikipedia.org/wiki/Spline_interpolation">Spline interpolation</seealso>
        public void Run()
        {
            // 1. Generate 10 samples of the function x*x-2*x on interval [0, 10]
            Console.WriteLine(@"1. Generate 10 samples of the function x*x-2*x on interval [0, 10]");
            double[] points;
            var values = SignalGenerator.EquidistantInterval(TargetFunction, 0, 10, 10, out points);
            Console.WriteLine();

            // 2. Create akima spline interpolation
            var method = new AkimaSplineInterpolation(points, values);
            Console.WriteLine(@"2. Create akima spline interpolation based on arbitrary points");
            Console.WriteLine();

            // 3. Check if interpolation support integration
            Console.WriteLine(@"3. Support integration = {0}", ((IInterpolation)method).SupportsIntegration);
            Console.WriteLine();

            // 4. Check if interpolation support differentiation
            Console.WriteLine(@"4. Support differentiation = {0}", ((IInterpolation)method).SupportsDifferentiation);
            Console.WriteLine();

            // 5. Differentiate at point 5.2
            Console.WriteLine(@"5. Differentiate at point 5.2 = {0}", method.Differentiate(5.2));
            Console.WriteLine();

            // 6. Integrate at point 5.2
            Console.WriteLine(@"6. Integrate at point 5.2 = {0}", method.Integrate(5.2));
            Console.WriteLine();

            // 7. Interpolate ten random points and compare to function results
            Console.WriteLine(@"7. Interpolate ten random points and compare to function results");
            var rng = new MersenneTwister(1);
            for (var i = 0; i < 10; i++)
            {
                // Generate random value from [0, 10]
                var point = rng.NextDouble() * 10;
                Console.WriteLine(@"Interpolate at {0} = {1}. Function({0}) = {2}", point.ToString("N05"), method.Interpolate(point).ToString("N05"), TargetFunction(point).ToString("N05"));
            }

            Console.WriteLine();
        }