Reputation: 147
I have created a gif of a phase plane of a damped pendulum. To do that I use the package DifferentialEquations.jl for the integration and the packages Plots.jl with the pyplot backend and ImageMagick.jl for the plotting and animation. To do that, I integrate the function for different initial values, and each of them for lots of times so I get some small fragment that together shape the final plot in the form of a gif. The code is the following:
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)
This code worked nice the first time I ran it. However, I tried to run it again changing the tfinal
and it showed this: signal (11): Segmentation fault: 11
(this is just the first line of the message from julia). Then I tried to run again the initial code and I get the same message. After reinitiating julia and the computer I get the same message. I changed again the tfinal
and it worked again and for every tfinal
I wanted to use. I have my desired output. However, it bothers me the fact that the julia "reaction" to my code is inconsistent. If needed I could paste the full error but is quite long.
EDIT: Here is the full error message
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]
Upvotes: 2
Views: 1327
Reputation: 19132
The segmentation fault was because your timespan was trivial.
x = linspace(0.0,50.0,101)
tfinal = collect(x)
Notice then that tfinal[1]=0.0
, so the first timespan is (0.0,0.0)
. What it was doing is giving a trivial diffeq solution, then trying to plot it, ending up with a bounds error, but bounds checking was turned off. Ouch. I put a commit in so that way the next patch will make this throw an error alerting the user that the timespan is trivial.
That means that the way to solve this is to remove the first timepoint:
x = linspace(0.0,50.0,101)
tfinal = collect(x)[2:end]
This will do fine.
You may also want to look at the provided animation interface. Not sure if it can easily animate everything in the order you want though: that might take more Plots.jl controls.
Upvotes: 1