The Formula that i am trying to use to calculate the total distance of a ball after free fall from a distance D and bouncing X times is:
for example after the ball hits the ground eight times this would be the answer:
distance = 1 + 2 * (h + h^2 + ... + h^7)
Note that in the above formula, the term h^n represents the height of the ball after the nth hit and the factor of 2 in all but the first term reflects that the ball travels both up and back down to the floor for each hit. The sum in the brackets represents the geometric series for the height of the ball.
distance = 1 + 2 * (2/3 + (2/3)^2 + (2/3)^3 + (2/3)^4 + (2/3)^5 + (2/3)^6 + (2/3)^7)
distance = 1 + 2 * (2/3 * (10423/2187)) = 1 + 2 * (6882/2187) = 10423/2187 = 4.77 m approximately
I somehow tried to do the javascript part but somehow my script doesnt work
function totalDistance(fall, bouncing, numBounces) {
let distance = fall;
let h = bouncing;
for (let i = 1; i <= numBounces - 1; i++) {
distance += 2 * Math.pow(h, i);
}
return distance;
}
function calculate() {
let fall = document.getElementById("fall").value;
let bouncing = document.getElementById("bouncing").value;
let numBounces = document.getElementById("numBounces").value;
document.getElementById("result").innerHTML = "The total distance traveled after " + numBounces + " bounces is: " + totalDistance(fall, bouncing, numBounces) + " meters";
}
<!DOCTYPE html>
<html>
<body>
<p>Enter the height of the fall (in meters): <input type="text" id="fall"></p>
<p>Enter the bouncing ratio (e.g. 0.66 for 2/3): <input type="text" id="bouncing"></p>
<p>Enter the number of bounces: <input type="text" id="numBounces"></p>
<button onclick="calculate()">Calculate</button>
<p id="result"></p>
</body>
</html>