numpy/scipy: calculate definite integral of sampled data

M

Manuel Graune

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 range by doing

definite_integral= scipy.integrate.quad(cos,lower_limit,upper_limit)

or

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:

@numpy.vectorize
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?


Regards,

Manuel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top