HERMITE6 = [ (x)->(1), # Hermite_0 polynomial
(x)->(2x),
(x)->(4x^2-2),
(x)->(8x^3 - 12x),
(x)->(16x^4 - 48x^2 + 12),
(x)->(32x^5 - 160 - 120x) ]
SQRPI = 1.7724538509055159 # square root of pi
function getHermite(n)
return HERMITE6[n+1] # because Jl start indicies at 1
end
function computeHermite(x,n)
f = getHermite(n)
return f(x)
end
function qho_WaveFact(n)
return (1 / sqrt( 2^n * factorial(n) ))
end
function qho_WaveNatX(x,n)
norm = 0.10627834566699294
WF = qho_WaveFact(n)
H_n = computeHermite(x,n)
return ( norm* WF * H_n * exp( -0.5 * x^2 ) )
end
function gaussianPert(x;alpha=4)
return ( (1/alpha)*exp(-0.5x^2) )
end
function qho_EnergyN(n)
norm4 = 0.10627834566699294^4
hBar = 1.05457e-34
return ( (n + 0.5) * norm4 * hBar^2 * pi )
end
wsp = linspace(-10,10,1000)
psi1 = zeros(1000)
phi1 = zeros(1000)
psi2 = zeros(1000)
phi2 = zeros(1000)
gPert1 = zeros(1000)
for i in [1:1000]
psi1[i] = qho_WaveNatX( wsp[i], 0 )
phi1[i] = qho_WaveNatX( wsp[i], 0 )
psi2[i] = qho_WaveNatX( wsp[i], 1 )
phi2[i] = qho_WaveNatX( wsp[i], 1 )
gPert1[i] = gaussianPert( wsp[i] )
end
println(dot( psi1, phi1 ))
println(dot( psi2, phi2 ))
println(dot( psi1, phi2 ))
println(dot( psi2, phi1 ))
for i in [1:1000]
phi1[i] = gPert1[i] * phi1[i]
end
dot(phi1, psi1)
1/sqrt(88.53406985273054)
qho_EnergyN(0)
16 * 4
64 - 3 - 3
58 / 5
58 / 7
acos(2/3)*180/pi
function fillWaveMat(n, N, dVec)
m = zeros(n,N)
for i = [1:N]
for j = [1:n]
m[j,i] = qho_WaveNatX( dVec[j], i-1 )
end
end
return m
end
function fillPsiNCol(n, N; left=-4, right=4)
return fillWaveMat(n, N, linspace(left,right,n) )
end
function fillPsiNRow(n, N; left=-4, right=4)
return transpose( fillPsiNCol(n, N) )
end
p_mat = fillPsiNCol( 100, 4 )
p_tmat = fillPsiNRow( 100, 4)
function qho_HKet( h, ket )
for i = [1:size(ket)[1]]
for j = [1:size(ket)[2]]
ket[i,j] = ket[i,j] * h[i]
end
end
return ket
end
function qho_PertKet()
ket = fillPsiNCol( 100, 4)
h = linspace(-4,4,100)
for i = [1:100]
h[i] = gaussianPert(h[i])
end
return qho_HKet( h, ket )
end
qho_PertKet()
HT = fillPsiNRow(100,4)*qho_PertKet()
hte = eigvecs(HT)
qho_e = transpose(hte)*HT*hte
# used to clobber terms in a matrix with NaN
function squishMat(mat; tol = 1e-16)
sz = size(mat)
for i = [1:sz[1]]
for j = [1:sz[2]]
if ((mat[i,j] == NaN) || (mat[i,j] <= tol))
mat[i,j] = 0
end
end
end
return mat
end
squishMat(qho_e)
function diffMatN(N)
m = zeros(N,N)
m[1,1] = -1
m[1,2] = 1
for i = [2:(N-1)]
m[i,(i-1)] = -1
m[i,i] = 0
m[i,(i+1)] = 1
end
m[N,(N-1)] = -1
m[N,N] = 1
return m
end
d1 = diffMatN(10)
d1*d1*d1*d1