0
$\begingroup$

I have the x and the f(x) for a set of x. I don't know the function, actually. This is sufficient to integrate it?

The x value might span from 1 to no more than 50, usually around 10. While y is always negative and it's peak might pass -100.

What's the simplest approach?

x 0  1  2  3  4  5  6  7  8 9
y 0 -3 -5 -7 -5 -3 -2 -1 -1 0

May I ask the Python code com compute that?

$\endgroup$
2
$\begingroup$

You can use scipy.integrate with a given method (Simpson's rule or composite trapezoidal rule for instance):

from scipy import integrate
x = array1
y = array2
int = integrate.cumtrapz(y, x, initial = 0)

See here for more.

$\endgroup$
  • $\begingroup$ Got this as result, [ 0. -1.5 -5.5 -11.5 -17.5 -21.5 -24. -25.5 -26.5 -27. ]. But a I was expecting just one number. $\endgroup$ – KcFnMi Dec 24 '16 at 18:10
  • $\begingroup$ @KcFnMi You can take the absolute value of the last element of the array. $\endgroup$ – wrong_path Dec 24 '16 at 19:19
  • $\begingroup$ The others are there just to complicate? $\endgroup$ – KcFnMi Dec 24 '16 at 19:23
  • 1
    $\begingroup$ @KcFnMi You have all the intermediate values since it's a cumulative function. Try, to be sure, to integrate between 0 and 1 the points generated by a simple function like $x^2$. $\endgroup$ – wrong_path Dec 24 '16 at 19:33
  • $\begingroup$ Ok, got the idea. Are there any special requirements I should pay attention? $\endgroup$ – KcFnMi Dec 24 '16 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.