I'm trying to perform the integration of f(x) = 42*log(2)*2^(-t) from x = zero to t for different values of t as follows:
import numpy as np
from scipy.integrate import quad
reward = lambda t: 41*np.log(2)*np.power(2,-t)
quad(reward, 0, t)
However, sometimes I get a underflow FloatingPointError for t=13713.773637630298
. If I do this in an interactive session, I see the following (which does not produce an underflow error):
# Sanity Checks
>>> quad(reward, 0, 0)
(0.0, 0.0)
>>> quad(reward, 0, np.inf)
(40.99999999999978, 1.2750366198868279e-07)
# Weird Stuff
>>> quad(reward, 0, 13000)
(41.00000000000001, 4.661522155502418e-07)
>>> quad(reward 0, 130000)
(3.511099523711482e-39, 6.981138006465757e-39)
My questions are:
- Why does the value approach zero for increasing values of t?
- Why do I get an underflow error when I run the module outside interactive mode, which I am unable to reproduce with an interactive session?
Related: scipy.integrate.quad gives wrong result on large ranges