#Q 1A
import numpy as np
from scipy.integrate import quad
import matplotlib.pyplot as plt
# Defining the Gaussian Function
def Gaussian(mu, sigma, x):
return (1./(np.sqrt(2*np.pi)*sigma)) * np.exp(-(x-mu)**2/(2*sigma**2))
x = np.linspace(-5,5,1001)
mu = 0
sigma = 0.5
# Plotting the Gaussian Function
plt.plot(x, Gaussian(mu,sigma,x), label=''r'$\frac{1}{\sigma \sqrt{2\pi}}e^{-\frac{(x-\mu)^2}{2\sigma^2}}$')
plt.xlabel('x')
plt.ylabel('f(x)')
plt.title("Ques. 1A Gaussian Function")
plt.legend()
plt.savefig("1A.png", dpi=600)
plt.show()
# Evaluating the Integral
mu = 1
sigma = 0.5
def f(x):
return (1./(np.sqrt(2*np.pi)*sigma)) * np.exp(-(x-mu)**2/(2*sigma**2))
x = np.linspace(-5,5,1001)
result_1 = quad(f, -np.inf, np.inf)
result_2 = 1./(sigma * np.sqrt(2*np.pi)) * result_1[0]
print("Value of the integral is = ", result_2)
Comments
Post a Comment