In an application, I need to find a region where some conditions must be true. However, these conditions are made of interpolating function solved by ParametricNDSolve. I will give a toy model example to clarify

eq1 = y1'[x]==y1^2+y2^4
eq2 = y2'[x]==2*y1^4-y2^2

These run super fast and I encounter no problems at all. After that, there are the conditions, which I write as


Supposing that I need thoses conditions to be less or equal than zero, I want to find the region where the {a,b} values are allowed and plot them. To do that, I'm using the following

Conditions[a_, b_, x_] := Apply[And,Table[ToExpression["c" <> ToString[i] <> "[a,b,x]" <> "\[LessEqual]0"], {i, 1, 
list = Reap[Table[Sow[Conditions[a, b, x]], {a, 0.,1., 0.02}, {b, 0., 1., 0.02]]

Essentially this is the code I'm using to generate the list of points that I need to plot. However, it's taking a huge amount of time. I would like to know if there is a proper and faster way to do this.

  • $\begingroup$ Your example doesn't work for me in its current form. As for the performance aspect: Keep in mind that ParametricNDSolve doesn't really solve anything when you evaluate the first block of code. It just generates the ParametricFunction expressions that do the actual solving, which is why the last step is so slow. $\endgroup$
    – Lukas Lang
    Commented Aug 9, 2022 at 12:47
  • $\begingroup$ Any advice to overcome using ParametricNDSolve or ParametricFunction? $\endgroup$
    – Lp_cam
    Commented Aug 9, 2022 at 12:54

1 Answer 1


OP seems to be open to different approaches, so I thought I try a graphical approach. Here I plot the vector field of the autonomous differential equation, and the region where both c1 and c2 are not positive:


I also plot a dashed red line that I will come to in a moment. Here is the plot:

enter image description here

OP wants to know for which initial points $y_1(0) = a$, $y_2(0) = b$ the solution $y_1(x)$, $y_2(x)$ is in the blue region. Unfortunately, OP did not specify for which $x$ this conditions must hold. For all $x$? For at least one $x$?

We can nevertheless say something conclusive if we restrict (as OP did in the code in the question) to the case $b \geq 0$, which means that we start somewhere above the red dashed line, and to $x \geq 0$. In that case we never go below the red dashed line for $x \geq 0$, in particular we never enter the blue region. This can be seen from the plot, since along the red dashed line, the arrows always point upward. This can also be seen from the differential equation itself, by setting $y_2=0$ there. (The only exception is $a=b=0$, where the solution remains at the origin eternally, and which belongs to the blue region.)

Comment. Note that solutions do not necessarily exist for all $x$. It can happen that the solution escapes to infinity after finite time $x$, because the differential equation is nonlinear.

  • $\begingroup$ Thank you, it was clarifying $\endgroup$
    – Lp_cam
    Commented Aug 11, 2022 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.