我已经使用以下代码来实现它
import numpy as np
from scipy.linalg import eig
import matplotlib.pyplot as plt
W = 10 #width of well
n = 1000 #number of points excluding 0,W
hbar = 1;m=1 #atomic units
x = np.linspace(1,W-1,num=n) #exclusion of 0,W
h = x[1]-x[0]#step size
#Construction of the hamiltonian matrix
H = np.zeros([n,n],dtype=complex)
for i in range(n):
H[i][i] = -2
if(i-1>=0):
H[i][i-1] = 1
if(i+1<n):
H[i][i+1] = 1
H = -1*(hbar**2)/(2*m*(h**2))*H
E,V = eig(H)
plt.plot(x,np.abs(V[:][0]),'.')
plt.plot(x,np.abs(V[:][1]),'.')
plt.show()
我想知道为什么这段代码不够优化,无法重现接近分析解决方案的结果,以及错误的来源是什么。
编辑:
N=10,000 的输出

但是,它运行大约需要 45 分钟

