Пример #1
0
            // Return Exp(-Abs(x)) * I(v, z) where x = z.Real
            public static Complex ScaledCbesi(double v, Complex z)
            {
                if (double.IsNaN(v) || double.IsNaN(z.Real) || double.IsNaN(z.Imaginary))
                {
                    return(new Complex(double.NaN, double.NaN));
                }

                int sign = 1;

                if (v < 0)
                {
                    v    = -v;
                    sign = -1;
                }

                int n    = 1;
                int kode = 2;
                int nz   = 0;
                int ierr = 0;

                double[] cyir = new double[n];
                double[] cyii = new double[n];
                for (int i = 0; i < n; i++)
                {
                    cyir[i] = double.NaN;
                    cyii[i] = double.NaN;
                }

                AmosHelper.zbesi(z.Real, z.Imaginary, v, kode, n, cyir, cyii, ref nz, ref ierr);
                Complex cyi = new Complex(cyir[0], cyii[0]);

                if (sign == -1)
                {
                    if (!ReflectI(cyi, v))
                    {
                        double[] cykr = new double[n];
                        double[] cyki = new double[n];
                        AmosHelper.zbesk(z.Real, z.Imaginary, v, kode, n, cykr, cyki, ref nz, ref ierr);
                        Complex cyk = new Complex(cykr[0], cyki[0]);

                        //adjust scaling to match zbesi
                        cyk = Rotate(cyk, -z.Imaginary / Math.PI);
                        if (z.Real > 0)
                        {
                            cyk = new Complex(cyk.Real * Math.Exp(-2 * z.Real), cyk.Imaginary * Math.Exp(-2 * z.Real));
                        }
                        //v -> -v
                        cyi = RotateI(cyi, cyk, v);
                    }
                }

                return(cyi);
            }
Пример #2
0
            // Returns I(v, z)
            public static Complex Cbesi(double v, Complex z)
            {
                if (double.IsNaN(v) || double.IsNaN(z.Real) || double.IsNaN(z.Imaginary))
                {
                    return(new Complex(double.NaN, double.NaN));
                }

                int sign = 1;

                if (v < 0)
                {
                    v    = -v;
                    sign = -1;
                }

                int n    = 1;
                int kode = 1;
                int nz   = 0;
                int ierr = 0;

                double[] cyir = new double[n];
                double[] cyii = new double[n];
                for (int i = 0; i < n; i++)
                {
                    cyir[i] = double.NaN;
                    cyii[i] = double.NaN;
                }

                AmosHelper.zbesi(z.Real, z.Imaginary, v, kode, n, cyir, cyii, ref nz, ref ierr);
                Complex cyi = new Complex(cyir[0], cyii[0]);

                if (ierr == 2)
                {
                    //overflow
                    if (z.Imaginary == 0 && (z.Real >= 0 || v == Math.Floor(v)))
                    {
                        if (z.Real < 0 && v / 2 != Math.Floor(v / 2))
                        {
                            cyi = new Complex(double.NegativeInfinity, 0);
                        }
                        else
                        {
                            cyi = new Complex(double.PositiveInfinity, 0);
                        }
                    }
                    else
                    {
                        cyi = ScaledCbesi(v * sign, z);
                        cyi = new Complex(cyi.Real * double.PositiveInfinity, cyi.Imaginary * double.PositiveInfinity);
                    }
                }

                if (sign == -1)
                {
                    if (!ReflectI(cyi, v))
                    {
                        double[] cykr = new double[n];
                        double[] cyki = new double[n];
                        AmosHelper.zbesk(z.Real, z.Imaginary, v, kode, n, cykr, cyki, ref nz, ref ierr);
                        Complex cyk = new Complex(cykr[0], cyki[0]);

                        cyi = RotateI(cyi, cyk, v);
                    }
                }

                return(cyi);
            }