Scipy 集成返回负值
我有一些 xdata 和 ydata。我已经对 xdata 和 ydata 进行了排序,使得 ydata 不断增加(即 ydata 数组末尾的最高 y 值)。 ydata 还包含一些点 = 0,因此我也从 xdata 和 ydata 中删除了这些点,留下了一组纯正、非零且递增的 ydata(以及相应的 xdata)。
由于某种原因,当我执行 val = scipy.integrate.simps(ydata,xdata) 时,我得到一个负值。使用 cumtrapz 时我也得到完全相同的负值。然后,我编写了自己的 cumtrapz 函数,该函数简单地对 0.5*dx*(y[i]+y[i+1]) 求和,并得到几乎相同的结果,但结果是正值。我的问题是为什么 scipy 函数没有正确返回正结果? (无法公开共享数据,但是,我可以将未排序的数据描述为指数衰减,我对其进行排序,以使最大的 y 值位于 ydata 数组的末尾)。
干杯任何帮助表示赞赏
I have some xdata and ydata. I have sorted my xdata and ydata such that ydata is increasing (ie highest y value at the end of the ydata array). ydata also contained some points = 0, and so I've also removed those points from xdata and ydata, leaving me with a purely positive, non-zero and increasing set of ydata (with corresponding xdata).
For some reason when I go val = scipy.integrate.simps(ydata,xdata) I get a negative value. I also get the exact same negative values when using cumtrapz. I then wrote my own cumtrapz function that simply sums 0.5*dx*(y[i]+y[i+1]) and get a nearly identical result, but positive. My question is why aren't the scipy functions correctly returning positive results? (Cannot share data publicly, however, I can describe the unsorted data as being an exponential decay, which I sort such that the largest y values are at the end of the ydata array).
Cheers any help appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论