# Issue with Complex DifferentialEquations

**URL:** <https://discourse.julialang.org/t/issue-with-complex-differentialequations/99432>\
**Category:** New to Julia\
**Created:** [May 26, 2023, 8:35am UTC](https://discourse.julialang.org/t/issue-with-complex-differentialequations/99432 "2023-05-26T08:35:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javad\_Vahedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/javad_vahedi/32/50070_2.png) [@Javad\_Vahedi](https://discourse.julialang.org/u/Javad_Vahedi)\
**Post date:** [May 26, 2023, 8:35am UTC](https://discourse.julialang.org/t/issue-with-complex-differentialequations/99432/1 "2023-05-26T08:35:35Z")

</div>

Dear Julia community,

bellow you can find the function of interest:

```julia
using DifferentialEquations
using OMEinsum
using LinearAlgebra
function ctwa!(du::Matrix{ComplexF64}, u::Matrix{ComplexF64}, 
               par::Tuple{Matrix{Float64}, Array{Float64, 4}, Array{ComplexF64, 3}}, 
               t::Float64)
    @views B_eff, J_eff, Tab = par
   
    # Tab : d, D , D
    # B_eff : d, Nc
    # J_eff : d, d, Nc, Nc
    # u shape : Nc , D   
    uConj = conj(u)

    @ein BTy[i,a] := B_eff[β,i] * Tab[β,a,b] * u[i,b]
    @ein JTTyyy[i,a] := J_eff[β,γ,i,j] * Tab[β,a,b] * Tab[γ,c,d] * u[i,b] * uConj[j,c] * u[j,d]
    @views du .= -im * (BTy + JTTyyy)
end 

prob = ODEProblem(ctwa!, y0, (TMIN,TMAX), par)
sol = solve( prob , AutoTsit5(Rosenbrock23()), alg_hints=[:stiff], 
                    saveat=TIMEPOINTS, verbose=true)

```

Unfortunately, I am getting a long error message, which I just pasted a few lines bellow:

> >

**ERROR:** LoadError: ArgumentError: Cannot create a dual over scalar type ComplexF64. If the type behaves as a scalar, define ForwardDiff.can\_dual(::Type{ComplexF64}) = true.

Stacktrace:

[1] **throw\_cannot\_dual(V::Type)**

@ ForwardDiff ~/.julia/packages/ForwardDiff/vXysl/src/dual.jl:41

[2] **ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, ComplexF64}, ComplexF64, 1}(value::ComplexF64, partials::ForwardDiff.Partials{1, ComplexF64})**

@ ForwardDiff ~/.julia/packages/ForwardDiff/vXysl/src/dual.jl:18

\<\<\<

Any help would be greatly appreciated.  
JV

---

<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:** [May 26, 2023, 1:02pm UTC](https://discourse.julialang.org/t/issue-with-complex-differentialequations/99432/2 "2023-05-26T13:02:01Z")

</div>

> [@Javad\_Vahedi](#):
>
> ```julia
> sol = solve( prob , AutoTsit5(Rosenbrock23()), alg_hints=[:stiff], 
> saveat=TIMEPOINTS, verbose=true)
> 
> ```

ForwardDiff has some issues with complex. Do:

```julia
sol = solve( prob , AutoTsit5(Rosenbrock23(autodiff=false)), alg_hints=[:stiff], 
                    saveat=TIMEPOINTS, verbose=true)

```

---

<div class="post-metadata">

**Author:** ![Javad\_Vahedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/javad_vahedi/32/50070_2.png) [@Javad\_Vahedi](https://discourse.julialang.org/u/Javad_Vahedi)\
**Post date:** [May 26, 2023, 1:42pm UTC](https://discourse.julialang.org/t/issue-with-complex-differentialequations/99432/3 "2023-05-26T13:42:44Z")

</div>

Many thanks, it worked well.
