Hugo
Hugo

Reputation: 1698

May I use a integration limit on scipy cumtrapz?

When I use cumtrapz the calculated area is limited by the XX axis. Is it possible to be limited by x=10, for instance?

Thank you

Hugo

Upvotes: 2

Views: 1879

Answers (1)

Joan Smith
Joan Smith

Reputation: 931

Use the x argument:

scipy.integrate.cumtrapz(y, x=range(low_lim, high_lim+1))

http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.cumtrapz.html

To limit your integration to y_min and y_max, when you have a list of definite values (not a function), you'll need to do some manual work.

The goal will be to change the values of your y-list to actually contain he samples you'd like to integrate.

So,

y_min = 10
y_max = 50
y_list = [100*sin(x) for x in range (0,100)]

mod_y = [0 if y < y_min else y - y_min for y in y_list]
mod_y = [y_max - y_min if y > y_max else y - y_min for y in mod_y]

scipy.integrate.cumtrapz(mod_y)

The subtraction on the comprehensions is to bring your minimum down to zero, which is what cumtrapz calculates anyway.

Upvotes: 3

Related Questions