# DiffEqs: Hybrid (continuous+discrete) system / periodic callback

**URL:** <https://discourse.julialang.org/t/diffeqs-hybrid-continuous-discrete-system-periodic-callback/23791>\
**Category:** Modelling & Simulations\
**Tags:** diffeq\
**Created:** [May 2, 2019, 7:35pm UTC](https://discourse.julialang.org/t/diffeqs-hybrid-continuous-discrete-system-periodic-callback/23791 "2019-05-02T19:35:31Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![asprionj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asprionj/32/6856_2.png) [@asprionj](https://discourse.julialang.org/u/asprionj)\
**Post date:** [May 2, 2019, 7:35pm UTC](https://discourse.julialang.org/t/diffeqs-hybrid-continuous-discrete-system-periodic-callback/23791/1 "2019-05-02T19:35:31Z")

</div>

I want to model the combination of a physical (and thus continuous-time) system with a (discrete-time) controller. The controller algorithm is executed, say, every second. The output of the controller (that thus changes every second) is the input to the physical system.

I tried the straightforward way: Model the physical system as an ODE, then run a loop that evaluates the controller, changes parameters of that model (that represent the controller output), then run the simulation for one second. The problem is that the initialisation phase of the `solve` command takes about 5ms, whereas the simulation of the physical system over 30 minutes simulated time takes around 60ms in total. So if I call `solve` 1800 times (every simulated second), this already takes 9s.

What would be a good way to implement this? Basically, it would have to be something like `tstops` every second, but then pause the solver and let the discrete function (the controller algorithm) execute and change parameters and/or some state variables with zero autonomous dynamics. Is a `DiscreteCallback` the way to go?

---

_[View the full topic](https://discourse.julialang.org/t/diffeqs-hybrid-continuous-discrete-system-periodic-callback/23791)._
