Exemple #1
0
def Cv(T):
	Tratio = T/Dt # ratio of temperature to Debye temperature
	lead = 9*V*rho*kb*(Tratio)**3 # leading term before integral
	a = 0 # lower limit of integral
	b = 1./Tratio # upper limit of integral 
	intg = gaussint(Cvintr,N,a,b)
	return lead*intg
Exemple #2
0
from gaussint import gaussint
import numpy as np

# This program computes the integral of x^3/(exp(x) - 1) from zero
# to infinity for a number of sample points

# Set constants for program
# Number of sample points (an array to test convergence)
Ns = np.arange(50, 101)
# Lower limit of integral
a = 0.
# Upper limit of integral
b = 1.


# Function returns z^3/(exp(z) - 1)dz under change of variables
# z = x/(1-x). This makes the integration limits finite.
def Wintr(x):
    num = x**3  # numerator
    den = (1 - x)**5 * (np.exp(x / (1 - x)) - 1)  # denominator
    return num / den


# Return evaluation of integral for each number of sample points
for N in Ns:
    Wintg = gaussint(Wintr, N, a, b)
    print 'N = {0}, integral = {1:.14f}'.format(N, Wintg)
Exemple #3
0
from gaussint import gaussint
import numpy as np

# This program computes the integral of x^3/(exp(x) - 1) from zero 
# to infinity for a number of sample points

# Set constants for program
# Number of sample points (an array to test convergence)
Ns = np.arange(50,101)
# Lower limit of integral
a = 0.
# Upper limit of integral
b = 1.

# Function returns z^3/(exp(z) - 1)dz under change of variables 
# z = x/(1-x). This makes the integration limits finite.
def Wintr(x):
	num = x**3 # numerator
	den = (1-x)**5 * (np.exp(x/(1-x))-1) # denominator
	return num/den

# Return evaluation of integral for each number of sample points
for N in Ns:
	Wintg = gaussint(Wintr,N,a,b)
	print 'N = {0}, integral = {1:.14f}'.format(N,Wintg)
Exemple #4
0
# z = x/(1-x). This makes the integration limits finite.
# multiply by 1 = e^-z/e^-z to eliminate overflow error
def Wintr(x):
    num = x**3 * (np.exp(-x / (1 - x)))  # numerator
    den = (1 - x)**5 * (1 - np.exp(-x / (1 - x)))  # denominator
    return num / den


# Create array to hold results of integral calculations for each N
Wintgs = []
# Add arbitrary first value so recursive subtraction will work
Wintgs.append(0)
# Return evaluation of integral for each number of sample points
# Check this result against the previous one to see if we have
# acheieved convergence.

N = 0
while N < len(Ns):
    # required tolerance (if increasing N changes result by less than
    # this, assume max accuracy acheived).
    eps = 1e-14
    Wintg = gaussint(Wintr, Ns[N], a, b)  # value of integral for given N
    print 'N = {0}, integral = {1:.13f}'.format(Ns[N], Wintg)  # print result
    diff = abs(Wintg - Wintgs[N - 1])  # compare with previous result
    if diff < eps:  # if difference is less than tolerance stop loop
        print 'Integral value converged at N = {0}'.format(Ns[N])
        N = len(Ns)
    elif diff > eps:  # else, continue increasing N
        Wintgs.append(Wintg)
        N += 1
Exemple #5
0
	         \n Cannot compute eigenvalues with numpy.linalg.eigvalsh'''

# Create x array to span well
x = np.linspace(0,L,1000)
# Choose number of integration points for integral to normalize psi
Nsamp = 50

# Create list to hold the probablity density information
probden = []

# Find the first three probability density functions
# (ground, first excited and second excited states).
for k in range(3):
	psi_n = evecs[k] # Isolate Fourier coefficients for given state
	psi2 = wavefn2(x,(mmax,psi_n)) # Compute the probability density function for x
	A2 = gaussint(wavefn2,Nsamp,0,L,(mmax,psi_n)) # Compute normalization 
	psi2 /= A2 # Normalize probability function
	probden.append(psi2)

# Plot the probability of each state across the well's width
plt.xlim(0,5e-10)
plt.plot(x,probden[0],label = 'Ground State')
plt.plot(x,probden[1],label = 'First Excited State')
plt.plot(x,probden[2],label = 'Second Excited State')
plt.ylabel('$|\psi(x)|^2$',fontsize = 20)
plt.xlabel('$x\,[m]$',fontsize = 20)
plt.title('Probability Density for Asymmetric Quantum Well')
plt.legend(loc = 'best')
plt.show()

Exemple #6
0
# Function returns z^3/(exp(z) - 1)dz under change of variables 
# z = x/(1-x). This makes the integration limits finite.
# multiply by 1 = e^-z/e^-z to eliminate overflow error
def Wintr(x):
	num = x**3*(np.exp(-x/(1-x))) # numerator
	den = (1-x)**5 * (1-np.exp(-x/(1-x))) # denominator
	return num/den

# Create array to hold results of integral calculations for each N
Wintgs = []
# Add arbitrary first value so recursive subtraction will work
Wintgs.append(0) 
# Return evaluation of integral for each number of sample points
# Check this result against the previous one to see if we have 
# acheieved convergence.

N = 0
while N < len(Ns):
	# required tolerance (if increasing N changes result by less than 
	# this, assume max accuracy acheived).
	eps = 1e-14
	Wintg = gaussint(Wintr,Ns[N],a,b) # value of integral for given N
	print 'N = {0}, integral = {1:.13f}'.format(Ns[N],Wintg) # print result
	diff = abs(Wintg - Wintgs[N-1]) # compare with previous result
	if diff < eps: # if difference is less than tolerance stop loop
		print 'Integral value converged at N = {0}'.format(Ns[N])
		N = len(Ns)
	elif diff > eps: # else, continue increasing N
		Wintgs.append(Wintg)
		N +=1
Exemple #7
0
	         \n Cannot compute eigenvalues with numpy.linalg.eigvalsh'''

# Create x array to span well
x = np.linspace(0, L, 1000)
# Choose number of integration points for integral to normalize psi
Nsamp = 50

# Create list to hold the probablity density information
probden = []

# Find the first three probability density functions
# (ground, first excited and second excited states).
for k in range(3):
    psi_n = evecs[k]  # Isolate Fourier coefficients for given state
    psi2 = wavefn2(
        x, (mmax, psi_n))  # Compute the probability density function for x
    A2 = gaussint(wavefn2, Nsamp, 0, L, (mmax, psi_n))  # Compute normalization
    psi2 /= A2  # Normalize probability function
    probden.append(psi2)

# Plot the probability of each state across the well's width
plt.xlim(0, 5e-10)
plt.plot(x, probden[0], label='Ground State')
plt.plot(x, probden[1], label='First Excited State')
plt.plot(x, probden[2], label='Second Excited State')
plt.ylabel('$|\psi(x)|^2$', fontsize=20)
plt.xlabel('$x\,[m]$', fontsize=20)
plt.title('Probability Density for Asymmetric Quantum Well')
plt.legend(loc='best')
plt.show()