JuliaDynamics/DynamicalSystems.jl

Support for Complex number equations?

LianGentleWind opened this issue · 3 comments

The example is simple:

using DynamicalSystems

function route(dx, x, p, t)
    dx[1] =  1im * ( p[1] * x[1] - 2 * real(x[2]) * x[1] - 0.5) - 0.05 * x[1]
    dx[2] = -1im * (0.75 * abs(x[1])^2 + x[2]) - 0.0005* x[2]
end

ds = DiscreteDynamicalSystem(route, ComplexF64[0, 0], [1])

Was trying to define a Dynamical system. And:

ArgumentError: Cannot create a dual over scalar type ComplexF64. If the type behaves as a scalar, define ForwardDiff.can_dual(::Type{ComplexF64}) = true.

So I manually set

ForwardDiff.can_dual(::Type{ComplexF64}) = true

And run it again:

MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{DynamicalSystemsBase.var"#5#11"{typeof(route), Vector{Int64}, Int64}, ComplexF64}, ComplexF64, 2})
Closest candidates are:
  (::Type{T})(::Real, ::RoundingMode) where T<:AbstractFloat at C:\Softwares\Julia\share\julia\base\rounding.jl:200
  (::Type{T})(::T) where T<:Number at C:\Softwares\Julia\share\julia\base\boot.jl:770 
  (::Type{T})(::VectorizationBase.Double{T}) where T<:Union{Float16, Float32, Float64, VectorizationBase.Vec{<:Any, <:Union{Float16, Float32, Float64}}, VectorizationBase.VecUnroll{var"#s35", var"#s34", var"#s33", V} where {var"#s35", var"#s34", var"#s33"<:Union{Float16, Float32, Float64}, V<:Union{Bool, Float16, Float32, Float64, Int16, Int32, Int64, Int8, UInt16, UInt32, UInt64, UInt8, SIMDTypes.Bit, VectorizationBase.AbstractSIMD{var"#s34", var"#s33"}}}} at 

If I remove the im in the equation and change ComplexF64 to Float64 then it works fine.
So does this mean DynamicalSystem.jl doesn't support complex numbers?

Package versions

versions:

  [608a59af] ChaosTools v2.8.1
  [5732040d] DelayEmbeddings v2.1.0
  [61744808] DynamicalSystems v2.3.0
  [6e36e845] DynamicalSystemsBase v2.7.0
  [ed8fcbec] Entropies v1.1.2
  [639c3291] RecurrenceAnalysis v1.8.0

Hi,

sorry this will never be supported in DynamicalSystems.jl. Within the nonlinear dynamics theory it is much better to decompose your complex numbers into formal equations for the real and imaginary parts. Otherwise you are "hiding" the dimensionality of your state space. The example you post above is not two dimensional, but four. Decomposing that enables the rest of the library to work, because many algorithms must know the state space dimensionality to work. And with complex numbers, you can never know if the dimensionality is twice as much, or something in between.

So in conclusion, re-write your equations with real numbers by separating real and imaginary parts.

However, I am re-opening this, because an error needs to be put into the dynamical system creation when the state has complex numbers. The error should say "decompose into reals.".

Hello! I am a first time contributor and I would like to help with this issue :)