Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Complex number equations? #181

Open
LianGentleWind opened this issue Apr 21, 2022 · 3 comments
Open

Support for Complex number equations? #181

LianGentleWind opened this issue Apr 21, 2022 · 3 comments

Comments

@LianGentleWind
Copy link

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
@Datseris
Copy link
Member

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.

@Datseris Datseris reopened this Apr 21, 2022
@Datseris
Copy link
Member

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.".

@MA-Ramirez
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants