Suppose I want to numerically determine the location of an object falling vertically in a gravitational field from an arbitrary height h. I know that I can use NDSolve to get a numerical interpolating function and it's easy enough to plot. However, I want to find the time when the altitude is zero, i.e., when the object hits the surface of the gravitational body.
I start with something like the following for Earth:
sol3[hh_] := Module[{h = hh},
NDSolve[{r''[t] == -((gg mm)/(re + r[t])^2), r[0] == h,
r'[0] == 0} /. {re -> 6.37814 10^6, mm -> 5.9742 10^24,
gg -> 6.67430 10^-11}, r, {t, 0, 10000}]
];
I can plot this and see that the object's altitude reaches zero before t = 150 using:
Plot[Evaluate[r[t] /. sol3[10^5]], {t, 0, 150}, PlotRange -> All]
However, I want to know the exact value of t when r[t] equals to zero. I am not sure how to procede as I've tried several approaches but to no avail. Any suggestions would be greatly appreciated.
WhenEvent[]. – J. M.'s missing motivation Jan 29 '21 at 17:28FindRoot?: https://mathematica.stackexchange.com/questions/23609/using-findroot-with-an-interpolating-function – Michael E2 Jan 29 '21 at 17:29WhenEventexample: https://mathematica.stackexchange.com/questions/42304/finding-the-intersection-of-a-curve-with-an-interpolation-function/42310#42310 – Michael E2 Jan 29 '21 at 17:32FindRootoption and kept getting errors like "...is not a list of numbers with dimensions {1} at {x}={0.}..." I haven't tried theWhenEventroute yet but can screw around with that a little. – honeste_vivere Jan 29 '21 at 17:37Firstsomewhere. – Michael E2 Jan 29 '21 at 18:01FindRoot[r[t] == 0 /. First@sol3[10^5], {t, 100}]works for me. – Michael E2 Jan 29 '21 at 18:05