duncanhall said:
I'd love to understand the logic behind the solution if I can.
The distance traveled is "the area under the curve," i.e. the integral of the velocity. One usual way to explain this is by breaking up the curve into little pieces:
Suppose you have the graph of velocity measured each second (for easy units), v(1), v(2), v(3), ... So say during the first second you're traveling at (about) v(1) = 3 m/s, then you've traveled 3 m/s * 1 s = 3 m, which is the area of a rectangle v(1) tall * 1 s wide. During the 2nd second (!) you're going v(2) = 5 m/s so that's 5 m, and so on. Add up all the areas and you have an approximation of the total area, hence the total distance traveled. The units work out because you're adding up speed * time = distance/time * time = distance.
Unless your velocity is "steppy" and the rectangles cover the graph perfectly, there will be some error in the above estimate. The trapezoidal rule seeks to improve this by covering the area with trapezoids whose tops connects the successive points. As it happens this takes very little extra work compared to using rectangles so it's a quick standby. Then there's Simpson's rule, which uses quadratic shapes (parabolas) to achieve much better precision but is surprisingly still easy to implement, and many others.
If you look up
Numerical integration, you'll find that the pictures explain it much better than I can in words.
So the main concern is that, if you're using this for an inertial navigation type application, aka "dead reckoning," then you are often integrating over a very long time, so you would want to use a very, very precise integration technique (without much regard for computing expense). So maybe the trapezoidal rule wouldn't be the best method for this after all. But hey it's a start. And as DrewD mentions, most of the standard methods are available in libraries, Matlab, scipy, etc., so ultimately you won't need to worry too much about implementation.
