0

I'm having some trouble using odeint to solve piece-wise odes when the time limits are very big. I have included here a minimalist example:

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint

t0 = 1.5e+21
t_end = 4.4e+23
t= np.linspace(t0,t_end,10000)  

def DMonly(y,tt):
    return 1. if tt>=(t0+t_end)/2. else 0.

plt.semilogx(t,odeint(DMonly,0.,t),marker='.')
plt.show()

The solution should be y=0 for the first half and then increase linearly for the second half yet I get that y=0 always, as in this plot.

If I take the exact same problem but now with different values for t0 and t_end:

t2= np.linspace(1.,100.,10000)

def DMonly2(y,tt):
    return 1. if tt>=(1.+100.)/2. else 0.

plt.plot(t2,odeint(DMonly2,0.,t2),marker='.')
plt.xlabel('t')
plt.ylabel('y(t)')
plt.show()

Now the solution is well behaved as in this plot.

Rudyard
  • 133
  • 1
  • 1
  • 7
  • Maybe try putting your big values for `t0` and `t_end` directly into your test to see if it's the values that pose a problem or something else? (like you do in your second example) – Arthur Spoon Nov 09 '17 at 12:01

1 Answers1

1

I just want to raise a question, is it possible that one of the libraries does not support large numbers.

For Python version I read this link, which explains very good the Python handling the numbers. But can there be a case where one of your libraries does not support those large numbers?

UPDATE: please have a look at this answer also, especially what Dietrich is mentioning in the answers about Sympy, maybe that can help better ;)

I am sorry...I am not an expert in maths but from a test I did I found this,

this number

t0 = 1.5e+21
t_end = 4.4e+23

qualify to this

t0 = 1500000000000000000000
t_end = 440000000000000000000000

running with such values:

t0 = 15000000
t_end = 4400000000

I got enter image description here

then with a less 0 with this values:

t0 = 1500000
t_end = 440000000

I get this:

enter image description here

oetoni
  • 3,269
  • 5
  • 20
  • 35