Accord.Math.Special.BSpline C# (CSharp) Method

BSpline() public static method

Computes the Basic Spline of order n
public static BSpline ( int n, double x ) : double
n int
x double
return double
        public static double BSpline(int n, double x)
        {
            // ftp://ftp.esat.kuleuven.ac.be/pub/SISTA/hamers/PhD_bhamers.pdf
            // http://sepwww.stanford.edu/public/docs/sep105/sergey2/paper_html/node5.html

            if (n == Int32.MaxValue)
                throw new ArgumentOutOfRangeException("n");


            double a = 1.0 / Special.Factorial(n);
            double c;

            bool positive = true;
            for (int k = 0; k <= n + 1; k++)
            {
                c = Binomial(n + 1, k) * Tools.TruncatedPower(x + (n + 1.0) / 2.0 - k, n);
                a += positive ? c : -c;
                positive = !positive;
            }

            return a;
        }
        #endregion