I'd like to count the number of times a ball will bounce above a certain height. Imagine a ball dropped from a building, and which bounces by a factor of 0,66. How many times it will reach the 2nd floor window at 1.5 meters high from the floor?
I solved it using code, but I thought that maybe there is a general solution to this. Unfortunately my maths courses are far now and I can't quite remember the techniques.
Assumptions are:
- height > window's height
- 1 > bounce rate > 0
Here is the code I used to solve it:
def number_of_bounces(height, bounce_rate, window_height):
"""
Calculates the number of times the ball will pass in front of the window
"""
if height < window_height:
return 0
next_bounce = height * bounce_rate
if next_bounce < window_height:
return 1
passage = 1
while next_bounce > window_height:
passage += 2 # Once upward, once downward
next_bounce = next_bounce * bounce_rate
return passage
Any idea for a general solution to this problem?
Edit : Tests for this problem : Initial height : 2 / Bounce rate : 0.5 / Windows height : 1 / Expected result : 1
Initial height : 3 / Bounce rate : 0.66 / Windows height : 1.5 / Expected result : 3
Initial height : 30 / Bounce rate : 0.66 / Windows height : 1.5 / Expected result : 1
Initial height : 30 / Bounce rate : 0.75 / Windows height : 1.5 / Expected result : 21
We have by energy
$$ \cases{ mgh_0 = \frac 12 m v_0^2\\ mgh_1 = \frac 12 m v_1^2\\ \vdots\\ mgh_k = \frac 12 m v_k^2 } $$
and also $v_{k+1} = \lambda v_k$ then
$$ h_{k+1} = \lambda^2 h_k,\ \ \ h_0 = H $$
and solving this recurrence
$$ h_k = H\lambda^{2k} $$
but $h_k = \frac g2 t_k^2$ or $t_k = \sqrt{\frac 2g H}\lambda^k$ and finally
$$ T_k = t_0+2\sum_{j=1}^{j=k} t_j $$
$$ T_k = \sqrt{\frac 2g H}+2\sqrt{\frac 2g H}\sum_{j=1}^k\lambda^j = \sqrt{\frac 2g H}+2\lambda\sqrt{\frac 2g H}\left(\frac{1-\lambda^k}{1-\lambda}\right) $$
NOTE
The "number of seen bounces" can be obtained as follows:
From $h_k = H\lambda^{2k}\ge \bar{h}$ we conclude that
$$ k = \text{floor}\left[\frac 12\log_{\lambda}\left(\frac{\bar{h}}{H}\right)\right]+1 $$
here $\lambda\lt 1$
or
$$ k = \text{floor}\left[\frac 12\ln\left(\frac{\bar{h}}{H}\right)/\ln(\lambda)\right]+1 $$
Attached a MATHEMATICA script showing the bouncing process.