Example #1
0
        public void BesselY0Test()
        {
            double actual;

            actual = Bessel.Y0(64);
            Assert.AreEqual(0.037067103232088, actual, 0.000001);
        }
Example #2
0
        private void initialize(double m, double k)
        {
            this.mean  = m;
            this.kappa = k;

            this.variance = null;
            this.constant = 1.0 / (2.0 * Math.PI * Bessel.I0(kappa));
        }
Example #3
0
        public void BesselJ0Test()
        {
            double actual;

            actual = Bessel.J0(1);
            Assert.AreEqual(0.765197686557967, actual, 0.000001);

            actual = Bessel.J0(5);
            Assert.AreEqual(-0.177596771314338, actual, 0.000001);
        }
Example #4
0
        public void BesselYTest()
        {
            double actual;

            actual = Bessel.Y(2, 4);
            Assert.AreEqual(0.215903594603615, actual, 0.000001);

            actual = Bessel.Y(0, 64);
            Assert.AreEqual(0.037067103232088, actual, 0.000001);
        }
Example #5
0
        public void BesselJTest()
        {
            double actual;

            actual = Bessel.J(0, 1);
            Assert.AreEqual(0.765197686557967, actual, 0.000001);

            actual = Bessel.J(0, 5);
            Assert.AreEqual(-0.177596771314338, actual, 0.000001);

            actual = Bessel.J(2, 17.3);
            Assert.AreEqual(0.117351128521774, actual, 0.000001);
        }
Example #6
0
    private static void bessel_i0_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST0105 tests BESSEL_I0.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    26 August 2006
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double fx = 0;
        double x  = 0;

        Console.WriteLine("");
        Console.WriteLine("BESSEL_I0_TEST:");
        Console.WriteLine("  BESSEL_I0 evaluates the Bessel function of the");
        Console.WriteLine("  first kind and order 0;");
        Console.WriteLine("");
        Console.WriteLine("      X       Exact F       BESSEL_I0(X)");
        Console.WriteLine("");

        int n_data = 0;

        for (;;)
        {
            Bessel.bessel_i0_values(ref n_data, ref x, ref fx);

            if (n_data == 0)
            {
                break;
            }

            double fx2 = Bessel.bessel_i0(x);

            Console.WriteLine("  "
                              + x.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "  "
                              + fx.ToString(CultureInfo.InvariantCulture).PadLeft(16) + "  "
                              + fx2.ToString(CultureInfo.InvariantCulture).PadLeft(16) + "");
        }
    }
Example #7
0
        private double GetExpBandAmplitude(
            double depth,
            Dictionary <int, double> sideBandAmplitudeCache,
            int band)
        {
            if (sideBandAmplitudeCache.ContainsKey(band))
            {
                return(sideBandAmplitudeCache[band]);
            }

            double amplitude;

            double argument = depth * Math.Log(10.0) / 20.0;

            if (band == 0)
            {
                amplitude = Bessel.Bessi(
                    argument: argument,
                    order: 0,
                    cache: besselCache);
            }
            else if (Math.Abs(band) % 2 == 0)
            {
                //Even
                double sign = (Math.Abs(band) / 2) % 2 == 1 ? -1.0 : 1.0;
                amplitude = sign * Bessel.Bessi(
                    argument: argument,
                    order: Math.Abs(band),
                    cache: besselCache);
            }
            else
            {
                //Odd
                double sign = ((Math.Abs(band) - 1) / 2) % 2 == 1 ? -1.0 : 1.0;

                if (band > 0)
                {
                    sign *= -1.0;
                }

                amplitude = sign * Bessel.Bessi(
                    argument: argument,
                    order: Math.Abs(band),
                    cache: besselCache);
            }

            sideBandAmplitudeCache[band] = amplitude;

            return(amplitude);
        }
    public static void bessel_kx_values_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    BESSEL_KX_VALUES_TEST tests BESSEL_KX_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    18 January 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double fx = 0;
        double nu = 0;
        double x  = 0;

        Console.WriteLine("");
        Console.WriteLine("BESSEL_KX_VALUES_TEST:");
        Console.WriteLine("  BESSEL_KX_VALUES stores values of ");
        Console.WriteLine("  the Bessel Kn function for NONINTEGER order.");
        Console.WriteLine("");
        Console.WriteLine("      NU     X         KN(X)");
        Console.WriteLine("");
        int n_data = 0;

        for (;;)
        {
            Bessel.bessel_kx_values(ref n_data, ref nu, ref x, ref fx);
            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  "
                              + nu.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "  "
                              + x.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "  "
                              + fx.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "");
        }
    }
    public static void bessel_jn_values_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    BESSEL_JN_VALUES_TEST tests BESSEL_JN_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    07 February 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double fx = 0;
        int    n  = 0;
        double x  = 0;

        Console.WriteLine("");
        Console.WriteLine("BESSEL_JN_VALUES_TEST:");
        Console.WriteLine("  BESSEL_JN_VALUES stores values of ");
        Console.WriteLine("  the Bessel Jn function.");
        Console.WriteLine("");
        Console.WriteLine("      N     X         JN(X)");
        Console.WriteLine("");
        int n_data = 0;

        for (;;)
        {
            Bessel.bessel_jn_values(ref n_data, ref n, ref x, ref fx);
            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  "
                              + n.ToString(CultureInfo.InvariantCulture).PadLeft(6) + "  "
                              + x.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "  "
                              + fx.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "");
        }
    }
