# Find a independent variable value from the numerical solutions of a system of differential equations

I have calculated the solutions for the following system of differential equations using NDSolve

{x''[t] == Sqrt[(1 - 2 /x[t] + x'[t]^2) (1 + x'[t]^2)]/x[t] - ( 2/x[t]^2 Sqrt[(1 + x'[t]^2)])/( Sqrt[1 + x'[t]^2] - Sqrt[1 - 2/x[t] + x'[t]^2]), y'[t] == x[t]/(x[t] - 2) Sqrt[1 - 2/x[t] + x'[t]^2]}

I would now like to find the value of t for which x(t)==2. I have tried with Solve in this way: Solve[x[t] /. sysSol == 2, t], but it does not work.

Any suggestion?

• In addition to root-finding, one can do this dierectly in NDSolve with the WhenEvent mechanism. May 2 '16 at 14:43
• How would you do that Daniel? I am thinking of making it print the value of t like WhenEvent[y[t] == 2, t], but I am definitely doing something wrong
– Vale
May 3 '16 at 6:57
• There is an example in NDSolve documentation. I suspect what you tried is close. Maybe use x instead of y? Or use Sow[t] as the event (don't forget to Reap it around the NDSolve)? May 3 '16 at 14:47

You haven't given any idea what your initial conditions are so I made some up and solved for a value that was in the range of the solution.

sols = NDSolve[{x''[t] == Sqrt[(1-2/x[t]+x'[t]^2) (1+x'[t]^2)]/x[t] -
(2/x[t]^2 Sqrt[(1+x'[t]^2)])/(Sqrt[1+x'[t]^2]-Sqrt[1-2/x[t]+x'[t]^2]),
y'[t] == x[t]/(x[t] - 2) Sqrt[1 - 2/x[t] + x'[t]^2],
x == 3/2, y == -1, x' == 3/4}, {x, y}, {t, 0, 1}];
fx = x /. sols[[1, 1]];
Chop[FindRoot[fx[t] == 1.8, {t, .5}]]


which returns {t -> 0.6} • Hi Bill, thanks for your answer. Can you explain to me the use of [[-,- ]] when defining a fx? Thanks
– Vale
May 2 '16 at 5:58
• @Vale look up reference.wolfram.com/language/ref/Part.html
– Bill
May 2 '16 at 16:18