1
$\begingroup$

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?

$\endgroup$
3
  • 1
    $\begingroup$ In addition to root-finding, one can do this dierectly in NDSolve with the WhenEvent mechanism. $\endgroup$ May 2 '16 at 14:43
  • $\begingroup$ 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 $\endgroup$
    – Vale
    May 3 '16 at 6:57
  • $\begingroup$ 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)? $\endgroup$ May 3 '16 at 14:47
1
$\begingroup$

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[0] == 3/2, y[0] == -1, x'[0] == 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}

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.