# Using DynamicalSystems: InexactError

Dear all, I have a question about the meaning of some output messages from the package DynamicalSystems from Lyapunov Exponents · DynamicalSystems.jl.
This error message appears when I tried to study a dynamical system with four equations Please find below the very small program and the messages. I would like to obtain the Lyapunov exponent.

Bests regards,

using DynamicalSystems # also exports relevant StaticArrays names
@inline @inbounds function loop(u, p, t)
nU = p[1]; nW = p[2];

``````du1=-(-((u[1]*(-nW*(1 + u[1]*u[2]) - 2*nW*u[3]*u[4]))/( 2*(1 + u[1]*u[2] + u[3]*u[4]))) + ( 1im*(u[1]^2*u[2]*(nU + u[3]) -
u[3]*(1 + u[3]*u[4]) + (-1 + u[1]^2)*(1 + u[1]*u[2] + u[3]*u[4]) +u[1]*(-nU + u[3]*(1 - u[2] + u[3]*u[4]))))/(1 + u[1]*u[2] + u[3]*u[4]))
du2=-((1im*(u[1]*u[2]^2*(nU + u[4]) - u[4]*(1 + u[3]*u[4]) + (-1 + u[2]^2)*(1 + u[1]*u[2] + u[3]*u[4]) + u[2]*(-nU + u[4]*(1 - u[1]+u[3]*u[4]))))/(1+u[1]*u[2]+
``````

u[3]u[4]))
du3=-((nW
u[3](1 + u[3]u[4]))/(2(1 + u[1]u[2] + u[3]u[4])) - 1im(1 + u[1] - u[3]^2 + u[3](-u[1] + (nU - nUu[3]u[4])/(1 + u[1]u[2] + u[3]u[4]))))
du4=-((nW
u[4]
(1 + u[3]u[4]))/(2(1 + u[1]u[2] + u[3]u[4])) + 1im(1 + u[2] - u[4]^2 + u[4](-u[2] + (nU - nU
u[3]*u[4])/(1 + u[1]*u[2] + u[3]*u[4]))))
return SVector{4}(du1, du2, du3, du4)
end

# Jacobian:

