Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Prob with NDSolve in Mathematica

  1. Feb 14, 2012 #1
    How can I show the regular part of the solution of a differential equation, numerically solved with NDSolve, if there's a singularity on the curve ?

    I know how to use NDSolve and show its solution, but Mathematica gives a bad curve after some point (singularity jumping). I don't want to show this part, just the regular curve BEFORE the singularity (which is occuring at t = %$&*).

    More precisely, the curve function should be strictly positive : a[t] > 0. The NDSolve should stop the resolution if a <= 0. I added the command StoppingTest -> (a[t] < 0.001) or StoppingTest -> (a[t] <= 0) but it doesn't work. I'm still getting wrong curve parts with a[t] < 0.

    Any idea ?
     
  2. jcsd
  3. Feb 14, 2012 #2

    kai_sikorski

    User Avatar
    Gold Member

    Why don't you just solve over the interval you're solving over now, but only plot it over the interval where it's positive?
     
  4. Feb 14, 2012 #3
    Duh ! Because I don't know in advance what are the singularities !

    There are two singularities on the curve, and I need to plot the regular part between them. There's no way I can know in advance the exact values of the singularities.
     
  5. Feb 14, 2012 #4

    phyzguy

    User Avatar
    Science Advisor

    Try using Sow and Reap inside the NDSolve, and only Sow when the answer meets your criterion, as in the attached notebook.
     

    Attached Files:

  6. Feb 14, 2012 #5
    https://www.youtube.com/watch?v=
    Very good trick ! Thanks a lot for that info ! :smile:

    However, I found the right solution to my problem : I just have to define the x values at which the curve y[x] blows away, like this :

    Code (Text):

    Xmin := (y /. Curve)[[1]][[1]][[1]][[1]]
    Xmax := (y /. Curve)[[1]][[1]][[1]][[2]]
     
    Then, I plot the curve between these two values.
     
  7. Feb 14, 2012 #6

    kai_sikorski

    User Avatar
    Gold Member

    I don't see how that's different than what I suggested.. but glad it worked for you
     
  8. Feb 14, 2012 #7
    Actually, it's exactly what you suggested. I just wasn't able to see how to implement it at first.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Similar Discussions: Prob with NDSolve in Mathematica
  1. Mathematica NDSolve (Replies: 1)

  2. NDSolve in Mathematica (Replies: 3)

  3. Mathematica NDSolve (Replies: 3)

  4. Mathematica NDSolve (Replies: 27)

Loading...