[英]Numerical integration with scipy.integrate.trapz returns a result but scipy.integrate.simps does not
I am trying to integrate the following data numerically: 我正在尝试以数字方式整合以下数据:
t,y
9.960000000000001e-05,8.334379999999999e-05
9.98e-05,0.000126125
0.0001,0.00018125
0.0001002,0.0002385
0.00010040000000000001,0.000289625
0.0001006,0.000347313
0.0001008,0.000391719
0.000101,0.00043284399999999994
0.00010120000000000001,0.000472375
0.00010140000000000001,0.000502469
0.00010160000000000002,0.000528594
0.00010180000000000001,0.000546219
0.000102,0.000569188
0.0001022,0.000584719
0.0001024,0.000593969
0.00010260000000000001,0.000607375
0.0001028,0.000618906
0.000103,0.000629344
0.0001032,0.000629344
0.0001034,0.000636313
0.00010360000000000001,0.0006374999999999999
0.0001038,0.000630375
0.00010400000000000001,0.00059875
0.0001042,0.00046825
0.0001044,0.000287344
0.00010460000000000002,0.000208594
0.0001048,0.000196094
0.000105,0.000172625
0.00010520000000000001,0.000134781
0.0001054,0.000115906
0.0001056,0.00010306300000000001
0.00010580000000000001,9.31563e-05
As shown below, I read this data set from a csv file. 如下所示,我从csv文件中读取了此数据集。 This is my code:
这是我的代码:
import pandas as pd
from scipy.integrate import trapz, simps
root="my/root/dir"
df = pd.read_csv(root+r"simps.csv")
print(trapz(df["t"], df["y"]))
print(simps(df["t"], df["y"]))
trapz returns a value (-9.5865055e-10) while simps returns nan and the following error: trapz返回值(-9.5865055e-10),而simps返回nan和以下错误:
anaconda\path\scipy\integrate\quadrature.py:324: RuntimeWarning: divide by zero encountered in true_divide
h0divh1 = h0 / h1
anaconda\path\scipy\integrate\quadrature.py:326: RuntimeWarning: divide by zero encountered in true_divide
y[slice1]*hsum*hsum/hprod +
anaconda\path\scipy\integrate\quadrature.py:327: RuntimeWarning: invalid value encountered in add
y[slice2]*(2-h0divh1))
anaconda\path\scipy\integrate\quadrature.py:326: RuntimeWarning: invalid value encountered in add
y[slice1]*hsum*hsum/hprod +
Why does this error occur? 为什么会发生此错误?
A very stupid mistake: I exchanged x and y. 一个非常愚蠢的错误:我交换了x和y。 Simps requires y as a first argument
Simps需要y作为第一个参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.