I'm trying to calculate the total distance travelled by an object with a known initial velocity and a damping factor that is applied to the velocity at each timestep. The iterative solution is easy:
// timestep and damping are constant
// v is velocity
// d is total distance
while (Math.abs(v) > 0.001) {
d += timestep * v;
v *= damping;
}
I'd like to do this in a single step using numeric methods rather than iteration but I don't know how to integrate a function which contains a recurrence relation (i.e. v_n+1 = damping * v_n
), plus my algorithm brushes aside the fact that the damping factor should also probably relate somehow to the timestep.