我有一个函数,它是一个相对大的数据集的插值。我使用线性插值interp1d
,所以有很多像this这样的非光滑尖锐点。scipy中的quad
函数将发出警告,因为存在尖锐的点。我想知道如何在没有警告的情况下进行集成?在
谢谢你!在
谢谢你的回答。在这里,我总结一些解决方法,以防其他人遇到同样的问题:
points
来避免警告并获得更准确的结果。在quad
的默认限制(limit=50
),所以我选择quad(f_interp, a, b, limit=2*p.shape[0], points=p)
来避免所有这些警告。在a
和{x
的相同起点或终点,则p
可以由p = x[where(x>=a and x<=b)]
选择
quad
接受一个可选参数,称为points
。根据文件:在您的例子中,“困难”
points
正是数据点的x坐标。下面是一个例子:以下是数据点和
f_interp
的图:现在将
^{2}$quad
调用为返回一系列警告以及
如果您提供
points
参数,即它不发出警告,结果是
这也意味着与之前的调用相比,结果的准确性要高得多。在
相关问题 更多 >
编程相关推荐