Monday, November 12, 2012

Visualizing Wave Packets

11/12/2012
The following python program demonstrates how to plot a Gaussian Function:
from pylab import*
center =5
sigma=1
coeff=1/sqrt(2*pi)*sigma
gauss_list=[]
for x in arange(0,10,0.1):
    gauss=coeff*exp(-(x-center)**2/(2.*sigma**2))
    gauss_list.append(gauss)
plot(gauss_list)
show()

The following python program demonstrates how to plot a multiple sine functions:

from pylab import*
A=1
w=1
for i in range(1,4):
    x=[]
    sine_function=[]
    for t in arange(-3.14,3.14,0.01):
        sine_f=A*sin(i*w*t)
        sine_function.append(sine_f)
        x.append(t)
    plot(x,sine_function)
show()

The following python program demonstrates how to plot the superposition of sine function:

from pylab import*
A=1
w=1
Fourier_Series=[]
for i in range(1,3):
    x=[]
    sine_function=[]
    for t in arange(-3.14,3.14,0.01):
        sine_f=A*sin(i*w*t)
        sine_function.append(sine_f)
        x.append(t)
    plot(x,sine_function)
    Fourier_Series.append(sine_function)
superposition=zeros(len(sine_function))
for function in Fourier_Series:
    for i in range(len(function)):
        superposition[i]+=function[i]
plot(x,superposition)
show()


The Gaussian Wave Packet.

from pylab import*
sigma = 2.5
halfHarmonicsNumber = 0 ## total harmonics number is 5
center = 0
w = 0.4*pi
A = 1
number = 1
Fourier_Series = []
coeff = 1/sqrt(2*pi)*sigma
for k in range(0, number+1):
    x = []
    sine_function = []
    for t in arange(-31.4,31.4,0.01):
        gauss = coeff * exp(-(t - center)**2/(2. *sigma**2))
        sine_f = gauss * A * sin(k*w*t)
        sine_function.append(sine_f)
        x.append(t)
    #plot(x,sine_function)
    Fourier_Series.append(sine_function)
superposition = zeros(len(sine_function))
for function in Fourier_Series:
    for i in range (len(function)):
        superposition[i]+= function[i]
plot(x,superposition/number)
for j in arange(-10,11,5):
    print coeff * exp(-(j*1.0/2 - center)**2/(2. *sigma**2))
show()



0.134977416283
0.604926811298
0.997355701004
0.604926811298
0.134977416283

Exercises:
a.

b.
                                    c.L
                                    d.2L
                                    e.2L
                                    f.h
                                    g.h
                                    h.no matter what k of 0 is, omega of p times omega of x equal to h.



No comments:

Post a Comment