python梯形法计算积分值_Python中实时数据的数值积分(梯形)

关于Python中实时数据的数值积分(梯形)问题-

背景:我在实时测量一个平均速度为100米/分钟的移动物体,每100毫秒采样一次,持续60秒,因此在一分钟结束时,我将有600个样本。我的测量方法不精确,每次测量都有10米的误差。一分钟间隔后的典型图表为:

e50a6cdee1e1d33a28de5e39a6c8ce07.png

问题:我大致知道物体在一分钟内移动100米,但是当在这段时间内积分(现在只使用梯形)时,我得到的答案是比预期的高60倍,我做错了什么?我怀疑是'width'或deltaT=100ms是不正确的(?)在

我的python代码如下-这是惯用的,也就是说,不是python代码,原因是为了模拟实时测量:# Trapezoidal rule integral

testData = [] # store all vel. measurements

width = 100e-3 # sample every 100ms

total = 0

currVel = 0

prevVel = 0

t = 0

while( t < 60 ):

# take a live sample and save it

currVel = np.random.normal(100,10,1)

testData.append( currVel )

# only complete the integral after the second sample

if( t >= 100e-3 ):

total += width*(currVel+prevVel)/2

# update previous flow and increment

prevVel = currVel

t += 100e-3

#total /= 60 # fudge factor, why this factor out?

print "Total distance covered over 1 minute", total

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值