根据scipy手册,quad function要指定limit参数An upper bound on the number of subintervals used in the adaptive algorithm.
默认情况下,limit的值是50。
你的代码返回警告信息quadpack.py:364: IntegrationWarning: 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, IntegrationWarning)
您必须更改limit参数,即:from scipy.integrate import quad
import numpy
integrand = lambda x: numpy.sin(x) / x ** 2
print(quad(integrand, 1e-16, 1.0, epsabs = 1e-4, limit=100))
输出:(36.7600787611414, 3.635057215414274e-05)
输出中没有警告消息。细分数小于100且quad达到了要求的精度。在