[SciPy-User] calculate definite integral of sampled data
Wed Aug 10 18:42:48 CDT 2011
I believe that scipy.integrate.cumtrapz exists to solve this problem.
There might be a cumulative Simpson's rule too. Nobody put too much
effort into this because integrating a sampled function is better
divided into separate interpolation (e.g. with a spline) and
integration (exact for spline interpolants). I'd approach your problem
with splrep and splint.
On 8/10/11, Manuel Graune <firstname.lastname@example.org> wrote:
> Hi everyone,
> to calculate the definite integral of a function or an array of sampled
> data scipy provides (among others) the quad and trapz functions.
> So it is possible to compute e. g. the definite integral of cos(t) over
> some interval by doing
> definite_integral= scipy.integrate.quad(cos,lower_limit,upper_limit)
> definite_integral= scipy.integrate.trapz(some_array).
> Now, if I want to plot cos(t) and the integral of cos(t) from 0 to t in
> a graph, the necessary array can be calculated by:
> def intfunc(fnc,upper_limit):
> return scipy.integrate.quad(fnc,0.0,upper_limit)
> definite_inegral= intfunc(cos,t)
> which seems (whithout knowing the actual code) a bit wasteful and slow
> but is relatively concise.
> Now for my question: scipy provides e. g. the trapz-function to
> calculate definite integral of a complete array of sampled data.
> However, I have no idea how to get achieve the same as above for
> sampled data (apart from manually iterating in a for-loop). Is there
> a function somewhere which delivers an array of the definite integrals
> for each of the data-points in an array?
> A hundred men did the rational thing. The sum of those rational choices was
> called panic. Neal Stephenson -- System of the world
> Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A 5828 5476 7E92 2DB4 3C99
Sent from my mobile device
More information about the SciPy-User