0

I'm working with the function NDSolve. I give it the time of integration, the time I want it to evaluate my differential equations. Sometimes, it crashes before the end of its attribuated time ; For example, I want to evaluate between 0 and 2000 seconds, but for a reason, it crashed at 1877.99325.... or something.

The fact that it crashed or stopped because a predicted event happened doesn't interest me here. I would like to know if there is a way to extract that time and put it in a variable, like that :

    NDSolve[...]
    (*output of NDSolve*){{f1[x]->InterpolatingFunction[{{0.,1877.99325 (*it's this value that I want !*)}},<>][x],f2[x]->InterpolatingFunction[{{0.,1877.99325 (*it's this value that I want !*)}},<>][x]}}
    t=a way or an other to extract my value
    timecrash=t

How could I do that ? Any help would be great !

EDIT : ... OK, so my answer was deleted and transformed as a comment, and now I can't comment my own answer (which was supposed to be a comment, by the way). But I can't comment the first comments neither because I still need 50 rep (..??) I tried the "Domain" solution, but it doesn't work so far. I tried these lines :

    f["Domain"]/.sol(*this "sol" comes from sol=NDSolve[...]*)//Last

The output is : f[Domain] Another shot : f["Domain"]//Last The output is : Domain

Darryl
  • 3
  • 2
Darryl
  • 21
  • 1
  • 2
    Letting f be any one of your InterpolatingFunction[]s, try f["Domain"] // Last. – J. M.'s missing motivation Jul 09 '15 at 14:19
  • what @Guesswhoitis says. also see here – chuy Jul 09 '15 at 14:21
  • Well, did you assign the output of NDSolve[] to something? – J. M.'s missing motivation Jul 09 '15 at 17:54
  • Mmmh nope, nothing happens. I only got the word "Domain" as an output... Could you be more specific ? Is there a package I am supposed to use ? @chuy, I am unfortunately not used to this kind of dense coding, so I don't really see where I could find any piece of answer :o) – Darryl Jul 09 '15 at 17:19
  • 1
    (You can comment on your own question, regardless of how much rep you have.) – J. M.'s missing motivation Jul 09 '15 at 17:55
  • It's supposed to work, but if you want to facilitate diagnosis, you might want to post in full your code that involves NDSolve[] so potential helpers can try things out for themselves. – J. M.'s missing motivation Jul 09 '15 at 19:59
  • @Darryl Isn't this the same question in essence? (If not, please clarify the difference. Without the particular code you're using, it seems the same.) – Michael E2 Jul 09 '15 at 20:35
  • @Guesswhoitis. The user Darryl seems to have created a duplicate account. – Michael E2 Jul 09 '15 at 20:38
  • @Michael E2 OK, indeed this question is the same, I didn't find it when I first did a research on the questions asked. So it finally works, but there was a difference between my code and the code you used, Michael E2, and this difference made the "Domain" work. The code is indeed Flatten[f["Domain"] /. sol] // Last If you write NDSolve[{(differential équations with f[x] & g[x])},{f[x],g[x]},{x,0,1000}] though, it won't work. If you use instead NDSolve[{(diff équations with f[x] & g[x])},{f,g},{x,0,1000}] – Darryl Jul 10 '15 at 06:58
  • @Darryl Yes, I almost always use the form NDSolve[eqns, {f, g}, {x,...}] for this and other reasons. Otherwise something like f[x] /. sol /. x -> "Domain" would probably work. Glad you solved it. (Including such details as you mentioned in you comment about the actual call to NDSolve would have helped others to give you more precise and helpful advice earlier. That's why people often ask for the code.) – Michael E2 Jul 10 '15 at 16:06

0 Answers0