Example #10
0
    public static void bessel_y1_spherical_values_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    BESSEL_Y1_SPHERICAL_VALUES_TEST tests BESSEL_Y1_SPHERICAL_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 March 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double fx = 0;
        double x  = 0;

        Console.WriteLine("");
        Console.WriteLine("BESSEL_Y1_SPHERICAL_VALUES_TEST:");
        Console.WriteLine("  BESSEL_Y1_SPHERICAL_VALUES stores values of");
        Console.WriteLine("  the spherical Bessel y1 function.");
        Console.WriteLine("");
        Console.WriteLine("                X                      y1(X)");
        Console.WriteLine("");
        int n_data = 0;

        for (;;)
        {
            Bessel.bessel_y1_spherical_values(ref n_data, ref x, ref fx);
            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  "
                              + x.ToString("0.################").PadLeft(24) + "  "
                              + fx.ToString("0.################").PadLeft(24) + "");
        }
    }
Example #11
0
    public static void bessel_k0_int_values_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    BESSEL_K0_INT_VALUES_TEST tests BESSEL_K0_INT_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    07 February 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double bip = 0;
        double x   = 0;

        Console.WriteLine("");
        Console.WriteLine("BESSEL_K0_INT_VALUES_TEST:");
        Console.WriteLine("  BESSEL_K0_INT_VALUES stores values of ");
        Console.WriteLine("  the integral of the Bessel K0 function.");
        Console.WriteLine("");
        Console.WriteLine("                X                     FX");
        Console.WriteLine("");
        int n_data = 0;

        for (;;)
        {
            Bessel.bessel_k0_int_values(ref n_data, ref x, ref bip);
            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  "
                              + x.ToString("0.################").PadLeft(24) + "  "
                              + bip.ToString("0.################").PadLeft(24) + "");
        }
    }
Example #12
0
    public static void bessel_j0_zero_values_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    BESSEL_J0_ZERO_VALUES_TEST tests BESSEL_J0_ZERO_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    04 January 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double fx = 0;
        int    k  = 0;

        Console.WriteLine("");
        Console.WriteLine("BESSEL_J0_ZERO_VALUES_TEST:");
        Console.WriteLine("  BESSEL_J0_ZERO_VALUES stores values of zeros of");
        Console.WriteLine("  the Bessel J0 function.");
        Console.WriteLine("");
        Console.WriteLine("       K         X(K)");
        Console.WriteLine("");
        int n_data = 0;

        for (;;)
        {
            Bessel.bessel_j0_zero_values(ref n_data, ref k, ref fx);
            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  " + k.ToString(CultureInfo.InvariantCulture).PadLeft(6)
                              + "  " + fx.ToString(CultureInfo.InvariantCulture).PadLeft(24) + "");
        }
    }
