Calculating the Area Under a Curve Given a Set of Coordinates, Without Knowing the Function

Calculating area under curve from x, y coordinates

As was mentioned, using the Trapezoid Rule the function is rather simple

def integrate(x, y):
sm = 0
for i in range(1, len(x)):
h = x[i] - x[i-1]
sm += h * (y[i-1] + y[i]) / 2

return sm

The theory behind is to do with the trapezoid area being calculated, with the use of interpolation.

area under the curve between two troughs rather than integrating between the two points

You could use the abs value for the function.
Is the same of

divide Y into negative and non negative groups and do the integral for
each group separately

but more fastly.

Mathematically it should work ... but i don't know if this is whath you want.

Hope it's helpful. :)

Related Topics

Leave a reply