问题
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