// Return Exp(-Abs(y)) * J(v, z) where y = z.Imaginary public static Complex ScaledCbesj(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[] cyjr = new double[n]; double[] cyji = new double[n]; for (int i = 0; i < n; i++) { cyjr[i] = double.NaN; cyji[i] = double.NaN; } AmosHelper.zbesj(z.Real, z.Imaginary, v, kode, n, cyjr, cyji, ref nz, ref ierr); Complex cyj = new Complex(cyjr[0], cyji[0]); if (sign == -1) { if (!ReflectJY(ref cyj, v)) { double[] cyyr = new double[n]; double[] cyyi = new double[n]; double[] cworkr = new double[n]; double[] cworki = new double[n]; for (int i = 0; i < n; i++) { cyyr[i] = double.NaN; cyyi[i] = double.NaN; cworkr[i] = double.NaN; cworki[i] = double.NaN; } AmosHelper.zbesy(z.Real, z.Imaginary, v, kode, n, cyyr, cyyi, ref nz, cworkr, cworki, ref ierr); Complex cyy = new Complex(cyyr[0], cyyi[0]); cyj = RotateJY(cyj, cyy, v); } } return(cyj); }
// 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); }
// Returns Exp(zta) * d/dz Ai(z) where zta = (2/3) * z * Sqrt(z) public static Complex ScaledCairyPrime(Complex z) { int id = 1; int kode = 2; int nz = 0; int ierr = 0; double air = double.NaN; double aii = double.NaN; AmosHelper.zairy(z.Real, z.Imaginary, id, kode, ref air, ref aii, ref nz, ref ierr); return(new Complex(air, aii)); }
// Returns Exp(-axzta) * d/dz Bi(z) where zta = (2 / 3) * z * Sqrt(z) and axzta = Abs(zta.Real) public static Complex ScaledCbiryPrime(Complex z) { int id = 1; int kode = 2; int nz = 0; int ierr = 0; double bipr = double.NaN; double bipi = double.NaN; AmosHelper.zbiry(z.Real, z.Imaginary, id, kode, ref bipr, ref bipi, ref nz, ref ierr); return(new Complex(bipr, bipi)); }
// Returns Bi(z) public static Complex Cbiry(Complex z) { int id = 0; int kode = 1; int nz = 0; int ierr = 0; double bir = double.NaN; double bii = double.NaN; AmosHelper.zbiry(z.Real, z.Imaginary, id, kode, ref bir, ref bii, ref nz, ref ierr); return(new Complex(bir, bii)); }
// Returns K(v, z) public static Complex Cbesk(double v, Complex z) { if (double.IsNaN(v) || double.IsNaN(z.Real) || double.IsNaN(z.Imaginary)) { return(new Complex(double.NaN, double.NaN)); } if (v < 0) { //K_v == K_{-v} even for non-integer v v = -v; } int n = 1; int kode = 1; int nz = 0; int ierr = 0; double[] cykr = new double[n]; double[] cyki = new double[n]; for (int i = 0; i < n; i++) { cykr[i] = double.NaN; cyki[i] = double.NaN; } AmosHelper.zbesk(z.Real, z.Imaginary, v, kode, n, cykr, cyki, ref nz, ref ierr); Complex cyk = new Complex(cykr[0], cyki[0]); if (ierr == 1) { if (z.Real == 0.0 && z.Imaginary == 0.0) { cyk = new Complex(double.PositiveInfinity, 0); } } else if (ierr == 2) { if (z.Real >= 0 && z.Imaginary == 0) { //overflow cyk = new Complex(double.PositiveInfinity, 0); } } return(cyk); }
// Returns Exp(zta) * d/dz Ai(z) where zta = (2/3) * z * Sqrt(z) public static double ScaledCairyPrime(double z) { if (z < 0) { return(double.NaN); } int id = 1; int kode = 2; int nz = 0; int ierr = 0; double air = double.NaN; double aii = double.NaN; AmosHelper.zairy(z, 0.0, id, kode, ref air, ref aii, ref nz, ref ierr); return(air); }
// Returns Exp(z * j) * H2(n, z) where j = Sqrt(-1) public static Complex ScaledCbesh2(double v, Complex z) { if (double.IsNaN(v) || double.IsNaN(z.Real) || double.IsNaN(z.Imaginary)) { return(new Complex(double.NaN, double.NaN)); } if (v == 0 && z.Real == 0 && z.Imaginary == 0) { return(new Complex(double.NaN, double.NaN)); // ComplexInfinity } int n = 1; int kode = 2; int m = 2; int nz = 0; int ierr = 0; double[] cyhr = new double[n]; double[] cyhi = new double[n]; for (int i = 0; i < n; i++) { cyhr[i] = double.NaN; cyhi[i] = double.NaN; } int sign = 1; if (v < 0) { v = -v; sign = -1; } AmosHelper.zbesh(z.Real, z.Imaginary, v, kode, m, n, cyhr, cyhi, ref nz, ref ierr); Complex cyh = new Complex(cyhr[0], cyhi[0]); if (sign == -1) { cyh = Rotate(cyh, -v); } return(cyh); }
// 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); }
// Return Y(v, z) public static Complex Cbesy(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; Complex cyy; if (z.Real == 0 && z.Imaginary == 0) { //overflow cyy = new Complex(double.NegativeInfinity, 0); } else { double[] cyyr = new double[n]; double[] cyyi = new double[n]; double[] cworkr = new double[n]; double[] cworki = new double[n]; for (int i = 0; i < n; i++) { cyyr[i] = double.NaN; cyyi[i] = double.NaN; cworkr[i] = double.NaN; cworki[i] = double.NaN; } AmosHelper.zbesy(z.Real, z.Imaginary, v, kode, n, cyyr, cyyi, ref nz, cworkr, cworki, ref ierr); cyy = new Complex(cyyr[0], cyyi[0]); if (ierr == 2) { if (z.Real >= 0 && z.Imaginary == 0) { //overflow cyy = new Complex(double.NegativeInfinity, 0); } } } if (sign == -1) { if (!ReflectJY(ref cyy, v)) { double[] cyjr = new double[n]; double[] cyji = new double[n]; for (int i = 0; i < n; i++) { cyjr[i] = double.NaN; cyji[i] = double.NaN; } AmosHelper.zbesj(z.Real, z.Imaginary, v, kode, n, cyjr, cyji, ref nz, ref ierr); Complex cyj = new Complex(cyjr[0], cyji[0]); cyy = RotateJY(cyy, cyj, -v); } } return(cyy); }