2 years ago
#9090
Oscar Ryu
Is there a way to integrate functions by d(logx) instead of dx in python?
I'm looking for a way to integrate functions in log(x) space. Scipy offers integration but I can't find how to use them in log(x) space.
My integral is
I tried to substitute log(x) into x and change entire equation, but after integrating in scipy, it shows an error (34, 'Result too large').
Here is my code. Thank you in advance.
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit
import scipy.integrate as integrate
from scipy.integrate import quad
def integrand(x,w,x1,t):
return (1-np.exp(-(t/(10**(x)))))*((w/((x+x1)**2+w**2))/np.pi)
def func(w,x1,t):
return quad(integrand,0,np.inf,args=(w,x1,t))[0]
t = np.logspace(-8,-2,1000,endpoint = True, base = 10)
vec_func = np.vectorize(func)
y3 = vec_func(0.1,5,t)
After using this, error code (34, 'Result too large') shows up.
But if I change the t value to
t = np.logspace(-8,-2.5,1000,endpoint = True, base = 10)
the error code disappears.
python
scipy
scipy-optimize
integral
0 Answers
Your Answer