Beginner Beginner - 4 years ago 194
Python Question

Integrating a function to get a function

I have a function which takes a dictionary and returns an acceleration


I put a list of data for a certain parameter (lets call it
) in that dictionary, and the function returned an array of 100 results(in respect to alpha).

Now I want to integrate these values one by one, to get let's say an array velocity
in respect to the parameter
( so that i can plot these values in matplotlib).


Actually i have a mechanical problem. The ladder is placed against the wall, and because its
friction coefficient
is too small it's starts sliding.
So i have written a function which returns the
of that ladder for any
angle between 30° and 90°
(30 is the starting angle, and 90 is when the ladder is on the ground).

Anyways, I've calculated
in respect to the angle
. I have the data stored in array
I tried
but that method returns the final velocity
. I've also tried
but returns the same result.

I would like to generate an array of velocities
which will contain a value for every angle, like in array of accelerations -

Answer Source

It sounds like you want to perform cumulative quadrature on an array of values. In that case, scipy.integrate.cumtrapz should do want you want. That will perform a cumulative integration using the trapezoidal rule on the supplied array, yielding an array of outputs the same size in the inputs. You control in initial value via a separate argument if it is non-zero.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download