# How to compose discrete-time static and dynamic models for systems simulation similar to Simulink?

**URL:** <https://discourse.julialang.org/t/how-to-compose-discrete-time-static-and-dynamic-models-for-systems-simulation-similar-to-simulink/74858>\
**Category:** Modelling & Simulations\
**Tags:** modelingtoolkit, sensors, state-space, digital-filters, modia\
**Created:** [January 19, 2022, 9:58am UTC](https://discourse.julialang.org/t/how-to-compose-discrete-time-static-and-dynamic-models-for-systems-simulation-similar-to-simulink/74858 "2022-01-19T09:58:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![JanKap](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jankap/32/22763_2.png) [@JanKap](https://discourse.julialang.org/u/JanKap)\
**Post date:** [January 19, 2022, 9:58am UTC](https://discourse.julialang.org/t/how-to-compose-discrete-time-static-and-dynamic-models-for-systems-simulation-similar-to-simulink/74858/1 "2022-01-19T09:58:37Z")

</div>

Hi all,

I’m searching for a Simulink replacement. The main purpose is to have a simplified system simulation for quick prototyping. The domain is mechanical/electrical

Usually, I have 4 kinds of models/subsystems

1. Sensor models that measure some ideal physical values and perturb them according to the model to generate realistic measurements
2. Environmental models to create ideal input data for 1., such as trajectory generators, temperature settings, orientation, simulation time etc.
3. Compensation models that try to invert 1., i.e. are algorithms that try to figure out the ideal input data from noisy measurement data
4. Logging & plotting modules

Details:

1. Are discrete models based on difference equations, LSTM models, simple lookup tables, digital filters (state space or transfer function formulation), usually a non-deterministic portion is included to simulate noise and drift (integrated noise)
2. Basically handles external parameter sets, loads data or generates data based on mechanically inspired equations. It’s discretized currently, but in theory it’s in continuous time
3. Is the rapid prototyping part. I want to exchange these algorithms quickly, ideally tune and optimize its parameters according to some output error metric. Examples are State Space Observer, (Extended) Kalman Filters, discrete filters, switching elements based on the value of input data, complementary filters, LSTM, … That part might get implemented in a µC when the optimal approach has been found
4. Not much to say, save results, errors, plots, push it to a database, things like that

Is there anything in the awesome Julia ecosystem that could handle that? So far there’s no need to mix continuous and discrete modeling, I _guess_, discrete systems are sufficient for now. Of course 2. mimics the environment and therefore is continuous, but since this might make things much more complicated, I would be happy with staying in the discrete time domain.

Any input is very welcome 🙂  
Thank you very much!  
Jan

edit: I forgot that of course I’ve had a look at ModelingToolkit.jl and Modia.jl. MTK seems not to have discrete states implemented yet, see [Discrete-Time (Sub-)Systems · Issue #894 · SciML/ModelingToolkit.jl (github.com)](https://github.com/SciML/ModelingToolkit.jl/issues/894) and [Allowing discrete Difference equations in ODESystem · Issue #1122 · SciML/ModelingToolkit.jl (github.com)](https://github.com/SciML/ModelingToolkit.jl/issues/1122).  
Modia seems also not to support discrete time modeling?

DifferentialEquations.jl seem to support discrete ODEs. Is this the way to go? [Discrete Solvers · DifferentialEquations.jl (sciml.ai)](https://diffeq.sciml.ai/stable/solvers/discrete_solve/)

Probably I’m getting something very wrong and discrete time modeling is a subset of all the great tools already implemented 🙂

Thanks!

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [January 20, 2022, 6:34am UTC](https://discourse.julialang.org/t/how-to-compose-discrete-time-static-and-dynamic-models-for-systems-simulation-similar-to-simulink/74858/2 "2022-01-20T06:34:01Z")

</div>

The intention is for MTK to handle hybrid discrete/continuous systems. There’s currently a large number of [issues open labeled “discrete-time”](https://github.com/SciML/ModelingToolkit.jl/issues?q=is%3Aopen+is%3Aissue+label%3Adiscrete-time), so for now, MTK is not the solution. Calling DifferentialEquations directly and using `PeriodicCallback` etc. is a viable alternative, but you won’t get the nice modeling language.

---

<div class="post-metadata">

**Author:** ![JanKap](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jankap/32/22763_2.png) [@JanKap](https://discourse.julialang.org/u/JanKap)\
**Post date:** [January 20, 2022, 1:37pm UTC](https://discourse.julialang.org/t/how-to-compose-discrete-time-static-and-dynamic-models-for-systems-simulation-similar-to-simulink/74858/3 "2022-01-20T13:37:31Z")

</div>

Hi @baggepinnen, thank you very much, I saw that `discrete-time` label after writing my post. I see, you and @ohmsweetohm1 are pretty active there, thanks for your work! I can try to assist, but it looks like the challenges are located deep inside the architecture of MTK.

Is anybody working actively on the issues, since nobody is assigned? However, I’m afraid this won’t be a short-term solution anyway, so I’d either need to stick to Simulink for now or to look at alternatives 😕

Will have a look at DifferentialEquations.jl and some Python stuff, like [Mathematical Formulation — SimuPy 1.0.0 documentation](https://simupy.readthedocs.io/en/latest/math.html) to come up with comparable systems.

edit: what’s about [https://zekeriyasari.github.io/Causal.jl/](https://zekeriyasari.github.io/Causal.jl/)?

---

<div class="post-metadata">

**Author:** ![JanKap](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jankap/32/22763_2.png) [@JanKap](https://discourse.julialang.org/u/JanKap)\
**Post date:** [March 22, 2023, 5:15pm UTC](https://discourse.julialang.org/t/how-to-compose-discrete-time-static-and-dynamic-models-for-systems-simulation-similar-to-simulink/74858/4 "2023-03-22T17:15:58Z")

</div>

Is the status mentioned above still the same? MTK + discrete time/events is not a smooth experience?  
Unfortunately, looks like Causal.jl is not very actively maintained.

Would a solution be to put specific MTK models into a FMU and integrate that into Simulink? Does anybody have experience with that?

Thanks

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [March 22, 2023, 5:20pm UTC](https://discourse.julialang.org/t/how-to-compose-discrete-time-static-and-dynamic-models-for-systems-simulation-similar-to-simulink/74858/5 "2023-03-22T17:20:49Z")

</div>

> [@JanKap](#):
>
> Is the status mentioned above still the same? MTK + discrete time/events is not a smooth experience?

Unfortunately, yes. There are some highly experimental features available underneath the hood, but they are not exported, nor documented and I do not recommend relying on them since they might break several times before they are ready.

See tests [here](https://github.com/SciML/ModelingToolkit.jl/blob/master/test/clock.jl#LL153-L171C28) and [here](https://github.com/SciML/ModelingToolkit.jl/blob/master/test/clock.jl#LL190-L229C59) for examples of how the interface _might_ look when it’s ready.

---

<div class="post-metadata">

**Author:** ![a\_tudor\_b](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@a\_tudor\_b](https://discourse.julialang.org/u/a_tudor_b)\
**Post date:** [July 2, 2024, 10:07am UTC](https://discourse.julialang.org/t/how-to-compose-discrete-time-static-and-dynamic-models-for-systems-simulation-similar-to-simulink/74858/6 "2024-07-02T10:07:33Z")

</div>

Hi,  
I’m new here, and I would like to know it there has been any update since last year on the simulation of hybrid continuous/discrete-time systems with MTK.  
If it is still under development, could somebody tell me when a first official release should be available?  
Thank you!

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [July 2, 2024, 10:15am UTC](https://discourse.julialang.org/t/how-to-compose-discrete-time-static-and-dynamic-models-for-systems-simulation-similar-to-simulink/74858/7 "2024-07-02T10:15:52Z")

</div>

> [@a\_tudor\_b](#):
>
> If it is still under development

Yes

> [@a\_tudor\_b](#):
>
> could somebody tell me when a first official release should be available?

Details will be shared during Juliacon

> **[Modeling and simulation of sampled-data systems Juliacon 2024](https://pretalx.com/juliacon2024/talk/KGAKA8/)**
>
> Computer algorithms interacting with the physical world around them give rise to what is referred to as a sampled-data system, a system with both parts that evolve continuously in time and processes that have a discrete time evolution. In this talk,...

---

<div class="post-metadata">

**Author:** ![a\_tudor\_b](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@a\_tudor\_b](https://discourse.julialang.org/u/a_tudor_b)\
**Post date:** [July 2, 2024, 5:41pm UTC](https://discourse.julialang.org/t/how-to-compose-discrete-time-static-and-dynamic-models-for-systems-simulation-similar-to-simulink/74858/8 "2024-07-02T17:41:24Z")

</div>

Thank you @baggepinnen

---

<div class="post-metadata">

**Author:** ![tuckermcclure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tuckermcclure/32/1187_2.png) [@tuckermcclure](https://discourse.julialang.org/u/tuckermcclure)\
**Post date:** [September 11, 2026, 5:15pm UTC](https://discourse.julialang.org/t/how-to-compose-discrete-time-static-and-dynamic-models-for-systems-simulation-similar-to-simulink/74858/9 "2026-09-11T17:15:19Z")

</div>

Hi @jankap. As an alternative to the other (excellent) packages mentioned so far, I just announced a [new package called SystemsOfSystems](https://discourse.julialang.org/t/ann-systemsofsystems-jl-a-simulation-engine/139359). It seems to do precisely what you’re describing. I remember seeing this post years ago and thought I would follow up. Fair warning: it can absolutely be a Simulink replacement, but it also works in a fundamentally different way, so there’s a bit of a mindset shift coming from something like Simulink.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [September 11, 2026, 6:19pm UTC](https://discourse.julialang.org/t/how-to-compose-discrete-time-static-and-dynamic-models-for-systems-simulation-similar-to-simulink/74858/10 "2026-09-11T18:19:36Z")

</div>

See also [https://youtu.be/ZM4oWlti\_YY?is=LAXsKVB9KYcf-vRn](https://youtu.be/ZM4oWlti_YY?is=LAXsKVB9KYcf-vRn) which is now in a much better state than when I wrote my last post in this thread 😊
