We used a python module called pylab to graph functions.
For my program, you can select the number of harmonics and the value for sigma, and compare different arrangements at once.
from pylab import *
harmonics,sigma = zeros(5),zeros(5)
#### Variables #####
harmonics[1] = 97
sigma[1] = 1
###
harmonics[2] = 97
sigma[2] = 5
###
harmonics[3] = 97
sigma[3] = 10
###
rng = 3.14 #range of x values to plot (-rng to +rng)
#############
def gauss(number,sigma):
"""harmonics, sigma"""
gauss_list = [] #empty array
coeff = 1/(sqrt(2*pi)*sigma)
for x in range(0,number):
funcval = coeff * exp(-(float(x) -float(number-1)/2 )**2/(2 * sigma**2))
gauss_list.append(funcval)
print gauss_list
return gauss_list
def sinplot(start, stop, A, harms):
"""start, stop, amplitude, harmonics"""
loop = int()
superpos = []
for n in arange( start, stop, 0.01 ): #Create list of zeros
superpos.append(0)
for i in range( 0, len(harms) ):
plot_list = []
domain = []
loop = 0
for x in arange( start, stop, 0.01 ):
funcval = A[i] * sin( harms[i] * x )
plot_list.append( funcval )
domain.append(x)
superpos[loop] = superpos[loop] + funcval #sum of funciton values
loop += 1
#plot( domain, plot_list) #show each harmonic
plot( domain, superpos )
#sinamp = gauss(harmonics, sigma)
#print sinamp
#harmonic = range(1,harmonics+1)
try:
for i in (1,2,3,4,5):
sinplot(-rng, rng,
gauss( harmonics[i],sigma[i] ),
range( 1,harmonics[i]+1 )
)
except:
print("Graphing...")
show()
The program generates thisThe plot shows the sum of harmonics of a wave function, with each increasing harmonic having a decreasing amplitude that varies as a gaussian function, with a specific sigma value. The blue plot has a sigma value of 1, the green plot has a sigma of 5 and the red plot has a sigma of 10. This shows that by using the right amplitudes and numbers of harmonics, the superposition of waves can model a wave packet.
We can then use this to answer some questions
a. The graph is a straight line
b.
c. 1*L
d. 2*L
e.
f. 6.63e-34 = h
g. 6.63e-34 = h