Find time when position less than zero
4 次查看(过去 30 天)
显示 更早的评论
I have code that integrates velocity to get position. I want to know when the position of projectile = 0 (ie time of flight), but there is no value in position vector where position = 0 at time of flight as position is measured periodically.
i.e How can I calculate time of flat for a projectile (intercept of position=0) when height of projectile is measured periodically?

This is the code I have to calculate position:
for t = 1:1:1500
v = cumtrapz(time,acceleration)
position = cumtrapz(time,v)
if t <= (60/dt)
acceleration(t) = (Fup-Fdown) /mass
else
acceleration(t) = (-Fdown) /mass;
end
time(t) = t*dt;
end
1 个评论
回答(1 个)
Star Strider
2018-11-21
I cannot run your code.
You can get the index of the first position that is negative using the find function:
negpos - find(position <= 0, '1, 'first');
The time will then be either:
tfinal = t(negpos)
or
tfinal = time(negpos)
depending on what you want.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!