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
59 stars 26 forks source link

saveat doubles the end point #93

Closed ChrisRackauckas closed 5 years ago

ChrisRackauckas commented 5 years ago
function delay_lotka_volterra(du,u,h,p,t)
  x, y = u
  α, β, δ, γ = p
  du[1] = dx = (α - β*y)*h(p,t-0.1)[1]
  du[2] = dy = (δ*x - γ)*y
end
h(p,t) = ones(eltype(p),2)
prob = DDEProblem(delay_lotka_volterra,[1.0,1.0],h,(0.0,10.0),[2.2, 1.0, 2.0, 0.4],constant_lags=[0.1])
sol = solve(prob,MethodOfSteps(Tsit5()),saveat=0.1)
length(sol)
length(0:0.1:10.0)
devmotion commented 5 years ago

An easy fix is to make the inequality in https://github.com/JuliaDiffEq/DelayDiffEq.jl/blob/master/src/integrator_utils.jl#L99 strict; in this example the final time point is included in saveat_internal due to https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/blob/0196b4fe34cce662d7069242f6f8668271c3fb98/src/solve.jl#L396 but the final time point is added anyway in the end, see https://github.com/JuliaDiffEq/DelayDiffEq.jl/blob/master/src/integrator_utils.jl#L180-L185.

devmotion commented 5 years ago

Nevertheless, IMO the logic of how solutions are created should be simplified if possible... It feels a bit overcomplicated at the moment :smile:

ChrisRackauckas commented 5 years ago

Indeed, it's quite complicated.