The following code tries to solve the complex ODE y’ = (0.3 + it)sin(y)/v with y(-5) = 0.53 + 0.3i.
using DifferentialEquations
function sysDEUD!(dΦdξ, Φ, p, ξ)
ν, x₀ = p
η = x₀ + im*ξ
dΦdξ[1] = η*sin(Φ)/ν
end
Φ₀ = complex(0.53, 0.3)
prob = ODEProblem(sysDEUD!, Φ₀, (-5.0, 5.0), (0.1, 0.3))
L = 5
N = 2500
solve(prob, saveat = LinRange(-L, L, N))
This returns the following error:
ERROR: MethodError: no method matching similar(::ComplexF64, ::Type{ComplexF64})
Closest candidates are:
similar(::Union{LinearAlgebra.Adjoint{T, var"#s832"}, LinearAlgebra.Transpose{T, var"#s832"}} where {T, var"#s832"<:(AbstractVector{T} where T)}, ::Type{T}) where T at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\adjtrans.jl:230
similar(::Union{LinearAlgebra.Adjoint{T, S}, LinearAlgebra.Transpose{T, S}} where {T, S}, ::Type{T}) where T at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\adjtrans.jl:234
similar(::Union{LinearAlgebra.Adjoint{T, S}, LinearAlgebra.Transpose{T, S}} where {T, S}, ::Type{T}, ::Tuple{Vararg{Int64, N}}) where {T, N} at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\adjtrans.jl:235
...
Stacktrace:
[1] alg_cache(alg::Vern9, u::ComplexF64, rate_prototype::ComplexF64, #unused#::Type{ComplexF64}, #unused#::Type{ComplexF64}, #unused#::Type{Float64}, uprev::ComplexF64, uprev2::ComplexF64, f::ODEFunction{true, typeof(sysDEUD!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, t::Float64, dt::Float64, reltol::Float64, p::Tuple{Float64, Float64}, calck::Bool, #unused#::Val{true})
@ OrdinaryDiffEq C:\Users\licer\.julia\packages\OrdinaryDiffEq\6gTvi\src\caches\verner_caches.jl:161
[2] macro expansion
@ C:\Users\licer\.julia\packages\OrdinaryDiffEq\6gTvi\src\caches\basic_caches.jl:0 [inlined]
[3] __alg_cache(algs::Tuple{Vern9, Rodas5{0, false, DefaultLinSolve, Val{:forward}}}, u::ComplexF64, rate_prototype::ComplexF64, #unused#::Type{ComplexF64}, #unused#::Type{ComplexF64}, #unused#::Type{Float64}, uprev::ComplexF64, uprev2::ComplexF64, f::ODEFunction{true, typeof(sysDEUD!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, t::Float64, dt::Float64, reltol::Float64,
p::Tuple{Float64, Float64}, calck::Bool, #unused#::Val{true})
@ OrdinaryDiffEq C:\Users\licer\.julia\packages\OrdinaryDiffEq\6gTvi\src\caches\basic_caches.jl:19
[4] alg_cache(alg::CompositeAlgorithm{Tuple{Vern9, Rodas5{0, false, DefaultLinSolve, Val{:forward}}}, OrdinaryDiffEq.AutoSwitchCache{Vern9, Rodas5{0, false, DefaultLinSolve, Val{:forward}}, Rational{Int64}, Int64}}, u::ComplexF64, rate_prototype::ComplexF64,
#unused#::Type{ComplexF64}, #unused#::Type{ComplexF64}, #unused#::Type{Float64}, uprev::ComplexF64, uprev2::ComplexF64, f::ODEFunction{true, typeof(sysDEUD!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, t::Float64, dt::Float64, reltol::Float64, p::Tuple{Float64, Float64}, calck::Bool, #unused#::Val{true})
@ OrdinaryDiffEq C:\Users\licer\.julia\packages\OrdinaryDiffEq\6gTvi\src\caches\basic_caches.jl:14
[5] __init(prob::ODEProblem{ComplexF64, Tuple{Float64, Float64}, true, Tuple{Float64, Float64}, ODEFunction{true, typeof(sysDEUD!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, alg::CompositeAlgorithm{Tuple{Vern9, Rodas5{0, false, DefaultLinSolve, Val{:forward}}}, AutoSwitch{Vern9, Rodas5{0, false, DefaultLinSolve, Val{:forward}}, Rational{Int64}, Int64}}, timeseries_init::Tuple{}, ts_init::Tuple{}, ks_init::Tuple{}, recompile::Type{Val{true}}; saveat::LinRange{Float64}, tstops::Tuple{}, d_discontinuities::Tuple{}, save_idxs::Nothing, save_everystep::Bool, save_on::Bool, save_start::Bool, save_end::Nothing, callback::Nothing, dense::Bool, calck::Bool, dt::Float64, dtmin::Nothing, dtmax::Float64, force_dtmin::Bool, adaptive::Bool, gamma::Rational{Int64}, abstol::Nothing, reltol::Nothing, qmin::Rational{Int64}, qmax::Int64, qsteady_min::Int64, qsteady_max::Int64, beta1::Nothing, beta2::Nothing, qoldinit::Rational{Int64}, controller::Nothing, fullnormalize::Bool, failfactor::Int64, maxiters::Int64, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), internalopnorm::typeof(LinearAlgebra.opnorm), isoutofdomain::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), unstable_check::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), verbose::Bool, timeseries_errors::Bool, dense_errors::Bool, advance_to_tstop::Bool, stop_at_next_tstop::Bool, initialize_save::Bool, progress::Bool, progress_steps::Int64, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), userdata::Nothing, allow_extrapolation::Bool, initialize_integrator::Bool, alias_u0::Bool, alias_du0::Bool, initializealg::OrdinaryDiffEq.DefaultInit, kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol, Symbol}, NamedTuple{(:default_set, :second_time), Tuple{Bool, Bool}}})
@ OrdinaryDiffEq C:\Users\licer\.julia\packages\OrdinaryDiffEq\6gTvi\src\solve.jl:295
[6] __solve(::ODEProblem{ComplexF64, Tuple{Float64, Float64}, true, Tuple{Float64, Float64}, ODEFunction{true, typeof(sysDEUD!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, ::CompositeAlgorithm{Tuple{Vern9, Rodas5{0, false, DefaultLinSolve, Val{:forward}}}, AutoSwitch{Vern9, Rodas5{0, false, DefaultLinSolve, Val{:forward}}, Rational{Int64}, Int64}}; kwargs::Base.Iterators.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:default_set, :second_time, :saveat), Tuple{Bool, Bool, LinRange{Float64}}}})
@ OrdinaryDiffEq C:\Users\licer\.julia\packages\OrdinaryDiffEq\6gTvi\src\solve.jl:4
[7] __solve(::ODEProblem{ComplexF64, Tuple{Float64, Float64}, true, Tuple{Float64, Float64}, ODEFunction{true, typeof(sysDEUD!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, ::Nothing; default_set::Bool, kwargs::Base.Iterators.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:second_time, :saveat), Tuple{Bool, LinRange{Float64}}}})
@ DifferentialEquations C:\Users\licer\.julia\packages\DifferentialEquations\GBjZU\src\default_solve.jl:8
[8] #__solve#57
@ C:\Users\licer\.julia\packages\DiffEqBase\b1nST\src\solve.jl:291 [inlined]
[9] #solve_call#42
@ C:\Users\licer\.julia\packages\DiffEqBase\b1nST\src\solve.jl:61 [inlined]
[10] #solve_up#44
@ C:\Users\licer\.julia\packages\DiffEqBase\b1nST\src\solve.jl:90 [inlined]
[11] #solve#43
@ C:\Users\licer\.julia\packages\DiffEqBase\b1nST\src\solve.jl:73 [inlined]
[12] top-level scope
@ REPL[43]:1
I’ve looked at other posts such as this one but it doesn’t seem relevant / nor does it solve the problem. Any suggestions on why this might be?