julia - 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)
代码中的错误在哪里?
解决方案
ψ0 = [] # Initial conditions
你可能不希望你的方程是非具体类型的,所以你可能想做
ψ0 = Float64[] # Initial conditions
推荐阅读
- javascript - 用于调查结果的 Firebase 数据库
- asp.net - 在 asp.net mvc 中编辑已部署网站的控制器或模型而不接触数据库
- laravel-5 - Laravel 5.6/Bootstrap 4.1.0 应用程序中的不同颜色主题
- angular - 无法在 mapbox-gl 弹出窗口中加载角度组件
- sql - SQL Server:非聚集日期索引
- laravel - ErrorException (E_ERROR) 试图获取非对象的属性“生日”
- mysql - 选择作为孩子没有特定价值的记录
- spring - spring security标签库sec:授权url不起作用
- javascript - 反应原生谷歌登录失败。错误代码 10
- json - 为什么我的 json 返回 nil