I am translating that nice animation of a ball bouncing on a hilly terrain (can be downloaded as a PDF file and as a GIF file) from Maple language into Wolfram Language. Here is my code.
surf = Sin[x] + 0.2*Cos[4 x + Sin[4 x]] - 0.2*x + 3;
Plot[surf, {x, 0, 10}, AspectRatio -> Automatic]
n = Normalize[{D[surf, x], 1}] /. x -> x[t];v = {x'[t], y'[t]};c = 0.99;
vreflect = -(1 + c)*v.n*n + v // Simplify;
deq = {y''[t] == -9.81, x''[t] == 0, x[0] == 2, y[0] == 4.5,x'[0] == 0, y'[0] == 0};
NDSolve[{Evaluate[deq], WhenEvent[Evaluate[y[t] == surf /. x -> x[t]], {y'[t] -> vreflect[[2]],
x'[t] -> vreflect[[1]]}]}, {x[t], y[t]}, {t, 0, 10}]
However, the latest command produces an error. I need to tronslate the code of Maple events = [[y(t) = eval(surf, x = x(t)), [temp = diff(x(t), t), diff(x(t), t) = V_reflect[1], diff(y(t), t) = subs(diff(x(t), t) = temp, V_reflect[2])]]]
, where the derivative diff(x(t), t)
is saved and used twice, into Wolfram Language.