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
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
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.stack.imgur.com/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.
You wrote lamba
instead of lambda
, which should raise a SyntaxError
.
Besides, reading your equation, the function you pass should rather be:
lambda t: 1/(1+t) - exp(-t)
Try changing your last line to:
print(quad(lambda t: (1/(1+t) - exp(-t)), 0, np.inf))