Prob with NDSolve in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter Barnak
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary

Discussion Overview

The discussion revolves around the challenges of using NDSolve in Mathematica to numerically solve differential equations that exhibit singularities. Participants explore methods to visualize only the regular parts of the solution curve, avoiding sections where the solution becomes invalid due to singularities.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant seeks a method to display only the regular part of a solution curve from NDSolve, specifically avoiding sections where the solution becomes negative or undefined due to singularities.
  • Another participant suggests plotting only the positive interval of the solution, but this is challenged by the original poster who notes the unpredictability of singularities.
  • A different approach is proposed involving the use of Sow and Reap within NDSolve to selectively store valid solutions based on certain criteria.
  • A participant shares a solution involving defining specific x values at which the curve becomes singular, allowing for plotting only between those points.
  • There is a recognition that the final solution aligns with an earlier suggestion, indicating a realization of the implementation method.

Areas of Agreement / Disagreement

Participants express differing views on how to handle singularities in the solution curve. While some methods are proposed and acknowledged, there is no consensus on a single best approach, and the discussion remains exploratory.

Contextual Notes

Participants indicate limitations in predicting singularities, which affects their ability to plot the solution accurately. The discussion highlights the complexity of implementing numerical solutions in the presence of singular behavior.

Who May Find This Useful

This discussion may be useful for Mathematica users dealing with differential equations, particularly those encountering singularities in their solutions and seeking methods to visualize only valid parts of their results.

Barnak
Messages
62
Reaction score
0
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 occurring 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 ?
 
Physics news on Phys.org
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?
 
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.
 
Try using Sow and Reap inside the NDSolve, and only Sow when the answer meets your criterion, as in the attached notebook.
 

Attachments

https://www.youtube.com/watch?v=
phyzguy said:
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 ! :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:
Xmin := (y /. Curve)[[1]][[1]][[1]][[1]]
Xmax := (y /. Curve)[[1]][[1]][[1]][[2]]

Then, I plot the curve between these two values.
 
I don't see how that's different than what I suggested.. but glad it worked for you
 
kai_sikorski said:
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K