I'm solving a series of ODEs in Matlab using ode23 that all 'blow up' for different values. Instead of stating a range to solve over, I want to tell Matlab to solve the equation until the solution becomes greater than a certain amount (1000, say) and then stop, so that I don't have to manually find the solvable range for each equation. Is there a way to do this? I want to do this so I can state a range of values that is the same for each ODE, but each equation is only solved on a subset of that range.
Asked
Active
Viewed 147 times
1

StefanM
- 797
- 1
- 10
- 17

Thomas Doyle
- 113
- 13
-
2What you're looking for is called [event location](https://www.mathworks.com/help/matlab/math/ode-event-location.html). In addition to the documentation, there are many question on this site that cover this, e.g., [this one](http://stackoverflow.com/a/16681767/2278029). – horchler Nov 16 '16 at 22:00
-
Are you sure the values *actually* blow up? `ode23` is a terrible integrator for most problems I've encountered; are you sure you're not seeing some numerical instability? Have you tried `ode45` or `ode113`? – Rody Oldenhuis Nov 16 '16 at 22:36
-
@RodyOldenhuis, Regarding solutions blowing up I would say that `ode45` is just as bad as `ode23` as they are both the same type of methods, one is just a 5th order where the other is a 2nd (i believe) order method. Thus if the problems comes from numerical instabilities I would rather suggest ode23s (the implicit and thus stable version of ode23). Alternatively Hamiltonian systems also have the habit of blowing up in terms of long time behaviour, when solved by variable stepsize methods. If this is the case I would implement Velocity-Verlet in stead. – Nicky Mattsson Nov 16 '16 at 23:24
-
@NickyMattsson True, but the main point was for the OP to try something different. It's *obvious* that you have a problem if the behaviors between `ode23` and `ode45` are different. `ode23s` is for *stiff* systems, not necessarily badly scaled ones, and because of its low order it may not give different outcomes. Increasing order usually is a good thing, so my first bet would be `ode15s` if stiffness is the problem. But I usually start these days with `ode113`, because it's the best all-rounder, also for Hamiltonian systems. Oh well. Main message is: find out whether it is a real phenomenon. – Rody Oldenhuis Nov 17 '16 at 07:56