1
$\begingroup$

I am trying to solve a differential equation in the form: dx/dt = funct(x) using scipy odeint.

However, for some initial values, I get a "ODEintWarning: Excess work done on this call", even if the ODE itself seems to be solvable analytically. Why does the numerical ODE solver give me a warning, and how can I make it work instead of jumping to x > 3e^7?

Here is a minimal (non) working example:

x0 =0.49 # works, but changing to 0.51 gives the ODEint warning
t = np.linspace(0,10,100)
def funct(x,t):
    return 2*x**2-x
x, out = integrate.odeint(funct, x0, t, full_output = 1)
plt.plot(t,x)

I am not too good at math, but I think the analytical answer should be: x = 1/(2 + C * exp(t)) with C being any constant.

If so, I think using initial value of x0=0.51 should also be numerically solvable because C exists (C = -0.04).

The closest question I could find was: scipy odeint: excess work done on this call and very sensitive to initial value However, the ODE in the previous question blows up analytically, whereas mine does not.

Edit: My real function and x are vectors and matrices about networks, not an analytically solvable one.

$\endgroup$
0
$\begingroup$

If I am not mistaken, for $x>0.5$, your example ODE yields $dx/dt>0$ and thus $x$ will increase and its time derivative as well. Therefore the solution diverges, even faster than a simple exponential after some time (when $x^2 \gg x$). If you start at $x=0.5$, the solution is a constant. For $x<0.5$, the solution converges to 0.

In the case of a divergence, the error estimate that is used to dynamically adapt the time step will require time steps smaller and smaller, and at one point lower than $10^{-15}$, or at least such that $t+dt=t$ at machine precision. The solver then assumes that there is no point in trying to pursue the integration and notifies you. That behaviour is absolutely normal.

$\endgroup$
1
  • $\begingroup$ Thanks for the answer. This was super helpful as I didn't realize that analytically solvable ODEs might still not be "solvable" with ODEint. I plotted the results of ODEint between 0<t<4, 0<x<20, and confirmed it increases in a super-exponential way as expected from the analytical solution. $\endgroup$
    – Hideshi
    Aug 6 at 5:02
0
$\begingroup$

To be more precise in the influence of the initial value, the ODE $\dot x=2x^2-x$ is Bernoulli. With $u=x^{-1}$ one gets $$ \dot u=-x^{-2}\dot x=u-2\implies u=2+(u_0-2)e^t\implies x=\frac{x_0}{2x_0+(1-2x_0)e^t}. $$ The denominator has a pole for $x_0>\frac12$ at $t_{pole}=\ln(\frac{x_0}{x_0-\frac12})$. For $x_0=0.51$ this gives $t_{pole}=\ln(51)=3.931825...$ This singularity provides an insurmountable obstacle for the integrator. There could be more informative error messages, but odeint just reports the failure of the step-size controller.

$\endgroup$
1
  • $\begingroup$ Thanks, I didn't know about Bernoulli ODEs so I appreciate your detailed comment. I also should have checked the existence of a pole at t = ln(51). For now, I will ignore the error, but if I find the running time is too long, I will follow your suggestions to use solve_ivp here: stackoverflow.com/questions/33072604/…. Thanks! $\endgroup$
    – Hideshi
    Aug 6 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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