Sudden drop when integrating Gaussian with quad

I am trying to integrate u -> exp (-uĀ² / 2) from -infinity into x. When I draw the function, there is a sudden drop around 21 and it drops to 0 around 36, whereas it should be about constant to 2.5. How do you explain this?

import numpy as np
from scipy.integrate import quad
import matplotlib.pyplot as plt

def intExp(x):
    return quad(lambda u: np.math.exp(-u*u/2),-np.Inf, x, full_output=0)

def plot(a,b, u, v,s):
    plt.close()
    t = np.arange(a,b,s)
    plt.plot(t , map(intExp,t))
    plt.axis([a, b, u, v])
    plt.show()

plot(-10, 50, -1, 3, 1)

      

Thanks for the help!

+3


source to share


1 answer


Has to do with stride width. Change epsabs

from default to 1e-9:



import numpy as np
from scipy.integrate import quad
import matplotlib.pyplot as plt

def intExp(x):
    return quad(lambda u: np.math.exp(-u*u/2),-np.Inf, x, full_output=0,epsabs=1e-9)

def plot(a,b, u, v,s):
    plt.close()
    t = np.arange(a,b,s)
    plt.plot(t , map(intExp,t))
    plt.axis([a, b, u, v])
    plt.show()


plot(-10, 50, -1, 3, 1)

      

+3


source







All Articles