pythonscipynumerical-integrationexp

I can't integrate cause of math range error


I can't integrate this in python (1/1+t))+(-1/exp(t)) [0,np.inf]

import numpy as np
from math import exp
from scipy.integrate import quad

print(quad(lamba t: (1/1+t))+(-1/exp(t)),0,np.inf)

It must show Euler constant

This is what i want to integrate


Solution

  • By the way, with this integral you will never have the Euler constant.

    Euler constant is defined as (sorry I can't post images):

    https://i.sstatic.net/z6iiM.jpg

    So you have to change your lambda function to the following:

    import numpy as np
    from math import exp
    from scipy.integrate import quad
    f = lambda t: 1/t * (1/(1+t) - exp(-t))
    
    In [21]: quad(f, 0.0, np.inf)
    Out[21]: (0.5772156649015537, 3.613579096292482e-10)
    

    The result is 0.5772156649015537 which is the value of the Euler constant.