# Q 1B
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import simps
a = 1
b = 2
F = lambda t: np.exp(-a*t**2)
F = np.vectorize(F)
G = lambda t: np.exp(-b*t**2)
G = np.vectorize(G)
conv = []
t = np.linspace(-5, 5, 1000)
for i in t:
t1 = np.linspace(-5.001, i, 1000)
h = F(t1) * G(i - t1)
conv.append(simps(h,t1))
plt.plot(t, F(t), label = "F(t)")
plt.plot(t, G(t), label = "G(t)")
plt.plot(t, conv, label = "Convolution")
plt.title("Ques 1B : Verify that convolution of 2 Gaussians is also a Gaussian")
plt.legend()
plt.savefig("1B.png", dpi = 600)
plt.show()
Comments
Post a Comment