# Numerical integration of given points, simple/easy way

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?

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.

• 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. Dec 24 '16 at 18:10
• @KcFnMi You can take the absolute value of the last element of the array. Dec 24 '16 at 19:19
• The others are there just to complicate? Dec 24 '16 at 19:23
• @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$. Dec 24 '16 at 19:33
• Ok, got the idea. Are there any special requirements I should pay attention? Dec 24 '16 at 19:53