import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display,Math
print('A Gaussian curve')
display(Math('y = e^{\\frac{-4ln(2)t^2}{h^2}}'))
display(Math('y = exp{ \\left( \\frac{-4ln(2)t^2}{h^2} \\right) }'))
display(Math('1 = exp{ \\left( \\frac{-4ln(2)t^2}{h^2} \\right) }'))
display(Math('ln(1) = ln \\left( exp{ \\left( \\frac{-4ln(2)t^2}{h^2} \\right) } \\right)'))
display(Math('0 = \\frac{-4ln(2)t^2}{h^2}'))
display(Math('.5 = exp{ \\left( \\frac{-4ln(2)t^2}{h^2} \\right) }'))
display(Math('ln(.5) = ln \\left( exp{ \\left( \\frac{-4ln(2)t^2}{h^2} \\right) } \\right)'))
display(Math('ln(.5) = \\frac{-4ln(2)t^2}{h^2}'))
display(Math('h^2 \\frac{ln(.5)}{-4ln(2)} = t^2'))
display(Math('\\pm \\sqrt {h^2 \\frac{ln(.5)}{-4ln(2)}} = t'))
display(Math('\\pm h \\sqrt { \\frac{ln(.5)}{-4ln(2)}} = t'))
h = .999
t = np.linspace(-3,3,1001)
g = np.exp(-4*np.log(2)*t**2 / h**2)
plt.plot(t,g)
plt.xlabel('t')
plt.ylabel('y')
plt.title('Gaussian with FWHM = ' + str(h)) # Full Width at Half Maximum (FWHM)
plt.show()
yVal2find = .5
tvals = h*np.sqrt(np.log(yVal2find)/(-4*np.log(2)))
print(tvals,-tvals)
Exercise
N = 100
G = np.zeros((N,len(t)))
h = np.zeros(N)
for i in range(N):
h[i] = (i+1)/N
G[i,:] = np.exp(-4*np.log(2)*t**2 / h[i]**2)
plt.pcolormesh(t,h,G)
plt.xlabel('t')
plt.ylabel('h')
plt.show()