Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Gaussian Wavepackets

import numpy as np
def Gaussian(x, chi, sigma):
    return 1/(sigma*sqrt(2*np.pi)) * np.exp(-(x - chi)**2/(2*sigma**2))
%pylab inline
%pylab is deprecated, use %matplotlib inline and import the required libraries.
Populating the interactive namespace from numpy and matplotlib
x = arange(0,10,0.1)
plot(x,Gaussian(x,5,0.5))
<Figure size 640x480 with 1 Axes>
import scipy.integrate as integ
integ.quad?
integ.quad(Gaussian, -numpy.inf, numpy.inf, (5,5))
(1.0000000000000022, 8.933780348092599e-09)
def eipx_Gaussian(x,p,chi,sigma):
    return np.exp(1j*p*x)*Gaussian(x,chi,sigma)
def psip(p):
    result = integ.quad(eipx_Gaussian,-numpy.inf,numpy.inf,(p,5,0.5))
    return result[0]
plot?
psip(0)
/opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/site-packages/scipy/integrate/_quadpack_py.py:628: ComplexWarning: Casting complex values to real discards the imaginary part
  return _quadpack._qagie(func, bound, infbounds, args, full_output,
1.0
from sympy import *
z = symbols('z')
integrate(Gaussian(z,5,0.5),(z,-oo,oo))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
AttributeError: 'Mul' object has no attribute 'exp'

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
Cell In[15], line 1
----> 1 integrate(Gaussian(z,5,0.5),(z,-oo,oo))

Cell In[2], line 2, in Gaussian(x, chi, sigma)
      1 def Gaussian(x, chi, sigma):
----> 2     return 1/(sigma*sqrt(2*np.pi)) * np.exp(-(x - chi)**2/(2*sigma**2))

TypeError: loop of ufunc does not support argument 0 of type Mul which has no callable exp method