Prob with NDSolve in Mathematica

  • Mathematica
  • Thread starter Barnak
  • Start date
  • Tags
    Mathematica
In summary, the conversation discusses the issue of showing the regular part of a solution to a differential equation that is numerically solved with NDSolve, while avoiding singularities on the curve. The solution involves using the commands StoppingTest and Sow and Reap, as well as defining the x values at which the curve blows away.
  • #1
Barnak
63
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
  • #2
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?
 
  • #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.
 
  • #4
Try using Sow and Reap inside the NDSolve, and only Sow when the answer meets your criterion, as in the attached notebook.
 

Attachments

  • Sow_Reap_Interpolating_Function.nb
    27 KB · Views: 431
  • #5
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.
 
  • #6
I don't see how that's different than what I suggested.. but glad it worked for you
 
  • #7
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.
 

1. Why is NDSolve not returning any solution?

NDSolve requires the user to provide initial conditions for the system being solved. If no initial conditions are provided, NDSolve will not be able to find a solution and will return an error message. Make sure to specify initial conditions for all variables in the system.

2. How do I specify boundary conditions in NDSolve?

Boundary conditions can be specified using the "Method" option in NDSolve. For example, for a boundary condition of y(0)=1, the option would be "Method->{y(0)->1}". Multiple boundary conditions can be specified using a list of rules. Refer to the NDSolve documentation for more details and examples.

3. What does the error message "Max step size is effectively zero; singularity or stiff system suspected" mean?

This error message indicates that NDSolve is having trouble finding a solution due to a potential singularity or stiffness in the system. It could be caused by a poorly defined system, incorrect initial/boundary conditions, or a numerical instability. Try adjusting the options in NDSolve or simplifying the system to resolve the issue.

4. Can NDSolve handle systems with discontinuities?

Yes, NDSolve can handle systems with discontinuities by using the "DiscontinuityHandling" option. The default behavior is to handle discontinuities by automatically detecting and adjusting the step size. However, for more control, the option can be set to "JumpHandler" or "EventLocator" to specify how discontinuities should be handled.

5. How can I improve the performance of NDSolve?

There are several ways to improve the performance of NDSolve, such as specifying appropriate options for the system, using compilation techniques, and simplifying the system if possible. Additionally, using the "MethodOfLines" option with an appropriate spatial discretization method can also greatly improve performance.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
848
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
203
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
157
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
7K
Back
Top