Python:积分曲线下的不均匀步数

2024-05-13 02:51:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个y值列表和一个x值列表。我想找出由这些点定义的曲线下的面积。对于间距为偶数的x值,我找到了几个解决方案:

1)Calculating the area under a curve given a set of coordinates, without knowing the function

2)Using scipy to perform discrete integration of the sample

但是当x值不均匀分布时,这两种方法都不起作用。在

例如:

>>> from scipy.integrate import simps
>>> y = np.array([1,1,1,1])
>>> x = np.array([0,5,20,30])
>>> simps(y,x)
-inf

当然,使用x=np.数组上面代码中的([0,10,20,30])按预期返回30.0。在

有人能建议一种方法来找到不均匀x间距曲线下的面积吗?在


Tags: ofthe方法列表定义npscipy解决方案