简体   繁体   中英

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:

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.

Q: why are you using analytic methods/libraries for this? in this case

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

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. Each sample will get a v-value you can plot. To find the value of v, make sure to add v0 (start speed)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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