方勢阱薛定諤方程

from numpy import array,arangenn# Constantsnm = 9.1094e-31 # Mass of electronnhbar = 1.0546e-34 # Plancks constant over 2*pine = 1.6022e-19 # Electron chargenL = 5.2918e-11 # Bohr radiusnN = 1000nh = L/Nnn# Potential functionndef V(x):n return 0.0nndef f(r,x,E):n psi = r[0]n phi = r[1]n fpsi = phin fphi = (2*m/hbar**2)*(V(x)-E)*psin return array([fpsi,fphi],float)nn# Calculate the wavefunction for a particular energyndef solve(E):n psi = 0.0n phi = 1.0n r = array([psi,phi],float)nn for x in arange(0,L,h):n k1 = h*f(r,x,E)n k2 = h*f(r+0.5*k1,x+0.5*h,E)n k3 = h*f(r+0.5*k2,x+0.5*h,E)n k4 = h*f(r+k3,x+h,E)n r += (k1+2*k2+2*k3+k4)/6nn return r[0]nn# Main program to find the energy using the secant methodnE1 = 0.0nE2 = enpsi2 = solve(E1)nntarget = e/1000nwhile abs(E1-E2)>target:n psi1,psi2 = psi2,solve(E2)n E1,E2 = E2,E2-psi2*(E2-E1)/(psi2-psi1)nnprint("E =",E2/e,"eV")n

E = 134.286371694 eV


推薦閱讀:

Python SciPy庫——擬合與插值
Python有哪些可以做帶約束的二次線性規劃的包?
擴散方程
Python科學計算與自動控制1-Python入門
使用VASPy快速處理VASP文件以及數據可視化

TAG:计算物理学 | 科学计算 | Python |