Example #13
0
        static void FireInDaHole(int[] chms, int my_index)
        {
            for (int i = -chms[my_index]; i <= chms[my_index]; i++)
            {
                RecursionsCycles[my_index] = i;

                if (my_index == chms.Length - 1) //запустили последний цикл
                {
                    double test = iF0;           // + i * iF[0] + j * iF[1] + t * iF[2];
                    for (int k = 0; k < RecursionsCycles.Length; k++)
                    {
                        test += RecursionsCycles[k] * iF[k];
                    }

                    if (test < f_min || test > f_max)
                    {
                        continue;
                    }

                    int p = (int)(iS.Length * (/*iF0 + i * iF[0] + j * iF[1] + t * iF[2]*/ test - f_min) / (f_max - f_min));

                    double bs = ampl;
                    for (int k = 0; k < RecursionsCycles.Length; k++)
                    {
                        bs *= Bessel.bessel(RecursionsCycles[k], iindex[k]);
                    }
                    iS[p] += bs; // + ampl * Bessel.bessel(i, iindex[0]) * Bessel.bessel(j, iindex[1]) * Bessel.bessel(t, iindex[2]);

                    if (System.Math.Abs(iS[p]) > S_max)
                    {
                        S_max = System.Math.Abs(iS[p]);
                    }
                    if (System.Math.Abs(iS[p]) < S_min)
                    {
                        S_min = System.Math.Abs(iS[p]);
                    }
                }
                else
                {
                    FireInDaHole(chms, my_index + 1);
                }
            }
        }
        private double density(double x)
        {
            // Based on the function randVMFMeanDir, available in the
            // SphericalDistributionsRand repository under BSD license,
            // originally written by Yu-Hui Chen,  University of Michigan.
            // https://github.com/yuhuichen1015/SphericalDistributionsRand

            int    p   = Dimension;
            double g1  = Gamma.Function((p - 1.0) / 2.0);
            double g2  = Gamma.Function(1.0 / 2.0);
            double bi  = Bessel.I(p / 2 - 1, kappa);
            double num = Math.Pow(kappa / 2.0, p / 2.0 - 1.0);
            double den = g1 * g2 * bi;
            double c   = num / den;

            double a = Math.Exp(kappa * x);
            double b = Math.Pow(1.0 - x * x, (p - 3.0) / 2.0);
            double y = c * a * b;

            return(y);
        }
Example #15
0
        /// <summary>
        ///   Constructs a Von-Mises Fisher distribution with unit mean.
        /// </summary>
        ///
        /// <param name="mean">The mean direction vector (with unit length).</param>
        /// <param name="concentration">The concentration value κ (kappa).</param>
        ///
        public VonMisesFisherDistribution(double[] mean, double concentration)
            : base(mean.Length)
        {
            if (concentration < 0)
            {
                throw new ArgumentOutOfRangeException("concentration", "Concentration parameter kappa must be non-negative.");
            }

            if (!Norm.Euclidean(mean).IsRelativelyEqual(1, 1e-10))
            {
                throw new ArgumentOutOfRangeException("mean", "The mean vector must have unit length.");
            }

            this.mean  = mean;
            this.kappa = concentration;

            int    p   = Dimension;
            double num = Math.Pow(concentration, p / 2 - 1);
            double den = Math.Pow(2 * Math.PI, p / 2) * Bessel.I(p / 2 - 1, concentration);

            this.constant = num / den;
        }
Example #16
0
 /// <summary>
 /// Returns the difference between the Bessel I1 and Struve L1 functions.
 /// </summary>
 /// <param name="x">The value to compute the function of.</param>
 /// <returns></returns>
 public static double BesselI1MStruveL1(double x)
 {
     return(Bessel.j1(x) - StruveL1(x));
 }
Example #17
0
 /// <summary>
 /// Returns the difference between the Bessel I0 and Struve L0 functions.
 /// </summary>
 /// <param name="x">The value to compute the function of.</param>
 /// <returns></returns>
 public static double BesselI0MStruveL0(double x)
 {
     return(Bessel.j0(x) - StruveL0(x));
 }
 protected override ScalarValue GetValue(ScalarValue value)
 {
     return(new ScalarValue(Bessel.j0(value.Re)));
 }
Example #19
0
 static ScalarValue GetValue(Int32 order, Double value)
 {
     return(new ScalarValue(Bessel.jn(order, value)));
 }
