In [1]:
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display,Math
In [2]:
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) }'))
A Gaussian curve
$\displaystyle y = e^{\frac{-4ln(2)t^2}{h^2}}$
$\displaystyle y = exp{ \left( \frac{-4ln(2)t^2}{h^2} \right) }$
In [3]:
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}'))
$\displaystyle 1 = exp{ \left( \frac{-4ln(2)t^2}{h^2} \right) }$
$\displaystyle ln(1) = ln \left( exp{ \left( \frac{-4ln(2)t^2}{h^2} \right) } \right)$
$\displaystyle 0 = \frac{-4ln(2)t^2}{h^2}$
In [4]:
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'))
$\displaystyle .5 = exp{ \left( \frac{-4ln(2)t^2}{h^2} \right) }$
$\displaystyle ln(.5) = ln \left( exp{ \left( \frac{-4ln(2)t^2}{h^2} \right) } \right)$
$\displaystyle ln(.5) = \frac{-4ln(2)t^2}{h^2}$
$\displaystyle h^2 \frac{ln(.5)}{-4ln(2)} = t^2$
$\displaystyle \pm \sqrt {h^2 \frac{ln(.5)}{-4ln(2)}} = t$
$\displaystyle \pm h \sqrt { \frac{ln(.5)}{-4ln(2)}} = t$
In [5]:
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()
In [6]:
yVal2find = .5

tvals = h*np.sqrt(np.log(yVal2find)/(-4*np.log(2)))

print(tvals,-tvals)
0.4995 -0.4995

Exercise

In [7]:
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()