我创建了阻尼摆的相位平面的GIF。为此,我将包装差异差异。为此,我将功能集成了不同的初始值,并且每个值都在很多次中集成在一起,因此我得到了一些小片段,它们以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)消息的第一行)。然后,我尝试再次运行初始代码,然后收到相同的消息。在重新启动朱莉娅和计算机后,我收到了相同的消息。我再次更改了tfinal
,它再次起作用,对于我想使用的每个tfinal
。我有所需的输出。但是,这让我感到困扰,即朱莉娅对我的代码的"反应"是不一致的。如果需要,我可以粘贴全部错误,但很长。
编辑:这是完整的错误消息
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]
分割故障是因为您的时间pan很微不足道。
x = linspace(0.0,50.0,101)
tfinal = collect(x)
请注意,然后tfinal[1]=0.0
,因此第一个timespan是 (0.0,0.0)
。它正在做的是给出一个琐碎的diffeq解决方案,然后尝试绘制它,最终以界限错误,但关闭了界限检查。哎哟。我提交了一个提交,这样下一个补丁将使此丢失错误,以提醒用户Timespan很微不足道。
这意味着解决此问题的方法是删除第一个时间点:
x = linspace(0.0,50.0,101)
tfinal = collect(x)[2:end]
这会很好。
您可能还想查看提供的动画接口。不确定它是否可以轻松地按照您想要的顺序进行动画。