Python 为什么从加速度转换后,速度和位移会增加?

Python 为什么从加速度转换后,速度和位移会增加?,python,Python,我试着把加速度转换成速度和位移 但我发现,使用cumtrapz转换后,速度和位移会随时间增加 我哪里出错了?还是有更好的方法将加速度转化为速度和位移 以下是我的python示例代码: import scipy.integrate as it acceleration = [1,2,-1,-2,1,2,-1,-2,1,2,-1,-2,1,2,-1,-2,1,2,-1,-2,1,2,-1,-2] time = range(0,len(acceleration)) velocity = it.cumt

我试着把加速度转换成速度和位移

但我发现,使用cumtrapz转换后,速度和位移会随时间增加

我哪里出错了?还是有更好的方法将加速度转化为速度和位移

以下是我的python示例代码:

import scipy.integrate as it
acceleration = [1,2,-1,-2,1,2,-1,-2,1,2,-1,-2,1,2,-1,-2,1,2,-1,-2,1,2,-1,-2]
time = range(0,len(acceleration))
velocity = it.cumtrapz(time,acceleration,initial=0)
displacement = it.cumtrapz(time,velocity,initial=0)
fig,ax = plt.subplots(ncols=1,nrows=3,figsize=(16,6),dpi=80)
ax[0].plot(time,acceleration,'-',color='green')
ax[1].plot(time,velocity,'-',color='blue')
ax[2].plot(time,displacement,'-',color='red')

康特拉普的
cumtrapz
来自哪个包装?什么是
it
?我想你把
cumtrapz()
的前两个参数颠倒过来了。你需要设置一个合适的积分常数。如果您的数据是谨慎的测量,我建议您使用
np.cumsum((accel-accel.mean())*np.diff(time,append=2*time[-1]-time[-2])
。抱歉,我错过了一个代码<代码>它是scipy。integrate@jasonharper你是说
速度=it.cumtrapz(加速度、时间、初始值=0)
?我试过了,但位移还是增加了。