Scipy 集成返回负值

发布于 2025-01-13 21:42:39 字数 445 浏览 2 评论 0原文

我有一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文