【问题标题】:Scipy - Opposite of incomplete gamma functionScipy - 不完全伽马函数的对立面
【发布时间】:2014-12-17 03:39:18
【问题描述】:

我正在研究一个超级简化的辐射传输问题,我最终得到了形式的积分
\int_{x_0}^{x_1} e^{+t} t^a dt
在我的一个方程式中。是否有:
1. 我一直找不到的这种功能的特殊名称?这显然与不完全伽马函数有关
\frac{1}{\Gamma(a)} \int_0^{x} e^{-t} t^{a-1} dt
这是在scipy.special.gammainc 下实现的。我已经在我的代码的早期部分中使用过它。
2. 这样一个函数的相当快的实现,其中指数 $a$ 是固定的,但积分边界 $x_{0,1}$ 是可变的?最好是 $x_{0,1}$ 可以是相同长度的 numpy 向量,或者是标量? (如果可以澄清问题,我可以讨论这如何解决问题。)

两个直接的变通方法使用scipy.integrate.quadscipy.integrate.cumtrapz

from scipy.integrate import quad  
from scipy.integrate import cumtrapz  
from numpy import exp, empty_like, linspace, ones

a = 0.286 * 4.0
fIntegrand = lambda t: exp(t) * t**a

def FIntegrated1(x0,x1):
    # Use quad to do integrals one by one
    F = empty_like(x0)
    for i in xrange(x0.size):
        F[i] = quad(fIntegrand, x0[i], x1[i])[0]
    return F

def FIntegrated2(x):
    # Use cumtrapz
    # x is a numpy array from x0 to maximum x1 to be calculated
    F = cumtrapz(fIntegrand, x=x, initial=0.0)
    return F

# Test out with typical values
x = linspace(.5,8,50)
x1 = x[1:]
x0 = ones(x1.shape) * .5
F1 = FIntegrated1(x0,x1)
F2 = FIntegrated2(x)

这两种解决方法都不是特别慢或特别快,但如果有更好的方法,我们将不胜感激。

【问题讨论】:

    标签: scipy integral


    【解决方案1】:

    scipy 中(较低的)不完全 gamma 函数的文档:(link)

    【讨论】:

    • 如果我没看错的话,OP已经熟悉这个功能了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 2011-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多