zeta function州的SciPy文档:
y = zeta(x,q)返回两个参数的Riemann zeta函数: 总和(第(k + q)的**( - X)中,k = 0..inf)
根据wiki entry on Riemann zeta function给出参数x=2, q=0
,我们应该sum((k)**(-2),k=0..inf)
给出约1.645
然而,SciPy给出了以下内容
>>> from scipy.special import zeta
>>> zeta(2,0)
1.7976931348623157e+308
我错过了什么或是scipy zeta功能坏了?
答案 0 :(得分:5)
scipy.special.zeta的旧文档字符串说:
y=zeta(x,q) returns the Riemann zeta function of two arguments:
sum((k+q)**(-x),k=0..inf)
根据维基百科中的文章,这是Hurwitz zeta函数,"当 q = 1 "时,它与Riemann zeta函数一致。 (不是q = 0)。确实如此:
In [3]: zeta(1.5, 1)
Out[3]: 2.6123753486854882
In [4]: zeta(2, 1)
Out[4]: 1.6449340668482266
In [5]: zeta(3, 1)
Out[5]: 1.202056903159594
In [6]: zeta(4,1)
Out[6]: 1.0823232337111381
In [7]: np.pi**4 / 90
Out[7]: 1.082323233711138
更新:docstring现在明确地说"双参数版本是Hurwitz zeta函数"和"黎曼zeta函数对应于q = 1."
答案 1 :(得分:1)
#!/usr/bin/python
import numpy as np
def mzeta(x,q,N=100):
s=0
for j in np.arange(1,N):
s+= 1./(1.*j+1.*q)**x
return s
for N in [100, 500, 1000, 5000, 15000]:
print mzeta(2.,0.,N), np.pi**2/ 6
产生
br@ratatoskr:~/sweethome/temp$ ./mzeta.py
1.63488390018 1.64493406685
1.64293206551 1.64493406685
1.64393356668 1.64493406685
1.64473404685 1.64493406685
1.64486739796 1.64493406685
请注意,此处的总和从1
UPD:的确,它似乎是总和的j=0
值:
print "*****"
x, q=2, 0.1
print mzeta(x,q,10000) + 1./q**x, zeta(x,q)
给出了
*****
101.433199147 101.433299151