考虑以下函数:
import numpy as np
from scipy.special import erf
def my_func(x):
return np.exp(x ** 2) * (1 + erf(x))
-14
当我从-4
使用函数评估这个函数的积分时scipy
,quad
我得到以下结果:
In [3]: from scipy import integrate
In [4]: integrate.quad(my_func, -14, -4)
/usr/local/lib/python2.7/dist-packages/scipy/integrate/quadpack.py:289: UserWarning: The maximum number of subdivisions (50) has been achieved.
If increasing the limit yields no improvement it is advised to analyze
the integrand in order to determine the difficulties. If the position of a
local difficulty can be determined (singularity, discontinuity) one will
probably gain from splitting up the interval and calling the integrator
on the subranges. Perhaps a special-purpose integrator should be used.
warnings.warn(msg)
Out[4]: (0.21896647054443383, 0.00014334175850538866)
也就是说,大约0.22
.
但是,当我将此积分提交给Wolfram Alpha时,我得到了一个非常不同的结果:
-5.29326 X 10 ^ 69.
这是怎么回事?我猜这与scipy
给我的警告有关。评估这个积分的最佳方法是python
什么?
注意:增加limit
警告的更改但保持scipy
结果不变:
In [5]: integrate.quad(my_func, -14, -4, limit=10000)
/usr/local/lib/python2.7/dist-packages/scipy/integrate/quadpack.py:289: UserWarning: The occurrence of roundoff error is detected, which prevents
the requested tolerance from being achieved. The error may be
underestimated.
warnings.warn(msg)
Out[5]: (0.21894780966717864, 1.989164129832358e-05)