Convert continuous time (ODESystem) to discrete time system?

I’d like to take a continuous time ODE, and convert it to a discrete time system, along the lines of c2d in ControlSystems.jl.

Here’s the ODE version:

Here’s the discrete-time equivalent:

I suspect that this is easy using ModelingToolkit (now that it has DiscreteProblem support), and that there is something out-of-the-box to do this, but I can’t find it.

A slightly harder version is to take a ReactionSystem and convert it to a discrete time Markov process - any pointers here would also be great!

I’m not sure exactly what you would like the result to be, a discrete-time simulation, or the discrete-time symbolic equations?

In either case, there is no support for this at the moment. For general MTK models, this “conversion” implies integration, so what you’re asking for would require the ability to choose the integration method etc. Looking at the discrete-time equations is pretty meaningless already for simple integrators like RK4, so I assume that you are interested in a numerical simulation with a particular integrator? You can of course already achieve this by adaptive=false and dt=δt when you call solve

To clarify, f you look at the specific examples I gave, there is an integration of the rates in the ODE to give proportions in the map; my question was whether this can be done symbolically in the current MTK. I’ll think about it some more (c2d does much the same thing in a different setting…)

I don’t recognize the integration scheme used in your code.

There is no feature to carry out this transformation at the moment, but if you describe it as an algorithm it can certainly be automated.

The example there is just a discrete time model? the new way to do this is to use clocks:

There isn’t an automatic conversion of an ODESystem into a discrete time clocked system at this time, but if it’s just for simulating then Euler with the right step size is the same thing.