【问题标题】:use scipy.integrate.simps or similar to integrate three vectors使用 scipy.integrate.simps 或类似方法来整合三个向量
【发布时间】:2018-01-27 21:45:11
【问题描述】:

我想近似一个我没有实际分析表达式的函数。我知道我想计算这个积分:integral a * b * c dx。假设我得到的abc 来自观察数据。我如何评估这个积分? scipy 可以这样做吗? scipy.integrate.simps 是正确的方法吗?

import numpy as np
from scipy.integrate import simps

a = np.random.random(10)
b = np.random.uniform(0, 10, 10)
c = np.random.normal(2, .8, 10)
x = np.linspace(0, 1, 10)
dx = x[1] - x[0]

print 'Is the integral of a * b * dx is ', simps(a * b, c, dx), ', ', simps(b * a, c, dx), ',', simps(a, b * c, dx), ', ', simps(a, c * b, dx), ', or something else?'

【问题讨论】:

  • 为什么不只是对这些值求和(或使用一些梯形规则)?无论如何,你不会得到比这更精确的。
  • 我想通过使用 scipy 的 API 来利用它的后端效率

标签: python scipy calculus


【解决方案1】:

根据您的设置,正确的集成方式是

simps(a*b*c, x)   # function values, argument values

simps(a*b*c, dx=dx)   # function values, uniform spacing between x-values

两者产生相同的结果。是的,simps 是集成采样数据的一个非常好的选择。大多数时候它比trapz 更准确。

如果数据来自平滑函数(即使您不知道该函数),并且您可以通过某种方式使点数比 2 的幂多 1,那么Romberg integration 会更好.我在this post 中比较了trapzsimpsquad

【讨论】:

    猜你喜欢
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    • 1970-01-01
    • 2016-07-19
    • 2016-08-03
    相关资源
    最近更新 更多