InexactError when trying to define in DynamicalSystems.jl

I am trying to create a dynamical system using the DynamicalSystems.jl package. However, I am encountering a very basic problem when trying to define a system.

using DynamicalSystems;
function L63_eom!(du, u, p, t)
         du[1] = p[1]*(u[2]-u[1]);
         du[2] = u[1]*(p[2]-u[3])-u[2];
         du[3] = u[1]*u[2]-p[3]*u[3];
         return nothing;
end
L63_param = [10.0, 28.0, 8.0/3 ];
L63 = ContinuousDynamicalSystem( L63_eom!, [0, 1, 0], L63_param );

I get the following error.

ERROR: InexactError: Int64(-2.6666666666666665)
Stacktrace:
 [1] Type at ./float.jl:703 [inlined]
 [2] convert at ./number.jl:7 [inlined]
 [3] convert at ./essentials.jl:304 [inlined] (repeats 3 times)
 [4] Type at /home/dass/.julia/packages/ForwardDiff/N0wMF/src/partials.jl:2 [inlined]
 [5] convert at /home/dass/.julia/packages/ForwardDiff/N0wMF/src/partials.jl:74 [inlined]
 [6] convert at /home/dass/.julia/packages/ForwardDiff/N0wMF/src/dual.jl:355 [inlined]
 [7] setindex! at ./array.jl:766 [inlined]
 [8] L63_eom!(::Array{ForwardDiff.Dual{ForwardDiff.Tag{getfield(DynamicalSystemsBase, Symbol("##7#14")){typeof(L63_eom!),Array{Float64,1},Int64},Int64},Int64,3},1}, ::Array{ForwardDiff.Dual{ForwardDiff.Tag{getfield(DynamicalSystemsBase, Symbol("##7#14")){typeof(L63_eom!),Array{Float64,1},Int64},Int64},Int64,3},1}, ::Array{Float64,1}, ::Int64) at ./REPL[7]:4
 [9] #9 at /home/dass/.julia/packages/DynamicalSystemsBase/W0ZBG/src/dynamicalsystem.jl:298 [inlined]
 [10] vector_mode_dual_eval(::getfield(DynamicalSystemsBase, Symbol("##9#16")){Array{Float64,1},Int64,typeof(L63_eom!)}, ::Array{Int64,1}, ::Array{Int64,1}, ::ForwardDiff.JacobianConfig{ForwardDiff.Tag{getfield(DynamicalSystemsBase, Symbol("##7#14")){typeof(L63_eom!),Array{Float64,1},Int64},Int64},Int64,3,Tuple{Array{ForwardDiff.Dual{ForwardDiff.Tag{getfield(DynamicalSystemsBase, Symbol("##7#14")){typeof(L63_eom!),Array{Float64,1},Int64},Int64},Int64,3},1},Array{ForwardDiff.Dual{ForwardDiff.Tag{getfield(DynamicalSystemsBase, Symbol("##7#14")){typeof(L63_eom!),Array{Float64,1},Int64},Int64},Int64,3},1}}}) at /home/dass/.julia/packages/ForwardDiff/N0wMF/src/apiutils.jl:44
 [11] vector_mode_jacobian!(::Array{Int64,2}, ::getfield(DynamicalSystemsBase, Symbol("##9#16")){Array{Float64,1},Int64,typeof(L63_eom!)}, ::Array{Int64,1}, ::Array{Int64,1}, ::ForwardDiff.JacobianConfig{ForwardDiff.Tag{getfield(DynamicalSystemsBase, Symbol("##7#14")){typeof(L63_eom!),Array{Float64,1},Int64},Int64},Int64,3,Tuple{Array{ForwardDiff.Dual{ForwardDiff.Tag{getfield(DynamicalSystemsBase, Symbol("##7#14")){typeof(L63_eom!),Array{Float64,1},Int64},Int64},Int64,3},1},Array{ForwardDiff.Dual{ForwardDiff.Tag{getfield(DynamicalSystemsBase, Symbol("##7#14")){typeof(L63_eom!),Array{Float64,1},Int64},Int64},Int64,3},1}}}) at /home/dass/.julia/packages/ForwardDiff/N0wMF/src/jacobian.jl:164
 [12] jacobian! at /home/dass/.julia/packages/ForwardDiff/N0wMF/src/jacobian.jl:74 [inlined]
 [13] #8 at /home/dass/.julia/packages/DynamicalSystemsBase/W0ZBG/src/dynamicalsystem.jl:297 [inlined]
 [14] get_J(::getfield(DynamicalSystemsBase, Symbol("##8#15")){typeof(L63_eom!),Array{Int64,1},ForwardDiff.JacobianConfig{ForwardDiff.Tag{getfield(DynamicalSystemsBase, Symbol("##7#14")){typeof(L63_eom!),Array{Float64,1},Int64},Int64},Int64,3,Tuple{Array{ForwardDiff.Dual{ForwardDiff.Tag{getfield(DynamicalSystemsBase, Symbol("##7#14")){typeof(L63_eom!),Array{Float64,1},Int64},Int64},Int64,3},1},Array{ForwardDiff.Dual{ForwardDiff.Tag{getfield(DynamicalSystemsBase, Symbol("##7#14")){typeof(L63_eom!),Array{Float64,1},Int64},Int64},Int64,3},1}}}}, ::Array{Int64,1}, ::Array{Float64,1}, ::Int64, ::Bool) at /home/dass/.julia/packages/DynamicalSystemsBase/W0ZBG/src/dynamicalsystem.jl:318
 [15] #ContinuousDynamicalSystem#2(::Float64, ::Type{ContinuousDynamicalSystem}, ::Function, ::Array{Int64,1}, ::Array{Float64,1}) at /home/dass/.julia/packages/DynamicalSystemsBase/W0ZBG/src/dynamicalsystem.jl:239
 [16] ContinuousDynamicalSystem(::Function, ::Array{Int64,1}, ::Array{Float64,1}) at /home/dass/.julia/packages/DynamicalSystemsBase/W0ZBG/src/dynamicalsystem.jl:228
 [17] top-level scope at REPL[8]:1

Why would the program try to convert a parameter value into Int64 ?

Just a guess but it looks like you are specifying your initial conditions as an Int64 array and so it assumes that your states are Int64 rather than Float64. Try using [0.0, 1.0, 0.0] instead of [0, 1, 0].

3 Likes

Thank you, you were right. Becaue the function L63_eom was a generic function, probably Julia tries to switch to Int64 arithmetic when it reads the vector [0,1,1].