简体   繁体   English

Scipy 辛普森积分以获取值数组

[英]Scipy simpson integration to get array of values

import numpy as np
from scipy.integrate import simpson

I'm trying to integrate the acceleration signal given below:我正在尝试整合下面给出的加速度信号:

f2 = lambda t: 0.1*np.sin(np.pi*t) + 0.1*np.sin(20*np.pi*t) + 0.01

for the timepoints:对于时间点:

t = np.arange(0, 20, 0.1)

I'm trying to use simps/simpson package from scipy to integrate the f2 over t but I'm getting this error:我正在尝试使用来自 scipy 的 simps/simpson package 将 f2 集成到 t 但我收到此错误:

v2 = simpson(f2, t)
IndexError: tuple index out of range

And if I create a list of acceleration datapoints using list comprehension like below:如果我使用如下列表理解创建加速数据点列表:

a2 = [f2(i) for i in t]

And integrate the above list using Simpson rule, I get only one value:并使用辛普森规则整合上面的列表,我只得到一个值:

v2 = simps(a2, t)

which is这是

v2 = 0.2005702922522627

I want to get a list or an array of velocity values using Simpson integration over the period t and plot it vs t but one of the methods I was trying is giving me an error and other one is giving a singular value.我想在 t 周期内使用 Simpson 积分和 plot 它与 t 得到一个速度值列表或数组,但我尝试的一种方法是给我一个错误,而另一种方法是给一个奇异值。

Q: why are you using analytic methods/libraries for this?问:您为什么为此使用分析方法/库? in this case在这种情况下

v = v0 + Sigma( da * dt ) * constant. v = v0 + Sigma( da * dt ) * 常数。

The constant depends on your accelleration sensor that produces your signal.常数取决于产生信号的加速度传感器。 If that sensor works linear then you can sample your lambda change (da) until t with a sufficiently small step size (dt), and multiply the result with the stepsize and accumulate the result.如果该传感器线性工作,那么您可以对 lambda变化(da) 进行采样,直到 t 具有足够小的步长 (dt),然后将结果乘以步长并累加结果。 Each sample will get a v-value you can plot.每个样本都会得到一个 v 值,你可以 plot。 To find the value of v, make sure to add v0 (start speed)要找到 v 的值,请确保添加 v0(起始速度)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM