首页 > 解决方案 > Julia中3d晶格上的时间相关薛定谔方程

问题描述

我想用DifferentialEquations.jl求解 3d 晶格上的矩阵形式时间相关薛定谔方程,
即 (∂/∂t)ψ = -i H ψ ,其中 ψ 是向量,H 是(与时间无关的)矩阵。
我试着写这样的代码。

#Define the underlying equation
function time_evolution(ψdot,ψ,p,t)
  ψdot.=-im.*H(Lx,Ly,Lz)*ψ
end

Lx = Ly = Lz = 10
ψ0 = [] #  Initial conditions
σ = sqrt(5/2)

for iz = 1:Lz
    for ix = 1:Lx
        for iy = 1:Ly                  
           gauss = (1/(sqrt(2*π)*σ)^3)*exp(-((ix)^2 + (iy)^2 + (iz)^2)/(2*(σ)^2))
           push!(ψ0,gauss)                           
        end
    end
end

tspan = (0.,1.0) #  Simulation time span


#Pass to Solvers
prob = ODEProblem(time_evolution,ψ0,tspan)
sol = solve(prob)

这里,H(Lx,Ly,Lz) 是由系统大小 Lx,Ly,Lz 和 N = Lx×Ly×Lz 参数化的 N×N 矩阵。
但是这段代码有错误。

StackOverflowError:
Stacktrace:
 [1] recursive_unitless_bottom_eltype(::Type{Any}) at 
/Users/username/.julia/packages/RecursiveArrayTools/OAIEc/src/utils.jl:86 (repeats 
80000 times)

代码中的错误在哪里?

标签: juliaphysicsdifferential-equations

解决方案


ψ0 = [] #  Initial conditions

你可能不希望你的方程是非具体类型的,所以你可能想做

ψ0 = Float64[] #  Initial conditions

推荐阅读