Skip to content
Advertisement

Numerical Python: Solving a BVP with a boolean condition?

I am not sure about the best way to ask this question, but I am trying to find the long-term state of an ODE system with an arbitrary extra constraint that needs to be fulfilled.

Ex:

JavaScript

In the code above, f is the right-hand-side of my ODE model. N is the dimension of my state vector X, t_range is the interval I want to view the values of X over, X0 is my initial condition, and a and b are just arbitrary model parameters.

The code written produces the following chart:

enter image description here

However, let’s say I didn’t want to evaluate X over some fixed t_range. Let’s say I wanted to keep solving the ODE until some condition was satisfied:

JavaScript

In other words, I want to do something like this:

JavaScript

Is there an easy way to do this in scipy? If not, is there a straightforward way to implement this?

Please let me know if I can clarify anything better.

Advertisement

Answer

@Lutz Lehmann answered my question in the comments.

If I wanted the solver to stop when one entry in X became < 0:

JavaScript
Advertisement