Artemis.Engine.Maths.SpecialFunctions.JN C# (CSharp) Метод

JN() публичный статический Метод

Returns the Bessel function of order n of the specified number.
public static JN ( int n, double x ) : double
n int
x double
Результат double
        public static double JN(int n, double x)
        {
            int j, m;
            double ax, bj, bjm, bjp, sum, tox, ans;
            bool jsum;

            double ACC = 40.0;
            double BIGNO = 1.0e+10;
            double BIGNI = 1.0e-10;

            if (n == 0) return J0(x);
            if (n == 1) return J1(x);

            ax = Math.Abs(x);
            if (ax == 0.0) return 0.0;
            else if (ax > (double) n)
            {
                tox = 2.0/ax;
                bjm = J0(ax);
                bj = J1(ax);
                for (j = 1; j < n; j++)
                {
                    bjp = j*tox*bj - bjm;
                    bjm = bj;
                    bj = bjp;
                }
                ans = bj;
            }
            else
            {
                tox = 2.0/ax;
                m = 2 * ((n + (int)Math.Sqrt(ACC * n)) / 2);
                jsum = false;
                bjp = ans = sum = 0.0;
                bj = 1.0;
                for (j = m; j > 0; j--)
                {
                    bjm = j*tox*bj - bjp;
                    bjp = bj;
                    bj = bjm;
                    if (Math.Abs(bj) > BIGNO)
                    {
                        bj *= BIGNI;
                        bjp *= BIGNI;
                        ans *= BIGNI;
                        sum *= BIGNI;
                    }
                    if (jsum) sum += bj;
                    jsum = !jsum;
                    if (j == n) ans = bjp;
                }
                sum = 2.0*sum - bj;
                ans /= sum;
            }
            return x < 0.0 && n%2 == 1 ? -ans : ans;
        }