Problem
A ball initially at height $h_0$ above a horizontal surface is dropped at time $t = 0$ with zero initial velocity. When it arrives at the surface, the ball bounces in the vertical direction with a fractional loss of speed at each bounce, such that $v_{after}/v_{before} = \alpha$, where $\alpha$ is a constant.
Plot the height of the ball as a function of time.
I know how to do it by hand, but I want to try plotting it using Mathematica. The following is my approach:
g = 9.81;
h[h0_, v_, t_] := h0 + v*t - 0.5*g*t^2
time = Array[t, 5, 0];
velocity = Array[v, 5, 0];
alpha = 0.8; (*arbitary*)
h0 = 10; (*arbitary*)
v[0] = Sqrt[2*g*h0]; (* velocity before first impact *)
For[i = 1, i < 5, i++,
v[i] = v[i - 1]*alpha] (* v[i]=velocity after i^th impact *)
t[0] = 0; (*start time*)
t[1] = t /. Solve[h[h0, 0, t] == 0 && t > 0, t][[1]]; (* time of 1st impact *)
For[i = 2, i < 5, i++,
t[i] = t[i - 1] + t /. Solve[h[0, v[i - 1], t] == 0 && t > 0, t][[1]]]
(* calculate all subsequent t[i], t[i]=time of i^th impact *)
plot = Array[p, 5, 0];
p[0] = Plot[h[h0, 0, s], {s, t[0], t[1]}];
For[i = 1, i < 5, i++, p[i] = Plot[h[0, v[i], s - t[i]], {s, t[i], t[i + 1]}]]
Show[p[0], p[1], p[2], p[3], PlotRange -> All, ImageSize -> 350]
The above gives the plot that I am looking for; however, I have some questions.
- Are there any ways to make the above code more elegant and efficient?
- I want to make $\alpha$ and $h_0$ variables instead of fixing them in the beginning. How should I do it so they can be controls in a
Manipulateexpression? - How can I automate the last line so that I don't have to manually type
p[0], p[1], p[2]? - How I can as make 'envelope' as I like on the plot?
PS: I am new to Mathematica, so please forgive me if I ask anything silly.

vand av tterm in the definition ofh. That produces an upward retardation proportional tov. Very strange. – m_goldberg Jul 18 '16 at 14:53