コード例 #1
0
 static ScalarValue GetValue(Int32 order, Double value)
 {
     return(new ScalarValue(Bessel.jn(order, value)));
 }
コード例 #2
0
ファイル: YlmFunction.cs プロジェクト: marcusanth/YAMP
        static double Pl(int l, double x)
        {
            if (l == 0)
            {
                return(1.0);
            }
            else if (l == 1)
            {
                return(x);
            }
            else if (l == 2)
            {
                return(0.5 * (3.0 * x * x - 1.0));
            }
            else if (x == 1.0)
            {
                return(1.0);
            }
            else if (x == -1.0)
            {
                return(l % 2 == 1 ? -1.0 : 1.0);
            }
            else if (l < 100000)
            {
                /* upward recurrence: l P_l = (2l-1) z P_{l-1} - (l-1) P_{l-2} */

                var p_ellm2 = 1.0;    /* P_0(x) */
                var p_ellm1 = x;      /* P_1(x) */
                var p_ell   = p_ellm1;
                var e_ellm2 = double.Epsilon;
                var e_ellm1 = Math.Abs(x) * double.Epsilon;
                var e_ell   = e_ellm1;

                for (int ell = 2; ell <= l; ell++)
                {
                    p_ell   = (x * (2 * ell - 1) * p_ellm1 - (ell - 1) * p_ellm2) / ell;
                    p_ellm2 = p_ellm1;
                    p_ellm1 = p_ell;
                    e_ell   = 0.5 * (Math.Abs(x) * (2 * ell - 1.0) * e_ellm1 + (ell - 1.0) * e_ellm2) / ell;
                    e_ellm2 = e_ellm1;
                    e_ellm1 = e_ell;
                }

                return(p_ell);
            }

            /*
             * Asymptotic expansion.
             * [Olver, p. 473]
             */
            double u   = l + 0.5;
            double th  = Math.Acos(x);
            double J0  = Bessel.j0(u * th);
            double Jm1 = Bessel.jn(-1, u * th);
            double pre;
            double B00;
            double c1;

            /*
             * B00 = 1/8 (1 - th cot(th) / th^2
             * pre = sqrt(th/sin(th))
             */
            if (th < 1.2207031250000000e-04)
            {
                B00 = (1.0 + th * th / 15.0) / 24.0;
                pre = 1.0 + th * th / 12.0;
            }
            else
            {
                double sin_th = Math.Sqrt(1.0 - x * x);
                double cot_th = x / sin_th;
                B00 = 1.0 / 8.0 * (1.0 - th * cot_th) / (th * th);
                pre = Math.Sqrt(th / sin_th);
            }

            c1 = th / u * B00;
            return(pre * (J0 + c1 * Jm1));
        }
コード例 #3
0
ファイル: BesselFunction.cs プロジェクト: bluntwcrackrap/YAMP
 ScalarValue GetValue(int order, double value)
 {
     return(new ScalarValue(Bessel.jn(order, value)));
 }