SciML / DelayDiffEq.jl

Delay differential equation (DDE) solvers in Julia for the SciML scientific machine learning ecosystem. Covers neutral and retarded delay differential equations, and differential-algebraic equations.
Other
58 stars 26 forks source link

`Dopri5` solver doesn't work for DDEs #260

Open thibmonsel opened 1 year ago

thibmonsel commented 1 year ago

Hello I was playing around with the DDE solver on some equations and consistently Dopri5 doesn't integrate properly.

MWE :

using DifferentialEquations
using DelimitedFiles
using PyPlot
using Metrics

# Basic check 1 =========================================
function basic_check_1(du, u, h, p, t)
    tau = p
    hist1 = h(p, t - tau)[1]
    du[1] = u[1] * (1 - hist1)
end

h(p, t) = 1.2 * ones(1)
u0 = [1.2]
tau = 1.0
lags = [tau]
p = (tau)
tspan = (0.0, 20.0)

prob = DDEProblem(basic_check_1, u0, h, tspan, p; constant_lags=lags)
alg = MethodOfSteps(Tsit5()) # doesn't work with DP5 DP8 but works with Tsit5 and Bosh3
sol = solve(prob, alg, saveat=0.1)
usol = transpose(hcat(sol.u...))
time = sol.t

alg2 = MethodOfSteps(DP5()) # doesn't work with DP5 DP8 but works with Tsit5 and Bosh3
sol2 = solve(prob, alg2, saveat=0.1)
usol2 = transpose(hcat(sol2.u...))

alg3 = MethodOfSteps(BS3()) # doesn't work with DP5 DP8 but works with Tsit5 and Bosh3
sol3 = solve(prob, alg3, saveat=0.1)
usol3 = transpose(hcat(sol3.u...))

plot(sol.t, usol, linestyle="dashed", label="Tsit5")
plot(sol.t, usol2, linestyle="dashdot", label="Dopri5")
plot(sol.t, usol3, linestyle="dotted", label="Bosh3")
plt.title("x' = x * (1 - x(t-1))")
plt.legend()
plt.xlabel("Time")
# plt.savefig("exp1.png")
plt.show()
plt.close()

I haven't checked the source code but I would guess that it comes from the Butcher tableau if an ODE example with Dopri5 doesn't work (I didn't check)