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
How to Get One Key and Value from a Json in Python
How to Find a Minimum Value in a 2D Array Without Using Numpy or Flattened in Python
How to Convert Data from Txt Files to Excel Files Using Python
Reading a CSV File into Pandas Dataframe With Quotation in Some Entries
Easiest Way to Convert Two Columns to Python Dictionary
How to Name a File by a Variable Name in Python
Can Anyone Explain Me What This Python 3 Command Do
Importing Local Module (Python Script) in Airflow Dag
Copy All Values in a Column to a New Column in a Pandas Dataframe
How to Check If a String Column in Pyspark Dataframe Is All Numeric
How to Find a Word That Starts With a Specific Character
Selecting Specific Rows and Columns from Numpy Array
Finding the Index of the First Occurrence of Any Item in a List
Identifying the Range of a Color in Hsv Using Opencv
Simple Digit Recognition Ocr in Opencv-Python
How to Print Float to N Decimal Places Including Trailing 0S