DiffEquations and DateTime abscissa

I’m solving an ODE, and want to change the time axis (abscissa) to a Date – or rather: DateTime.

using Plots, Dates, DifferentialEquations
# test case
tust!(x,p,t) = -x/p + 2sin(t*2pi)
x0 = 3.
p = 0.5
prob = ODEProblem(tust!,x0,tspan,p)
sol = solve(prob)

I can transform the solution by:

mymap(t,x) = (t,-2x)

leading to:

I can do a “manual” plotting with dates:

function timeperiod(x::Float64)
    Second(Int(floor(Second(Day(1)).value * x)))
tm = DateTime(2020,10,21) + timeperiod.(sol.t)

leading to

However, if I try to do the following:

mymap2(t,x) = (DateTime(2020,10,21) + timeperiod(t),-2x)

this does not work… I get the following:

Question: how can I fix this so that I use the plotting recipe of DifferentialEquations and maintain the smoothness of the interpolation of DifferentialEquations?

What about directly solving where time itself is a date time? Does that actually work? If so… that might be the easiest way to do this.

1 Like

Interesting idea. I’ll check. I have solved the problem for now using the interpolating solution for up-sampling – works fine.