Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Simpson's rule, negative answer for positive area under the curve?

I have

y1=[  9.49110000e-004   4.74145420e-004   1.41847155e-008   3.33228420e-028
       3.76352289e-081   4.48206815e-193   0.00000000e+000   0.00000000e+000
       0.00000000e+000   0.00000000e+000   0.00000000e+000] 

x=[ 112.  111.97667396  111.90666665  111.78989038  111.62619837  
     111.41538384  111.15717866  110.85125168  110.49720654  110.09457901
    109.64283388]

All the y values are positive, so the area under the curve should be positive. But when I try to use Simpson's rule to integrate

  from scipy.integrate import simps
  b= simps(y1, x)

  print b

I am getting -2.45630795891e-05 as the answer. What am I doing wrong?

like image 615
HuShu Avatar asked Mar 13 '23 12:03

HuShu


1 Answers

x is decreasing, so you're integrating from right to left. This flips the sign of the result.

like image 109
user2357112 supports Monica Avatar answered May 03 '23 18:05

user2357112 supports Monica