Register to reply

Prob with NDSolve in Mathematica

by Barnak
Tags: mathematica, ndsolve, prob
Share this thread:
Barnak
#1
Feb14-12, 09:28 AM
P: 61
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 ?
Phys.Org News Partner Science news on Phys.org
Scientists discover RNA modifications in some unexpected places
Scientists discover tropical tree microbiome in Panama
'Squid skin' metamaterials project yields vivid color display
kai_sikorski
#2
Feb14-12, 11:13 AM
PF Gold
kai_sikorski's Avatar
P: 162
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?
Barnak
#3
Feb14-12, 12:25 PM
P: 61
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.

phyzguy
#4
Feb14-12, 12:40 PM
P: 2,195
Prob with NDSolve in Mathematica

Try using Sow and Reap inside the NDSolve, and only Sow when the answer meets your criterion, as in the attached notebook.
Attached Files
File Type: nb Sow_Reap_Interpolating_Function.nb (27.0 KB, 4 views)
Barnak
#5
Feb14-12, 12:56 PM
P: 61
Quote Quote by phyzguy View Post
Try using Sow and Reap inside the NDSolve, and only Sow when the answer meets your criterion, as in the attached notebook.
Very good trick ! Thanks a lot for that info !

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 :

Xmin := (y /. Curve)[[1]][[1]][[1]][[1]]
Xmax := (y /. Curve)[[1]][[1]][[1]][[2]]
Then, I plot the curve between these two values.
kai_sikorski
#6
Feb14-12, 03:27 PM
PF Gold
kai_sikorski's Avatar
P: 162
I don't see how that's different than what I suggested.. but glad it worked for you
Barnak
#7
Feb14-12, 04:27 PM
P: 61
Quote Quote by kai_sikorski View Post
I don't see how that's different than what I suggested.. but glad it worked for you
Actually, it's exactly what you suggested. I just wasn't able to see how to implement it at first.


Register to reply

Related Discussions
Problem in NDSolve in mathematica Math & Science Software 5
NDSolve in mathematica Differential Equations 6
Mathematica NDSolve Differential Equations 2
Mathematica NDSolve Math & Science Software 1
Mathematica: ODE, NDSolve Math & Science Software 0