我创建了一个阻尼摆相平面的 gif。为此,我使用包 DifferentialEquations.jl 进行集成,使用包 Plots.jl 和 pyplot 后端,使用 ImageMagick.jl 进行绘图和动画。为此,我为不同的初始值集成了函数,并且将它们中的每一个集成了很多次,因此我得到了一些小片段,它们共同以 gif 的形式形成最终图。代码如下:
using DifferentialEquations
using Plots ; default(size=(1000,700))
pyplot()
using ImageMagick
x = linspace(0.0,50.0,101)
tfinal = collect(x)
b = 0.2
p = plot()
u0vals = ([pi,-2.41],[2.0*pi,-2.41],[-2.0*pi,-3.0],[-2pi,3.0])
anim = @animate for j=1:endof(tfinal)
for i=1:endof(u0vals)
f = function(t,u,du)
du[1] = u[2]
du[2] = -b*u[2] -sin(u[1])
end
u0 = u0vals[i]
tspan=(0.0,tfinal[j])
prob = ODEProblem(f, u0, tspan)
sol = solve(prob)
plot!(p, sol, vars=(1,2),arrow=true,legend = false, titlefont=font(15, "cursive"),title = "STRO Figure 6.7.7", linewidth=1,linecolor=:"black",xlims=(-15.0,10.0),border=false,ticks=nothing,grid=false)
end
end
gif(anim, "STRO_6_7_7_GIF_.gif",fps=5)
这段代码在我第一次运行时运行良好。但是,我尝试再次运行它来更改它tfinal
,它显示了这一点:(signal (11): Segmentation fault: 11
这只是来自 julia 的消息的第一行)。然后我尝试再次运行初始代码并收到相同的消息。重新启动 julia 和计算机后,我收到相同的消息。我再次更改了tfinal
它并且它再次工作并且对于tfinal
我想要使用的每一个。我有我想要的输出。然而,让我感到困扰的是 julia 对我的代码的“反应”是不一致的。如果需要,我可以粘贴完整的错误,但很长。
编辑:这是完整的错误信息
signal (11): Segmentation fault: 11
while loading no file, in expression starting on line 0
ode_interpolation at /Users/pacagal/.julia/v0.5/OrdinaryDiffEq/src/dense/generic_dense.jl:134
[inlined]
InterpolationData at /Users/pacagal/.julia/v0.5/OrdinaryDiffEq/src/interp_func.jl:20
unknown function (ip: 0x32b584519)
macro expansion at /Users/pacagal/.julia/v0.5/DiffEqBase/src/solutions/solution_interface.jl:72 [inlined]
apply_recipe at /Users/pacagal/.julia/v0.5/RecipesBase/src/RecipesBase.jl:238
unknown function (ip: 0x32b5808c6)
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9 x64/build/src/./julia_internal.h:189 [inlined]
jl_apply_generic at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1942
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia.h:1392 [inlined]
jl_f__apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/builtins.c:547
_process_userrecipes at /Users/pacagal/.julia/v0.5/Plots/src/pipeline.jl:73
_plot! at /Users/pacagal/.julia/v0.5/Plots/src/plot.jl:171
unknown function (ip: 0x32b57bbed)
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia_internal.h:189 [inlined]
jl_apply_generic at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1942
#plot!#266 at /Users/pacagal/.julia/v0.5/Plots/src/plot.jl:151
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia_internal.h:189 [inlined]
jl_apply_generic at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1942
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia.h:1392 [inlined]
jl_f__apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/builtins.c:547
#plot! at ./<missing>:0
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia_internal.h:189 [inlined]
jl_apply_generic at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1942
macro expansion; at ./REPL[10]:11 [inlined]
macro expansion; at /Users/pacagal/.julia/v0.5/Plots/src/animation.jl:154 [inlined]
anonymous at ./<missing> (unknown line)
unknown function (ip: 0x32b5566ff)
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia_internal.h:189 [inlined]
jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:569
jl_toplevel_eval_in_warn at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/builtins.c:590
eval at ./boot.jl:234
jlcall_eval_19752 at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia_internal.h:189 [inlined]
jl_apply_generic at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1942
eval_user_input at ./REPL.jl:64
unknown function (ip: 0x3192d9e66)
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia_internal.h:189 [inlined]
jl_apply_generic at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1942
macro expansion at ./REPL.jl:95 [inlined]
#3 at ./event.jl:68
unknown function (ip: 0x3192d30df)
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia_internal.h:189 [inlined]
jl_apply_generic at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1942
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia.h:1392 [inlined]
start_task at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/task.c:253
Allocations: 40525029 (Pool: 40521241; Big: 3788); GC: 71
[Proceso completado]