Python: integrating area under curve with uneven steps in x

≡放荡痞女 提交于 2019-12-10 07:28:30

问题


I have a list of y values and a list of x values. I would like to find the area under the curve defined by these points. I have found a couple of solutions to this problem for x values with even spacing:

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

But neither of these works when the x values are not evenly spaced.

For example:

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

Of course, using x = np.array([0,10,20,30]) in the above code returns 30.0, as expected.

Can anyone suggest a way to find the area under a curve with uneven x-spacing?

来源:https://stackoverflow.com/questions/22238489/python-integrating-area-under-curve-with-uneven-steps-in-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!