擅长:python、mysql、java
<p>我以前用过mpmath的<a href="http://mpmath.org/doc/current/calculus/sums_limits.html?highlight=nsum#mpmath.nsum" rel="nofollow">^{<cd1>}</a>来做这个,结果很好:</p>
<pre><code>>>> from mpmath import nsum, exp, inf
>>> nsum(lambda x: exp(-x**2), [-inf, inf])
mpf('1.7726372048266521')
</code></pre>
<p>这与</p>
<pre><code>>>> from mpmath import quad
>>> quad(lambda x: exp(-x**2), [-inf, inf])
mpf('1.7724538509055161')
</code></pre>
<p>我们可以得到更高的精度,并将其与分析值进行比较:</p>
<pre><code>>>> import mpmath
>>> mpmath.mp.dps = 50
>>> nsum(lambda x: exp(-x**2), [-inf, inf])
mpf('1.7726372048266521530312505511578584813433860453722459')
>>> mpmath.jtheta(3, 0, 1/exp(1))
mpf('1.7726372048266521530312505511578584813433860453722465')
</code></pre>