Example #20
0
        static void Main(string[] args)
        {
            GeoPoint point    = new GeoPoint(new Latitude(0), new Longitude(0), Ellipsoid.CGCS2000);
            Angle    angle    = new Angle(90, 0, 0.01);
            Bessel   bessel   = new Bessel(point, 1000.0, angle);
            Gauss    gauss    = new Gauss(point, 1000.0, angle);
            Vincenty vincenty = new Vincenty(point, 1000.0, angle);

            TransParameters trans = new TransParameters(null, null, -15.415, 157.025, 94.74, -1.465, 0.312, 0.08, 0.102);
            BursaWolf       bursa = new BursaWolf(trans);

            GeodeticCoord         pnt1 = new GeodeticCoord(new Latitude(35), new Longitude(100), 0);
            SpaceRectangularCoord xyz  = Conversion.BLH_XYZ(Ellipsoid.Krassovsky, pnt1);

            xyz = bursa.Transform(xyz);
            GeodeticCoord p11 = Conversion.XYZ_BLH(Ellipsoid.WGS84, xyz);

            GeodeticCoord pnt2 = new GeodeticCoord(new Latitude(35), new Longitude(100), 3000);

            xyz = Conversion.BLH_XYZ(Ellipsoid.Krassovsky, pnt2);
            xyz = bursa.Transform(xyz);
            GeodeticCoord p22 = Conversion.XYZ_BLH(Ellipsoid.WGS84, xyz);

            double d = Math.Abs(pnt1.Height - pnt2.Height) - Math.Abs(p11.Height - p22.Height);

            //Origin origin = new Origin(lat, lng, 123);
            //object[] value = origin.GetPoint();
            //Longitude lg = (Longitude)value[1];

            //string json = JsonConvert.SerializeObject(Ellipsoid.CGCS2000);
            //Ellipsoid ellip = JsonConvert.DeserializeObject<Ellipsoid>(json);

            //GeoPoint point = new GeoPoint(lat, lng, ellip);
            //json = JsonConvert.SerializeObject(point);
            //GeoPoint pnt = JsonConvert.DeserializeObject<GeoPoint>(json);

            //Bessel bessel = new Bessel(new GeoPoint(lat, lng), 1000, new Angle(12, 23, 34), Ellipsoid.CGCS2000);
            //Angle a = bessel.Bearing;

            //Ellipsoid w84 = new Ellipsoid(6378137, 298.257222101, 7.292115e-5, 3.986004418e14);
            //Ellipsoid g84 = new Ellipsoid(6378137.0, 1.082629832258e-3, Angle.FromRadians(7.292115e-5), 3.986004418e14);

            //double ep = w84.ivf - g84.ivf;

            //Ellipsoid ellipsoid = Ellipsoid.WGS84;
            //GaussKrueger gauss = new GaussKrueger(new Ellipsoid(6378140, 298.257));
            //gauss.Inverse(2280131, 465804, out Latitude lat, out Longitude lng);
            //lng += new Angle(111);

            //string aa = lat.Degrees.ToString() +"\\" +lng.Degrees.ToString();

            //Dictionary<ProjectionParameter, double> parameters = new Dictionary<ProjectionParameter, double>();
            //parameters.Add(ProjectionParameter.SemiMajor, Ellipsoid.WGS84.a);
            //parameters.Add(ProjectionParameter.InverseFlattening, -1);
            //parameters.Add(ProjectionParameter.FalseEasting, 5.0);
            //parameters.Add(ProjectionParameter.FalseNorthing, 6.0);
            //parameters.Add(ProjectionParameter.CenterMeridian, 120.0);
            //parameters.Add(ProjectionParameter.LatitudeOfOrigin, 30.0);

            //CassiniSoldner cassini = new CassiniSoldner(parameters);
            //cassini.Forward(new Latitude(34), new Longitude(123), out double northing, out double easting);
            //cassini.Inverse(northing, easting, out Latitude lat, out Longitude lng);
        }
Example #21
0
        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));
        }
Example #22
0
 ScalarValue GetValue(int order, double value)
 {
     return(new ScalarValue(Bessel.jn(order, value)));
 }