# What is the formula to match this series?

I am trying to find a formula for use in a web application. I'd like to predict the total distance given initial velocity and a fixed amount of "drag".

Inputs:

• number representing initial velocity
• number representing drag

Output:

• number representing distance

In this web application, we can know that the number of "iterations" is equal to velocity / drag - rounded down.

For example, given:

velocity: 1.8509277593973181

drag: 0.0175

1.8509277593973181 / 0.0175 = 105 (rounded down).

Distance is calculated by accumulating the velocity of each iteration, starting with the initial velocity.

1.8509277593973181

+

1.8509277593973181 - 0.0175

+

1.8509277593973181 - 0.0175 - 0.0175

+

1.8509277593973181 - 0.0175 - 0.0175 - 0.0175

...

This ends when the next number to add is less than 0.0175.

Note: I know that I can loop through these iterations and calculate distance imperatively, but I have a feeling that distance can be represented by a formula based on initial velocity and drag.

Maybe the following visualisation could be helpful.

Draw a rectangle, with a base long $1$, and height long $v$, initial velocity.

Next to it, to the right, you can draw a rectangle whose base is still long $1$, while the height equals $v - d$, $d$ for drag. You could continue, so that the $n$-th rectangle has height $v - (n-1)d$, until the height is negative. Well it turns out the travelled distance equals the area of all the rectangles, which is quite easy to calculate.

A resonable Approximation (should you reduce in future your ´time step Duration) is given by $\frac {v \frac{v}{d}}{2} = \frac{v^2}{2d}$, by the formula giving you the area of a triangle). For the exact result you could check for "Gauss's trick", allegedely discovered by the great mathematician at the age of 7.

• Thank you! Is Guass's trick the realization that if we add the series in opposite orders, the resulting terms are the same for each item in the series? – Raphael Rafatpanah Sep 14 '17 at 21:25
• Yes, summing the first and the last, the second and the next to the last, and so on... – An aedonist Sep 14 '17 at 21:28

The formula to sum an arithmetic sequence is: n = iterations = initial velocity / drag

a = first term = initial velocity

d = common difference = drag

https://www.mathsisfun.com/algebra/sequences-sums-arithmetic.html

A comparison of the imperative and formula methods in JavaScript show the same result for both: https://jsfiddle.net/persianturtle/we1bkk9d/1/

var initial_velocity = 1.8509277593973181
var drag = 0.0175

var iterations = Math.floor(initial_velocity / drag)

// Imperative
var sum = 0
for (var i = 0; i < iterations; i++) {
sum += initial_velocity - drag * i
}
console.log('imperative', sum)

// Formula
sum = (iterations / 2) * (2 * initial_velocity - (iterations - 1) * drag)
console.log('formula', sum)

// Estimate
sum = (initial_velocity * initial_velocity) / (2 * drag);
console.log('estimate', sum)