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

Polevl() public static method

Evaluates polynomial of degree N
public static Polevl ( double x, double coef, int n ) : double
x double
coef double
n int
return double
        public static double Polevl(double x, double[] coef, int n)
        {
            double ans;

            ans = coef[0];

            for (int i = 1; i <= n; i++)
                ans = ans * x + coef[i];

            return ans;
        }

Usage Example

コード例 #1
0
        /// <summary>
        ///   Gamma function as computed by Stirling's formula.
        /// </summary>
        ///
        public static double Stirling(double x)
        {
            double[] STIR =
            {
                7.87311395793093628397E-4,
                -2.29549961613378126380E-4,
                -2.68132617805781232825E-3,
                3.47222221605458667310E-3,
                8.33333333333482257126E-2,
            };

            double MAXSTIR = 143.01608;

            double w = 1.0 / x;
            double y = Math.Exp(x);

            w = 1.0 + w * Special.Polevl(w, STIR, 4);

            if (x > MAXSTIR)
            {
                double v = Math.Pow(x, 0.5 * x - 0.25);
                y = v * (v / y);
            }
            else
            {
                y = System.Math.Pow(x, x - 0.5) / y;
            }

            y = Constants.Sqrt2PI * y * w;
            return(y);
        }
All Usage Examples Of Accord.Math.Special::Polevl