@inline @inbounds function loop_jac(u, p, t)
nU = p[1]; nW = p[2];
J= [(-nW * (u[1] * u[2] + 1) - 2 * nW * u[3] * u[4]) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) - u[1] * nW * u[2] / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) - 2 * u[1] * (-nW * (u[1] * u[2] + 1) - 2 * nW * u[3] * u[4]) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) ^ 2 * u[2] + -1im * (2 * u[1] * u[2] * (nU + u[3]) + 2 * u[1] * (u[1] * u[2] + u[3] * u[4] + 1) + (u[1] ^ 2 - 1) * u[2] - nU + u[3] * (u[3] * u[4] - u[2] + 1)) / (u[1] * u[2] + u[3] * u[4] + 1) + 1im * (u[1] ^ 2 * u[2] * (nU + u[3]) - u[3] * (u[3] * u[4] + 1) + (u[1] ^ 2 - 1) * (u[1] * u[2] + u[3] * u[4] + 1) + u[1] * (-nU + u[3] * (u[3] * u[4] - u[2] + 1))) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[2] -u[1] ^ 2 * nW / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) - 2 * u[1] ^ 2 * (-nW * (u[1] * u[2] + 1) - 2 * nW * u[3] * u[4]) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) ^ 2 + -1im * (u[1] ^ 2 * (nU + u[3]) + (u[1] ^ 2 - 1) * u[1] - u[1] * u[3]) / (u[1] * u[2] + u[3] * u[4] + 1) + 1im * (u[1] ^ 2 * u[2] * (nU + u[3]) - u[3] * (u[3] * u[4] + 1) + (u[1] ^ 2 - 1) * (u[1] * u[2] + u[3] * u[4] + 1) + u[1] * (-nU + u[3] * (u[3] * u[4] - u[2] + 1))) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[1] -2 * u[1] * nW * u[4] / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) - 2 * u[1] * (-nW * (u[1] * u[2] + 1) - 2 * nW * u[3] * u[4]) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) ^ 2 * u[4] + -1im * (u[1] ^ 2 * u[2] - 2 * u[3] * u[4] - 1 + (u[1] ^ 2 - 1) * u[4] + u[1] * (2 * u[3] * u[4] - u[2] + 1)) / (u[1] * u[2] + u[3] * u[4] + 1) + 1im * (u[1] ^ 2 * u[2] * (nU + u[3]) - u[3] * (u[3] * u[4] + 1) + (u[1] ^ 2 - 1) * (u[1] * u[2] + u[3] * u[4] + 1) + u[1] * (-nU + u[3] * (u[3] * u[4] - u[2] + 1))) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[4] -2 * u[1] * nW * u[3] / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) - 2 * u[1] * (-nW * (u[1] * u[2] + 1) - 2 * nW * u[3] * u[4]) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) ^ 2 * u[3] + -1im * (-u[3] ^ 2 + (u[1] ^ 2 - 1) * u[3] + u[1] * u[3] ^ 2) / (u[1] * u[2] + u[3] * u[4] + 1) + 1im * (u[1] ^ 2 * u[2] * (nU + u[3]) - u[3] * (u[3] * u[4] + 1) + (u[1] ^ 2 - 1) * (u[1] * u[2] + u[3] * u[4] + 1) + u[1] * (-nU + u[3] * (u[3] * u[4] - u[2] + 1))) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[3]; -1im * (u[2] ^ 2 * (nU + u[4]) + (u[2] ^ 2 - 1) * u[2] - u[2] * u[4]) / (u[1] * u[2] + u[3] * u[4] + 1) + 1im * (u[1] * u[2] ^ 2 * (nU + u[4]) - u[4] * (u[3] * u[4] + 1) + (u[2] ^ 2 - 1) * (u[1] * u[2] + u[3] * u[4] + 1) + u[2] * (-nU + u[4] * (u[3] * u[4] - u[1] + 1))) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[2] -1im * (2 * u[1] * u[2] * (nU + u[4]) + 2 * u[2] * (u[1] * u[2] + u[3] * u[4] + 1) + (u[2] ^ 2 - 1) * u[1] - nU + u[4] * (u[3] * u[4] - u[1] + 1)) / (u[1] * u[2] + u[3] * u[4] + 1) + 1im * (u[1] * u[2] ^ 2 * (nU + u[4]) - u[4] * (u[3] * u[4] + 1) + (u[2] ^ 2 - 1) * (u[1] * u[2] + u[3] * u[4] + 1) + u[2] * (-nU + u[4] * (u[3] * u[4] - u[1] + 1))) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[1] -1im * (-u[4] ^ 2 + (u[2] ^ 2 - 1) * u[4] + u[2] * u[4] ^ 2) / (u[1] * u[2] + u[3] * u[4] + 1) + 1im * (u[1] * u[2] ^ 2 * (nU + u[4]) - u[4] * (u[3] * u[4] + 1) + (u[2] ^ 2 - 1) * (u[1] * u[2] + u[3] * u[4] + 1) + u[2] * (-nU + u[4] * (u[3] * u[4] - u[1] + 1))) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[4] -1im * (u[1] * u[2] ^ 2 - 2 * u[3] * u[4] - 1 + (u[2] ^ 2 - 1) * u[3] + u[2] * (2 * u[3] * u[4] - u[1] + 1)) / (u[1] * u[2] + u[3] * u[4] + 1) + 1im * (u[1] * u[2] ^ 2 * (nU + u[4]) - u[4] * (u[3] * u[4] + 1) + (u[2] ^ 2 - 1) * (u[1] * u[2] + u[3] * u[4] + 1) + u[2] * (-nU + u[4] * (u[3] * u[4] - u[1] + 1))) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[3]; 2 * nW * u[3] * (u[3] * u[4] + 1) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) ^ 2 * u[2] + 1im * (1 + u[3] * (-1 - (-nU * u[3] * u[4] + nU) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[2])) 2 * nW * u[3] * (u[3] * u[4] + 1) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) ^ 2 * u[1] + -1im * u[3] * (-nU * u[3] * u[4] + nU) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[1] -nW * (u[3] * u[4] + 1) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) - nW * u[3] * u[4] / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) + 2 * nW * u[3] * (u[3] * u[4] + 1) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) ^ 2 * u[4] + 1im * (-2 * u[3] - u[1] + (-nU * u[3] * u[4] + nU) / (u[1] * u[2] + u[3] * u[4] + 1) + u[3] * (-nU * u[4] / (u[1] * u[2] + u[3] * u[4] + 1) - (-nU * u[3] * u[4] + nU) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[4])) -nW * u[3] ^ 2 / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) + 2 * nW * u[3] ^ 2 * (u[3] * u[4] + 1) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) ^ 2 + 1im * u[3] * (-nU * u[3] / (u[1] * u[2] + u[3] * u[4] + 1) - (-nU * u[3] * u[4] + nU) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[3]); 2 * nW * u[4] * (u[3] * u[4] + 1) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) ^ 2 * u[2] + 1im * u[4] * (-nU * u[3] * u[4] + nU) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[2] 2 * nW * u[4] * (u[3] * u[4] + 1) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) ^ 2 * u[1] + -1im * (1 + u[4] * (-1 - (-nU * u[3] * u[4] + nU) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[1])) -nW * u[4] ^ 2 / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) + 2 * nW * u[4] ^ 2 * (u[3] * u[4] + 1) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) ^ 2 + -1im * u[4] * (-nU * u[4] / (u[1] * u[2] + u[3] * u[4] + 1) - (-nU * u[3] * u[4] + nU) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[4]) -nW * (u[3] * u[4] + 1) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) - nW * u[3] * u[4] / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) + 2 * nW * u[3] * (u[3] * u[4] + 1) / (2 * u[1] * u[2] + 2 * u[3] * u[4] + 2) ^ 2 * u[4] + -1im * (-2 * u[4] - u[2] + (-nU * u[3] * u[4] + nU) / (u[1] * u[2] + u[3] * u[4] + 1) + u[4] * (-nU * u[3] / (u[1] * u[2] + u[3] * u[4] + 1) - (-nU * u[3] * u[4] + nU) / (u[1] * u[2] + u[3] * u[4] + 1) ^ 2 * u[3]))]
return J
end

