2
$\begingroup$

I am solving a system of ODEs with DSolve, which returns the results as interpolating functions. The solver always stops after some finite time because of resolution issues, so the domain of the outputted interpolating function is limited.

Hence, if I then plot those functions with a Plot command, I have to specify the range {t,0,tmax}. However tmax would change a bit everytime I run the DSolve command, and it is a pain to always change tmax manually.

Is there a way to address the domain of such a function directly?

$\endgroup$
3
$\begingroup$

You can get the domain of an interpolation-object quite simple.

For example the simulation timerange of

sol = NDSolveValue[{x'[t] == -x[t], x[0] == 1, WhenEvent[x[t] < .5, "StopIntegration"]}, x, {t, 0, 1}]

is

sol["Domain"][[1]]
(*{0., 0.693147}*)
$\endgroup$
  • $\begingroup$ Perfect, thanks! $\endgroup$ – Britzel Mar 26 at 16:02
  • $\begingroup$ You're welcome! $\endgroup$ – Ulrich Neumann Mar 26 at 16:05
  • $\begingroup$ Short followup question: Is it possible to remove the { } around those two numbers in a simple way? I know I could address now each element of that list. But perhaps there is a smarter solution. $\endgroup$ – Britzel Mar 26 at 16:11
  • $\begingroup$ Perhaps {t0,t1}= sol["Domain"][[1]]? $\endgroup$ – Ulrich Neumann Mar 26 at 16:18
  • $\begingroup$ Suppose that works, thanks a lot! $\endgroup$ – Britzel Mar 28 at 21:04

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.