'Why scipy.integrate.quad returning odd values for integration of a normalised sinc function instead of 1 in python?
While I was trying to approximate a normalised sinc function as a delta function and integrate it using quad from -infinity to infinity , it is returning me some erronous results. Same happens if I use simps splitting up the integral on both sides of discontinuity. Couldn't figure out what's happening. Any help appreciated. Here is the code: '''
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import.quad
sigma=eval(input('Enter sigma i.e.
width: '))
mu=eval(input('Enter the shifted x-
coordinate: ')) # Point of peak value
delta3=lambda x: 1/(np.sqrt(2*np.pi)*sigma)*np.exp((-(x-mu)**2)/(2*sigma**2))
delta3=np.vectorize(delta3)
xp=np.linspace(mu-np.inf,np.inf,1000)
I=simps(f(xp)*delta3(xp),xp)
print('Value of Integration: ',format(I,'0.7f'))
'''
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
