- Find any consecutive pair of points that change the sign of their velocity.
- Between such a pair, use (linear) interpolation to locate the time where the velocity was zero.
- Insert new points at those zeros.
- Now take the absolute value of all velocities in the new expanded vector of velocities.
- Use trapz or cumtrapz (as desired) to integrate velocity.
Integrating discrete values to determine the absolute value of displacement
6 views (last 30 days)
Show older comments
I have a velocity dataset [stored in 700 x 1 double] that i want to get the total displacement of (eg: I don't want net displacement. For total displacement, any negative displacement I would flip it to positive values). Normally, I would use cumtrapz again to gain the displacement, however any positive or negative displacements would cancel each other out. I don't want that.
I know that the area under the velocity curve is supposed to yield the total displacement. What would be the best way to code it such that the negative area is captured as positive area? Please note that I do not have points that are exactly zero (so point 1 may be +0.7 and point 2 may be -0.5, but it does not have a point in the discrete data which shows 0). I cannot simply just make the y outputs as all absolute value, because integrating between +0.7 and +0.5 yields a different area than +0.7 and -0.5. Any help would be greatly appreciated.
0 Comments
Accepted Answer
John D'Errico
on 16 Aug 2021
Edited: John D'Errico
on 16 Aug 2021
Break "large" problems down into small, managable peices. Then solve each one, and put it all together. A large problem is defined as any problem that is too difficult for you to solve easily.
4 Comments
John D'Errico
on 17 Aug 2021
Edited: John D'Errico
on 17 Aug 2021
I'll concede the use of sort there may not have been obvious. :) But once you see it done, it should make sense.
The other line of code that may not be completely obvious is the interpolation step. That comes from a line segment connecting two known points, where you know the line segment crosses y==0. Then find the location on the x-axis where the segment must have crossed the axis. As I did, just draw what is happening on paper, write the corresponding equation for the line, then do some algebra. That formula falls out. In fact, the formula applies for any two endpoints on a line, as long as the line is not horizontal. They need not be on opposite sides of the axis, but then the point of intersection will not be between the endpoints on the segment.
I guess I could have derived the formula, given two points (x1,y1), (x2,y2). The equation of that line goes back to some ancient algebra class I must have taken:
syms x1 y1 x2 y2 x y
lineeq = (y - y1) == (y2 - y1)/(x2-x1)*(x - x1)
xsol = solve(subs(lineeq,y,0),x,'returnconditions',true)
xsol.x
xsol.conditions
In that solution, we see the formula I gave, as well as the requirement that y1~=y2, otherwise the line is horizontal and never crosses the axis at all.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!