1

我在用 Java 实现 MATLAB 的gammainc时遇到了麻烦。

我试着部分地做。我使用了这些使用 Lanczos 近似的函数,我在网上找到了它来求解Γ(a)

private static double logGamma(double x) {
          double tmp = (x - 0.5) * Math.log(x + 4.5) - (x + 4.5);
          double ser = 1.0 + 76.18009173    / (x + 0)   - 86.50532033    / (x + 1)
                           + 24.01409822    / (x + 2)   -  1.231739516   / (x + 3)
                           +  0.00120858003 / (x + 4)   -  0.00000536382 / (x + 5);
          return tmp + Math.log(ser * Math.sqrt(2 * Math.PI));
       }

private static  double gamma(double x) { return Math.exp(logGamma(x)); }

然后我使用辛普森法则解决积分部分然后我将它们组合起来做 gammainc 但我得到的输出是不合理的。

积分部分也可以看作是下不完全伽马函数

我正在寻求更好的解决方案的建议。

4

1 回答 1

3

尝试使用 Apache Commons Math,其中包括logGamma()andregularizedGammaP()regularizedGammaQ().

我不太确定您正在寻找哪个数量(您能更具体吗?),但是对其中的一两个进行一些代数操作应该可以得到您想要的。

如果您无法处理 Apache Commons 的 .jar 导入,只需在项目中包含Gamma.java的源文件(但要确保许可问题不会给您带来任何问题)。

于 2012-01-02T16:26:10.480 回答