ds = ContinuousDynamicalSystem(loop, rand(4), [1, 1, 1], loop_jac)
λ = lyapunov(ds, 100, d0 = 1e-7, upper_threshold = 1e-4, Ttr = 100)

error message

InexactError: Float64(-0.45320104263522193 + 0.7182458475836356im)

Stacktrace:
[1] Real
@ .\complex.jl:44 [inlined]
[2] convert
@ .\number.jl:7 [inlined]
[3] macro expansion
@ C:\Users\griff.julia\packages\StaticArraysCore\gkLqH\src\StaticArraysCore.jl:79 [inlined]
[4] convert_ntuple
@ C:\Users\griff.julia\packages\StaticArraysCore\gkLqH\src\StaticArraysCore.jl:75 [inlined]
[5] SVector{4, Float64}(x::NTuple{4, ComplexF64})
@ StaticArraysCore C:\Users\griff.julia\packages\StaticArraysCore\gkLqH\src\StaticArraysCore.jl:111
[6] convert
@ C:\Users\griff.julia\packages\StaticArrays\5bAMi\src\convert.jl:168 [inlined]
[7] setindex!
@ .\array.jl:903 [inlined]
[8] (::DynamicalSystemsBase.var"#30#32"{ContinuousDynamicalSystem{false, SVector{4, Float64}, 4, typeof(loop), Vector{Int64}, typeof(loop_jac), Matrix{ComplexF64}, false}, Int64})(du::Vector{SVector{4, Float64}}, u::Vector{SVector{4, Float64}}, p::Vector{Int64}, t::Float64)
@ DynamicalSystemsBase C:\Users\griff.julia\packages\DynamicalSystemsBase\56NGa\src\core\create_dynamics.jl:83
[9] ODEFunction
@ C:\Users\griff.julia\packages\SciMLBase\IJbT7\src\scimlfunctions.jl:1624 [inlined]
[10] step!
@ C:\Users\griff.julia\packages\SimpleDiffEq\vIpeG\src\tsit5\atsit5.jl:458 [inlined]
[11] step!
@ C:\Users\griff.julia\packages\SimpleDiffEq\vIpeG\src\tsit5\atsit5.jl:592 [inlined]
[12] step!
@ C:\Users\griff.julia\packages\SimpleDiffEq\vIpeG\src\tsit5\atsit5.jl:586 [inlined]
[13] lyapunov(pinteg::SimpleDiffEq.SimpleATsit5Integrator{true, Vector{SVector{4, Float64}}, Float64, Vector{Int64}, SciMLBase.ODEFunction{true, DynamicalSystemsBase.var"#30#32"{ContinuousDynamicalSystem{false, SVector{4, Float64}, 4, typeof(loop), Vector{Int64}, typeof(loop_jac), Matrix{ComplexF64}, false}, Int64}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(DynamicalSystemsBase._parallelnorm)}, T::Int64, Ttr::Int64, Δt::Int64, d0::Float64, ut::Float64, lt::Float64)
@ ChaosTools C:\Users\griff.julia\packages\ChaosTools\PHPDF\src\chaosdetection\lyapunovs.jl:355
[14] lyapunov(ds::ContinuousDynamicalSystem{false, SVector{4, Float64}, 4, typeof(loop), Vector{Int64}, typeof(loop_jac), Matrix{ComplexF64}, false}, T::Int64; u0::SVector{4, Float64}, Ttr::Int64, d0::Float64, upper_threshold::Float64, lower_threshold::Float64, inittest::ChaosTools.var"#217#218"{Int64}, Δt::Int64, diffeq::NamedTuple{(), Tuple{}}, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ ChaosTools C:\Users\griff.julia\packages\ChaosTools\PHPDF\src\chaosdetection\lyapunovs.jl:347
[15] top-level scope
@ In[19]:1
[16] eval
@ .\boot.jl:373 [inlined]
[17] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
Your initial condition is real but it looks like you have an `im` in the Jacobian definition at least, so it’s failing to convert the dynamics to complex numbers. You should choose a complex initial condition if you want it to solve in complex numbers.