来自math.net的第一类贝塞尔函数

时间:2014-06-22 18:53:14

标签: c# math mathdotnet bessel-functions

我需要在unity3d中使用第一种bessel函数(使用c#)。在尝试使用mathnet.numerics .dll统一后,我发现很多错误显然是由于unity3d不支持.NET 4.我决定然后使用jetbrains dotPeek反编译来查找bessel函数源。

然而,bessel函数提供了错误的输出,说实话,数学高于我的paygrade,因此调试它非常困难。任何人都可以看到我使用过的任何错误。

例如,x = 20的输出是43558282.5571362 其中应该是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;
        return Math.Exp(x) * ChebyshevA(BesselI0A, x1);
    }
    else
    {
        double x1 = 32.0 / x - 2.0;
        return 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;
    do
    {
        num7 = num5;
        num5 = num4;
        num4 = x * num5 - num7 + coefficients[num3++];
    }
    while (--num6 > 0);
    return 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
};

1 个答案:

答案 0 :(得分:0)

如果您尝试使用贝塞尔函数,而不是修改贝塞尔函数,则应该查找贝塞尔,而不是贝塞尔。但是,我在这个lib中找不到这个。