I have two tabulated data arrays, x and y, and I don't know the function that generated the data. I want to be able to evaluate the integral of the line produced by the data at any point along the x-axis.
Rather than interpolating a piecewise function to the data and then attempting to integrate that, which I am having trouble with, is there something I can use that will simply provide the integral by evaluating the arrays?
When searching for solutions, I have seen references to iPython and Pandas, but I haven't been able to find the parts of those packages that will aid in this task.
If there isn't a way to simply integrate the arrays, could you provide some advice on the best way to handle this task?
Scipy has an integration feature that can help you.
If you want to use the cumulative sum of trapezoids for integration, which would probably be best for a series of points.
You can do this:
This will also plot the data and show it to you graphically. This is the integration call
integrate.cumtrapz(y, x, initial=0)
where x, and y are your two arrays.Scipy has some nice tools to perform numerical integration.
For example, you can use
scipy.integrate.simps
to perform simpson's Rule, and you can pass it the following:So you can use your two arrays to do numerical integration.