I faced an issue when trying to use quad to integrate a function. Essentially, I have two versions of code where I define t(a) in different places. Both codes looks the same to me but the result I am getting is slightly different.
I am guessing that it is due to the error associated with using the quad method, but am not too sure. Would appreciate any help!
import numpy as np
from scipy.integrate import quad
s = 0.05
# Version 1
def POi1(w):
def t(a):
return (1/(0.27*a**(-1)+(1-0.27)*a**(-3*w-1))**(1/2))
return (np.exp(-((1+w)**2)/(2*s**2))*(1/(quad(t, 0, 1)[0]+((2/3)*(1/(np.abs(1+w)*1*(1-0.27)**2))))))
PO1 = quad(POi1, -np.inf, -1)[0]
print(PO1)
#Version 2
def t(a):
return (1/(0.27*a**(-1)+(1-0.27)*a**(-3*w-1))**(1/2))
def POi1(w):
return (np.exp(-((1+w)**2)/(2*s**2))*(1/(quad(t, 0, 1)[0]+((2/3)*(1/(np.abs(1+w)*1*(1-0.27)**2))))))
PO1 = quad(POi1, -np.inf, -1)[0]
print(PO1)