簡體   English   中英

使用scipy.integrate.simps或類似的方法來整合三個向量

[英]use scipy.integrate.simps or similar to integrate three vectors

我想近似一個我沒有實際解析表達式的函數。 我知道我想計算該積分: integral a * b * c dx 假設我從觀察到的數據中得到abc 我如何評估這個積分? scipy可以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?'

通過您的設置,正確的集成方式是

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集成會更好。 我在這篇文章中比較了trapzsimpsquad

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM