Plot 如何在Julia中绘制3D高斯的时间演化?
我想画一个三维高斯分布的时间演化图。 是sin(r)/r的表面版本代码。Plot 如何在Julia中绘制3D高斯的时间演化?,plot,3d,julia,physics,Plot,3d,Julia,Physics,我想画一个三维高斯分布的时间演化图。 是sin(r)/r的表面版本代码。 所以我写了一个代码来引用它 using Makie using FileIO using LinearAlgebra using AbstractPlotting scene = Scene(backgroundcolor = :black); f(x,y,z) = exp(-((x)^2 + (y)^2 + (z)^2)) r = LinRange(-5, 5, 50) vol_func(t)
所以我写了一个代码来引用它
using Makie
using FileIO
using LinearAlgebra
using AbstractPlotting
scene = Scene(backgroundcolor = :black);
f(x,y,z) = exp(-((x)^2 + (y)^2 + (z)^2))
r = LinRange(-5, 5, 50)
vol_func(t) = [Float64(f(x - cos(t),y - sin(t),z - t)) for x = r, y = r,z = r]
vol = volume!(scene,r,r,r,vol_func(20),algorithm = :mip)[end]
scene[Axis].names.textcolor = :gray
N = 20
scene
record(scene, "voloutput.mp4", range(0, stop = 5, length = N)) do t
vol[3] = vol_func(t)
end
但是这个代码不起作用
MethodError: Cannot `convert` an object of type Array{Float64,3} to an object of type LinRange{Float64}
我应该如何修复代码
附加说明初始时间的快照如下所示。() 我想看到黄色区域呈螺旋状移动。(2020/08/28) 我刚刚意识到不是第[3]卷,而是第[4]卷。然后,它成功了。 但我还有一个问题。(2020/08/31)
我试着为你做同样的事情 这里,H(Lx,Ly,Lz)是一个由系统大小Lx,Ly,Lz和N=Lx×Ly×Lz参数化的N×N矩阵。H(Lx,Ly,Lz)的示例代码为。 那么 但是这个代码有一个错误
ArgumentError: range(0.0, stop=5.0, length=1): endpoints differ
错在哪里
我发现了错误。(2020/09/02)
然后,代码通过并获得mp4动画。但在mp4文件中看不到绘图。为什么…
using LinearAlgebra
using OrdinaryDiffEq
using DifferentialEquations
#Define the underlying equation
function time_evolution(ψdot,ψ,p,t)
ψdot.=-im.*H(Lx,Ly,Lz)*ψ
end
Lx = Ly = Lz = 10
ψ0 = [] # Initial conditions
for iz = 1:Lz
for ix = 1:Lx
for iy = 1:Ly
gauss = exp(-((ix)^2 + (iy)^2 + (iz)^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)
using Makie
using FileIO
using LinearAlgebra
using AbstractPlotting
using ColorSchemes
x = 1: Lx # our value range
y = 1: Ly
z = 1: Lz
ρ(ix,iy,iz,nt) = abs2.((sol[nt][(iz-1)*Lx*Ly + (ix-1)*Ly + (iy-1)])./norm(sol[nt][(iz-1)*Lx*Ly + (ix-1)*Ly + (iy-1)]))
ψ(nt) = Float64[ρ(ix,iy,iz,nt) for ix in x, iy in y,iz in z]
scene = Scene(backgroundcolor = :white)
c = ψ(length(sol.t))
vol = volume!(
scene,
x, y, z, # coordinates to plot on
c, # charge density (functions as colorant)
algorithm = :mip, # maximum-intensity-projection
colorrange = (0,0.01),
transparency = true,
)[end]
update_cam!(scene, Vec3f0(1,0.5,0.1), Vec3f0(0))
scene[Axis].names.textcolor = :gray # let axis labels be seen on darkbackground
record(scene, "output.mp4", range(0, stop = length(sol.t)-1, length = 1)) do nt
vol[4] = ψ(nt)
end
ArgumentError: range(0.0, stop=5.0, length=1): endpoints differ
sol[nt]→sol(nt)
range(0, stop = length(sol.t)-1, length = 1)→range(0, stop = 1.0, length = 20)