# Method Error: No mathching method when using ContinuousDynamicalSystem

**URL:** <https://discourse.julialang.org/t/method-error-no-mathching-method-when-using-continuousdynamicalsystem/52040>\
**Category:** Numerics\
**Tags:** differentiation, forwarddiff\
**Created:** [December 18, 2020, 11:33am UTC](https://discourse.julialang.org/t/method-error-no-mathching-method-when-using-continuousdynamicalsystem/52040 "2020-12-18T11:33:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gary\_McCormack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gary_mccormack/32/20727_2.png) [@Gary\_McCormack](https://discourse.julialang.org/u/Gary_McCormack)\
**Post date:** [December 18, 2020, 11:33am UTC](https://discourse.julialang.org/t/method-error-no-mathching-method-when-using-continuousdynamicalsystem/52040/1 "2020-12-18T11:33:45Z")

</div>

Hi everyone,  
I’m very new to Julia and trying to wrap my head around the following error. This is a stripped-down version of the ODE I am trying to wrap as a Continuous Dynamical System.

```julia
using DifferentialEquations
using ChaosTools

@inline @inbounds function ODE(dy, y, p, t)
    alpha = p
    gamma = alpha * t

    dy[1] = -1im * (-y[2] +gamma*y[1] )
    dy[2] = -1im * (-(y[1]+y[3]) )
    dy[3] = -1im * (-y[2] - gamma*y[3] )

    return SVector{3}(dy[1],dy[2],dy[3])
end

p = [0] 

y0=[ -0.9950737714883371,
 -0.09901475429766803,
 -0.004926228511662883]

ds=ContinuousDynamicalSystem(ODE,y0,p)

```

However, this produces the following error message

```julia
LoadError: MethodError: no method matching +(::ForwardDiff.Dual{ForwardDiff.Tag{DynamicalSystemsBase.var"#13#20"{Array{Float64,1},Float64,typeof(ODE)},Float64},Float64,3}, ::Array{ForwardDiff.Dual{ForwardDiff.Tag{DynamicalSystemsBase.var"#13#20"{Array{Float64,1},Float64,typeof(ODE)},Float64},Float64,3},1})
For element-wise addition, use broadcasting with dot syntax: scalar .+ array
Closest candidates are:
  +(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:538
  +(!Matched::ChainRulesCore.DoesNotExist, ::Any) at /Users/garymccormack/.julia/packages/ChainRulesCore/cpHLu/src/differential_arithmetic.jl:23
  +(!Matched::ChainRulesCore.One, ::Any) at /Users/garymccormack/.julia/packages/ChainRulesCore/cpHLu/src/differential_arithmetic.jl:94
  ...
in expression starting at /Users/garymccormack/OneDrive - The University of Nottingham/ExtendedBoseHubbard/TripleWell/longrange/LyapunovExp/Lyap_RydDress.jl:45
ODE at Lyap_RydDress.jl:19 [inlined]
(::DynamicalSystemsBase.var"#13#20"{Array{Float64,1},Float64,typeof(ODE)})(::StaticArrays.SArray{Tuple{3},ForwardDiff.Dual{ForwardDiff.Tag{DynamicalSystemsBase.var"#13#20"{Array{Float64,1},Float64,typeof(ODE)},Float64},Float64,3},1,3}) at dynamicalsystem.jl:313
static_dual_eval at apiutils.jl:32 [inlined]
vector_mode_jacobian at jacobian.jl:178 [inlined]
jacobian at jacobian.jl:85 [inlined]
(::DynamicalSystemsBase.var"#12#19"{typeof(ODE)})(::StaticArrays.SArray{Tuple{3},Float64,1,3}, ::Array{Float64,1}, ::Float64) at dynamicalsystem.jl:312
get_J(::DynamicalSystemsBase.var"#12#19"{typeof(ODE)}, ::StaticArrays.SArray{Tuple{3},Float64,1,3}, ::Array{Float64,1}, ::Float64, ::Bool) at dynamicalsystem.jl:324
ContinuousDynamicalSystem(::Function, ::Array{Float64,1}, ::Array{Float64,1}; t0::Float64) at dynamicalsystem.jl:243
ContinuousDynamicalSystem(::Function, ::Array{Float64,1}, ::Array{Float64,1}) at dynamicalsystem.jl:231
top-level scope at Lyap_RydDress.jl:45
include_string(::Function, ::Module, ::String, ::String) at loading.jl:1088

```

I’m still learning how to read error messages from Julia and I’m struggling big time with this!  
I **think** it may have something to do with the ODE being a complex ODE, but I’m not sure…  
Would anyone be able to help me out?  
Thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 18, 2020, 2:05pm UTC](https://discourse.julialang.org/t/method-error-no-mathching-method-when-using-continuousdynamicalsystem/52040/2 "2020-12-18T14:05:38Z")

</div>

Your initial condition should be complex numbers if your numbers are eventually complex.

---

<div class="post-metadata">

**Author:** ![Gary\_McCormack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gary_mccormack/32/20727_2.png) [@Gary\_McCormack](https://discourse.julialang.org/u/Gary_McCormack)\
**Post date:** [December 18, 2020, 3:19pm UTC](https://discourse.julialang.org/t/method-error-no-mathching-method-when-using-continuousdynamicalsystem/52040/3 "2020-12-18T15:19:08Z")

</div>

Hi Chris, thanks for the quick reply.  
I’ve included the line

```julia
y0=complex(y0)

```

however now it raises an Argument Error

```julia
ERROR: LoadError: ArgumentError: Cannot create a dual over scalar type Complex{Float64}. If the type behaves as a scalar, define FowardDiff.can_dual.
Stacktrace:
 [1] throw_cannot_dual(::Type{T} where T) at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/dual.jl:36
 [2] ForwardDiff.Dual{ForwardDiff.Tag{DynamicalSystemsBase.var"#13#20"{Array{Float64,1},Complex{Float64},typeof(ODE)},Complex{Float64}},Complex{Float64},3}(::Complex{Float64}, ::ForwardDiff.Partials{3,Complex{Float64}}) at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/dual.jl:18
 [3] Dual at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/dual.jl:55 [inlined]
 [4] Dual at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/dual.jl:67 [inlined]
 [5] macro expansion at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/apiutils.jl:28 [inlined]
 [6] dualize at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/apiutils.jl:21 [inlined]
 [7] static_dual_eval at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/apiutils.jl:32 [inlined]
 [8] vector_mode_jacobian at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/jacobian.jl:178 [inlined]
 [9] jacobian at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/jacobian.jl:85 [inlined]
 [10] (::DynamicalSystemsBase.var"#12#19"{typeof(ODE)})(::StaticArrays.SArray{Tuple{3},Complex{Float64},1,3}, ::Array{Float64,1}, ::Complex{Float64}) at /Users/garymccormack/.julia/packages/DynamicalSystemsBase/dkA8o/src/dynamicalsystem.jl:312
 [11] get_J(::DynamicalSystemsBase.var"#12#19"{typeof(ODE)}, ::StaticArrays.SArray{Tuple{3},Complex{Float64},1,3}, ::Array{Float64,1}, ::Complex{Float64}, ::Bool) at /Users/garymccormack/.julia/packages/DynamicalSystemsBase/dkA8o/src/dynamicalsystem.jl:324
 [12] ContinuousDynamicalSystem(::Function, ::Array{Complex{Float64},1}, ::Array{Float64,1}; t0::Float64) at /Users/garymccormack/.julia/packages/DynamicalSystemsBase/dkA8o/src/dynamicalsystem.jl:243
 [13] ContinuousDynamicalSystem(::Function, ::Array{Complex{Float64},1}, ::Array{Float64,1}) at /Users/garymccormack/.julia/packages/DynamicalSystemsBase/dkA8o/src/dynamicalsystem.jl:231
 [14] top-level scope at /Users/garymccormack/OneDrive - The University of Nottingham/ExtendedBoseHubbard/TripleWell/longrange/LyapunovExp/Lyap_RydDress.jl:46
 [15] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1088
in expression starting at /Users/garymccormack/OneDrive - The University of Nottingham/ExtendedBoseHubbard/TripleWell/longrange/LyapunovExp/Lyap_RydDress.jl:46

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 18, 2020, 3:34pm UTC](https://discourse.julialang.org/t/method-error-no-mathching-method-when-using-continuousdynamicalsystem/52040/4 "2020-12-18T15:34:25Z")

</div>

Double check: is this fine using DifferentialEquations.jl directly instead of through DynamicalSystems.jl?

---

<div class="post-metadata">

**Author:** ![Gary\_McCormack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gary_mccormack/32/20727_2.png) [@Gary\_McCormack](https://discourse.julialang.org/u/Gary_McCormack)\
**Post date:** [December 18, 2020, 4:00pm UTC](https://discourse.julialang.org/t/method-error-no-mathching-method-when-using-continuousdynamicalsystem/52040/5 "2020-12-18T16:00:11Z")

</div>

If I was to solve the differential equations directly I would use

```julia
prob = ODEProblem(ODE, collect(Complex{Float64}, y0), tspan, p)

```

where tspan is defined as`(0,20)`

This produces no errors and I have gotten nice results from it :).  
However, I’m trying to encapsulate the ODE as a Continuous Dynamical system to perform a Lyapunov spectrum analysis on the system, which is where I’m getting the original errors from.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 18, 2020, 7:53pm UTC](https://discourse.julialang.org/t/method-error-no-mathching-method-when-using-continuousdynamicalsystem/52040/6 "2020-12-18T19:53:54Z")

</div>

This is a problem for @Datseris

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [December 19, 2020, 4:29pm UTC](https://discourse.julialang.org/t/method-error-no-mathching-method-when-using-continuousdynamicalsystem/52040/7 "2020-12-19T16:29:51Z")

</div>

Hi, thanks a lot for the tag Chris. @Gary_McCormack could please be so kind to open an issue with this code in [DynamicalSystemsBase.jl](https://github.com/JuliaDynamics/DynamicalSystemsBase.jl) ? I’ll have a look when I have some extra free time 🙂

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [December 19, 2020, 4:31pm UTC](https://discourse.julialang.org/t/method-error-no-mathching-method-when-using-continuousdynamicalsystem/52040/8 "2020-12-19T16:31:56Z")

</div>

> However, I’m trying to encapsulate the ODE as a Continuous Dynamical system to perform a Lyapunov spectrum analysis on the system, which is where I’m getting the original errors from.

This will not work with the algorithm for the Lyapunov exponents. You have to separate the real and imaginary parts, as your system is 6-dimensional, not 3-dimensional, given that all components are complex numbers. The Lyapunov exponents operate on the full state space and you have to resolve its dimensionality fully.

Re-write your equations so that you have 6 real numbers as variables and it will work.

In dynamical systems we assume that the dimensionality of the state space is `length(u0)`.
