scipy.special.gamma

scipy.special.gamma(z) = <ufunc 'gamma'>

伽马函数。

伽马函数定义为

\[\Gamma(Z)=\int_0^\inty t^{z-1}e^{-t}dt\]

\(\Re(z) > 0\) 并通过解析延拓将其推广到复平面的睡觉。看见 [dlmf] 了解更多详细信息。

参数
zarray_like

实值或复值变元

退货
标量或ndarray

伽马函数的值

注意事项

伽马函数通常被称为广义阶乘,因为 \(\Gamma(n + 1) = n!\) 对于自然数 \(n\) 。更一般地,它满足递推关系 \(\Gamma(z + 1) = z \cdot \Gamma(z)\) 对于复杂的 \(z\) ,这结合了一个事实,那就是 \(\Gamma(1) = 1\) ,隐含着上面的身份 \(z = n\)

参考文献

dlmf

美国国家标准与技术研究院数学函数数字类库https://dlmf.nist.gov/5.2#E1

示例

>>> from scipy.special import gamma, factorial
>>> gamma([0, 0.5, 1, 5])
array([         inf,   1.77245385,   1.        ,  24.        ])
>>> z = 2.5 + 1j
>>> gamma(z)
(0.77476210455108352+0.70763120437959293j)
>>> gamma(z+1), z*gamma(z)  # Recurrence property
((1.2292740569981171+2.5438401155000685j),
 (1.2292740569981158+2.5438401155000658j))
>>> gamma(0.5)**2  # gamma(0.5) = sqrt(pi)
3.1415926535897927

绘制实数x的Gamma(X)图

>>> x = np.linspace(-3.5, 5.5, 2251)
>>> y = gamma(x)
>>> import matplotlib.pyplot as plt
>>> plt.plot(x, y, 'b', alpha=0.6, label='gamma(x)')
>>> k = np.arange(1, 7)
>>> plt.plot(k, factorial(k-1), 'k*', alpha=0.6,
...          label='(x-1)!, x = 1, 2, ...')
>>> plt.xlim(-3.5, 5.5)
>>> plt.ylim(-10, 25)
>>> plt.grid()
>>> plt.xlabel('x')
>>> plt.legend(loc='lower right')
>>> plt.show()
../../_images/scipy-special-gamma-1.png