# Simulating a PID in a DAE - how to simulate a DDAE?

**URL:** https://discourse.julialang.org/t/simulating-a-pid-in-a-dae-how-to-simulate-a-ddae/111320
**Category:** Modelling & Simulations
**Created:** [March 7, 2024, 7:53pm UTC](https://discourse.julialang.org/t/simulating-a-pid-in-a-dae-how-to-simulate-a-ddae/111320 "2024-03-07T19:53:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![lpz18](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@lpz18](https://discourse.julialang.org/u/lpz18)
#### Post date: [March 7, 2024, 7:53pm UTC](https://discourse.julialang.org/t/simulating-a-pid-in-a-dae-how-to-simulate-a-ddae/111320/1 "2024-03-07T19:53:03Z")

</div>

I would like to run a PID controller with a nonlinear set of ODEs with 6 continous variables.

I thought I could do this with delay differential algebraic equaions, since in DelayDiffEq.jl it says

> Covers neutral and retarded delay differential equations, and differential-algebraic equations.

I haven’t been able to find any tutorials for how to write a DDAE system, could someone point me in the right direction?

Or even better, suggest another way to simulate a PID controller with a set of DAEs

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [March 7, 2024, 10:40pm UTC](https://discourse.julialang.org/t/simulating-a-pid-in-a-dae-how-to-simulate-a-ddae/111320/2 "2024-03-07T22:40:16Z")

</div>

What have you tried? If you just define a DDAE in mass matrix form it should work. There’s tests on this.

---

<div class="post-metadata">

### Author: ![lpz18](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@lpz18](https://discourse.julialang.org/u/lpz18)
#### Post date: [March 8, 2024, 10:28pm UTC](https://discourse.julialang.org/t/simulating-a-pid-in-a-dae-how-to-simulate-a-ddae/111320/3 "2024-03-08T22:28:02Z")

</div>

Thanks Chris!

So I see this [example](https://github.com/SciML/DelayDiffEq.jl/blob/master/test/interface/mass_matrix.jl), which is very useful and resolves how to simulate a DDAE.

I still don’t know how to simulate a [PID controller](https://en.wikipedia.org/wiki/PID_controller) which requires an integral term. The example above has a constant lag, and I’d be looking to compute an integral/sum over a fixed window of time into the past.

I can do this by sampling at a discrete number of constant lag points, but my solver is already relatively slow, and I was wondering if there is a more elegant way solving the problem

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [March 9, 2024, 1:37pm UTC](https://discourse.julialang.org/t/simulating-a-pid-in-a-dae-how-to-simulate-a-ddae/111320/4 "2024-03-09T13:37:18Z")

</div>

A PID controller is commonly simulated just by created in an integrated state, i.e. add the ODE `Ix' = x` and then `Ix = Integral(x)`.

---

<div class="post-metadata">

### Author: ![lpz18](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@lpz18](https://discourse.julialang.org/u/lpz18)
#### Post date: [March 11, 2024, 6:16pm UTC](https://discourse.julialang.org/t/simulating-a-pid-in-a-dae-how-to-simulate-a-ddae/111320/5 "2024-03-11T18:16:45Z")

</div>

I used the example of the SIR model I linked above and a vector of constant lags summed over like in [this example](https://discourse.julialang.org/t/integro-differential-equations-with-differentialequations-jl/19265)

I am not sure what you mean by `Ix = Integral(x)`. I searched in the DifferentialEquations docs and github page and can’t find anything like that. The closest thing I found was Integrals.jl, but it doesn’t seem to have any examples that use DEs.

If you meant something specitic, then I would appreciate clarification. Otherwise, I have a working solution now.

thanks for your help
