c# - Bessel function of first kind from math.net -
i need utilize bessel function of first kind in unity3d (using c#). after trying utilize mathnet.numerics .dll in unity found many errors apparently due unity3d not supporting .net 4. decided utilize jetbrains dotpeek decompiler find bessel functions source.
however bessel function gives wrong output , honest maths above paygrade debugging has been difficult. can see errors in have used.
for example, output x = 20 43558282.5571362 is supposed 0.167025
public static double besseli0(double x) { if (x < 0.0) x = -x; if (x <= 8.0) { double x1 = x / 2.0 - 2.0; homecoming math.exp(x) * chebysheva(besseli0a, x1); } else { double x1 = 32.0 / x - 2.0; homecoming math.exp(x) * chebysheva(besseli0b, x1) / math.sqrt(x); } } internal static double chebysheva(double[] coefficients, double x) { int num1 = 0; double[] numarray = coefficients; int index = num1; int num2 = 1; int num3 = index + num2; double num4 = numarray[index]; double num5 = 0.0; int num6 = coefficients.length - 1; double num7; { num7 = num5; num5 = num4; num4 = x * num5 - num7 + coefficients[num3++]; } while (--num6 > 0); homecoming 0.5 * (num4 - num7); } private static readonly double[] besseli0a = new double[30] { -4.41534164647934e-18, 3.33079451882224e-17, -2.43127984654795e-16, 1.71539128555513e-15, -1.16853328779935e-14, 7.67618549860494e-14, 0.0 / 1.0, 0.0 / 1.0, 0.0 / 1.0, 0.0 / 1.0, -5.18979560163526e-10, 2.65982372468239e-09, -1.30002500998625e-08, 6.04699502254192e-08, -2.67079385394061e-07, 1.1173875391201e-06, -4.41673835845875e-06, 1.64484480707289e-05, -5.7541950100821e-05, 0.000188502885095842, -0.000576375574538582, 0.00163947561694134, -0.00432430999505058, 0.010546460394595, -0.0237374148058995, 0.0493052842396707, -0.0949010970480476, 0.171620901522209, -0.304682672343198, 0.676795274409476 }; private static readonly double[] besseli0b = new double[25] { -7.23318048787475e-18, -4.83050448594418e-18, 4.46562142029676e-17, 3.46122286769746e-17, -2.82762398051658e-16, -3.42548561967722e-16, 1.77256013305653e-15, 3.81168066935262e-15, -9.55484669882831e-15, -4.15056934728722e-14, 1.54008621752141e-14, 0.0 / 1.0, 0.0 / 1.0, 0.0 / 1.0, 0.0 / 1.0, 0.0 / 1.0, 0.0 / 1.0, 4.94060238822497e-10, 3.39623202570839e-09, 2.26666899049818e-08, 2.04891858946906e-07, 2.89137052083476e-06, 6.88975834691682e-05, 0.00336911647825569, 0.804490411014109 }; c# math mathdotnet bessel-functions
No comments:
Post a Comment