private static MultiPrecision <N> BesselKIntegerNuNearZero(int n, MultiPrecision <N> z)
        {
            Consts.BesselIntegerFiniteTermCoef      finite_table      = Consts.Bessel.IntegerFiniteTermCoef(n);
            Consts.BesselIntegerConvergenceTermCoef convergence_table = Consts.Bessel.IntegerConvergenceTermCoef(n);

            MultiPrecision <Double <N> > z_ex = z.Convert <Double <N> >();
            MultiPrecision <Double <N> > u    = 1;
            MultiPrecision <Double <N> > w    = z_ex * z_ex;

            MultiPrecision <Double <N> > r
                = MultiPrecisionSandbox <Double <N> > .BesselINearZero(n, z_ex).Convert <Double <N> >() * MultiPrecision <Double <N> > .Log(z_ex / 2);

            long r_exponent = r.Exponent;

            MultiPrecision <Double <N> > m = MultiPrecision <Double <N> > .Pow(z_ex / 2, n);

            MultiPrecision <Double <N> > x = 0, y = 0;

            Sign sign = Sign.Plus;

            for (int k = 0; k < int.MaxValue; k++, u *= w)
            {
                MultiPrecision <Double <N> > c = u * convergence_table.Value(k);

                y += c;

                if (k < n)
                {
                    if (sign == Sign.Plus)
                    {
                        x   += u * finite_table.Value(k);
                        sign = Sign.Minus;
                    }
                    else
                    {
                        x   -= u * finite_table.Value(k);
                        sign = Sign.Plus;
                    }
                    continue;
                }

                if (r.Exponent < -MultiPrecision <N> .Bits * 8 && (c.IsZero || y.Exponent - c.Exponent > MultiPrecision <Plus1 <N> > .Bits))
                {
                    break;
                }

                if (c.IsZero || Math.Min(y.Exponent - c.Exponent, r_exponent - c.Exponent - m.Exponent) > MultiPrecision <Double <N> > .Bits)
                {
                    break;
                }
            }

            MultiPrecision <Double <N> > d = (x / m + ((n & 1) == 0 ? 1 : -1) * (y * m - 2 * r)) / 2;

            return(d.Convert <N>());
        }
        private static MultiPrecision <N> BesselYIntegerNuNearZero(int n, MultiPrecision <N> z)
        {
            Consts.BesselIntegerFiniteTermCoef      finite_table      = Consts.Bessel.IntegerFiniteTermCoef(n);
            Consts.BesselIntegerConvergenceTermCoef convergence_table = Consts.Bessel.IntegerConvergenceTermCoef(n);

            MultiPrecision <Double <N> > z_ex = z.Convert <Double <N> >();
            MultiPrecision <Double <N> > u    = 1;
            MultiPrecision <Double <N> > w    = z_ex * z_ex;

            MultiPrecision <Double <N> > r
                = 2 * BesselJNearZero(n, z).Convert <Double <N> >() * MultiPrecision <Double <N> > .Log(z_ex / 2);

            long r_exponent = MultiPrecision <Pow2.N4> .Sqrt(2 / (MultiPrecision <Pow2.N4> .PI * (z.Convert <Pow2.N4>() + MultiPrecision <Pow2.N4> .Point5))).Exponent;

            MultiPrecision <Double <N> > m = MultiPrecision <Double <N> > .Pow(z_ex / 2, n);

            MultiPrecision <Double <N> > x = 0, y = 0;

            Sign sign = Sign.Plus;

            for (int k = 0; k < int.MaxValue; k++, u *= w)
            {
                MultiPrecision <Double <N> > c = u * convergence_table.Value(k);

                if (sign == Sign.Plus)
                {
                    x   += c;
                    sign = Sign.Minus;
                }
                else
                {
                    x   -= c;
                    sign = Sign.Plus;
                }

                if (k < n)
                {
                    y += u * finite_table.Value(k);
                    continue;
                }

                if (c.IsZero || Math.Min(x.Exponent - c.Exponent, r_exponent - c.Exponent - m.Exponent) > MultiPrecision <Plus1 <N> > .Bits)
                {
                    break;
                }
            }

            MultiPrecision <Double <N> > d = (r - y / m - x * m) / MultiPrecision <Double <N> > .PI;

            return(d.Convert <N>());
        }
示例#3
0
        private static MultiPrecision <N> BesselKIntegerNuNearZero(int n, MultiPrecision <N> z)
        {
            Consts.BesselNearZeroCoef               nearzero_table    = Consts.Bessel.NearZeroCoef(n);
            Consts.BesselIntegerFiniteTermCoef      finite_table      = Consts.Bessel.IntegerFiniteTermCoef(n);
            Consts.BesselIntegerConvergenceTermCoef convergence_table = Consts.Bessel.IntegerConvergenceTermCoef(n);

            MultiPrecision <Double <N> > z_ex = z.Convert <Double <N> >();
            MultiPrecision <Double <N> > m = MultiPrecision <Double <N> > .Pow(z_ex / 2, n), inv_mm = 1 / (m * m);

            MultiPrecision <Double <N> > u = m, v = 2 * m * MultiPrecision <Double <N> > .Log(z_ex / 2);

            MultiPrecision <Double <N> > w = z_ex * z_ex;

            MultiPrecision <Double <N> > x = 0;
            bool probably_convergenced     = false;

            Sign sign = Sign.Plus;

            for (int k = 0; k < int.MaxValue; k++, u *= w, v *= w)
            {
                MultiPrecision <Double <N> > c_pos = u * convergence_table.Value(k);
                MultiPrecision <Double <N> > c_neg = v * nearzero_table.Value(k);
                MultiPrecision <Double <N> > c     = c_pos - c_neg;

                if ((n & 1) == 0)
                {
                    x += c;
                }
                else
                {
                    x -= c;
                }

                if (k < n)
                {
                    MultiPrecision <Double <N> > d = u * inv_mm * finite_table.Value(k);

                    if (sign == Sign.Plus)
                    {
                        x   += d;
                        sign = Sign.Minus;
                    }
                    else
                    {
                        x   -= d;
                        sign = Sign.Plus;
                    }
                }
                else
                {
                    if (c.IsZero || x.Exponent - c.Exponent > MultiPrecision <Plus1 <N> > .Bits)
                    {
                        if (probably_convergenced)
                        {
                            break;
                        }
                        else
                        {
                            probably_convergenced = true;
                            continue;
                        }
                    }
                    probably_convergenced = false;
                }
            }

            MultiPrecision <N> y = x.Convert <N>() / 2;

            return(y);
        }