hilbert2
Science Advisor
- 1,600
- 607
DrClaude said:The potential of the square well is uniquely 0 on the finite spatial grid. Otherwise, a term ##V(x)## would appear on the diagonal.
Yes, if for instance we have a harmonic oscillator potential ##V(x) \propto (x-x_0 )^2##, the discretized potential ##V_n = V(n\Delta x)## appears on the diagonal elements. My code that calculates the three lowest energy states of this system is below:
Code:
L <- 6.0 # Length of the domain
N <- 150 # Number of discrete points
dx <- L/N
A = matrix(nrow = N, ncol = N) # Hamiltonian matrix
V = c(1:N)
for(m in c(1:N))
{
V[m] = 3.0*(m*dx - 3.0)*(m*dx - 3.0) # define a harmonic oscillator potential with spring constant k = 6
}
for(m in c(1:N)) # Fill the Hamiltonian matrix with elements appropriate for a harmonic oscillator system
{
for(n in c(1:N))
{
A[m,n]=0
if(m == n) A[m,n] = 2/dx^2 - V[m]
if(m == n-1 || m == n+1) A[m,n]=-1/dx^2
}
}
v = eigen(A) # Solve the eigensystem
vec = v$vectors
psi1 = c(1:N)
psi2 = c(1:N)
psi3 = c(1:N)
xaxis = c(1:N)*L/N
for(m in c(1:N))
{
psi1[m] = vec[m,1] # Fill the psi-vectors with the eigenfunction values
psi2[m] = vec[m,2]
psi3[m] = vec[m,3]
}
jpeg(file = "plot.jpg") # Plot the probability densities for the ground state and two excited states above it
plot(xaxis, 0.01*V, ylim=c(0,0.04))
lines(xaxis, 0.01*V)
lines(xaxis,abs(psi1)^2)
lines(xaxis,abs(psi2)^2)
lines(xaxis,abs(psi3)^2)
dev.off()
A plot of V(x) and the approximate probability densities for quantum numbers n=0, n=1 and n=2 looks like this: