# How to ensure :sum of state varaibles remain a constant value , dde with constant lags

**URL:** <https://discourse.julialang.org/t/how-to-ensure-sum-of-state-varaibles-remain-a-constant-value-dde-with-constant-lags/108244>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 2, 2024, 5:52am UTC](https://discourse.julialang.org/t/how-to-ensure-sum-of-state-varaibles-remain-a-constant-value-dde-with-constant-lags/108244 "2024-01-02T05:52:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ananya\_Hazarika](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ananya_hazarika/32/50508_2.png) [@Ananya\_Hazarika](https://discourse.julialang.org/u/Ananya_Hazarika)\
**Post date:** [January 2, 2024, 5:52am UTC](https://discourse.julialang.org/t/how-to-ensure-sum-of-state-varaibles-remain-a-constant-value-dde-with-constant-lags/108244/1 "2024-01-02T05:52:49Z")

</div>

how can i make sure that none of the values become negative and at the same time their sum to be constant?

solving a dde with constant lags.

---

<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:** [January 2, 2024, 11:47am UTC](https://discourse.julialang.org/t/how-to-ensure-sum-of-state-varaibles-remain-a-constant-value-dde-with-constant-lags/108244/2 "2024-01-02T11:47:46Z")

</div>

Is this enforced by the definition of the system? If so then `isoutofdomain`. You can also use the DAE form by specifying a mass matrix.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 2, 2024, 6:25pm UTC](https://discourse.julialang.org/t/how-to-ensure-sum-of-state-varaibles-remain-a-constant-value-dde-with-constant-lags/108244/3 "2024-01-02T18:25:10Z")

</div>

> [@Ananya\_Hazarika](#):
>
> how can i make sure that none of the values become negative and at the same time their sum to be constant?

If the sum of several variables is a constant, you should alternatively be able to rewrite the equations to eliminate one of the variables.

---

<div class="post-metadata">

**Author:** ![Ananya\_Hazarika](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ananya_hazarika/32/50508_2.png) [@Ananya\_Hazarika](https://discourse.julialang.org/u/Ananya_Hazarika)\
**Post date:** [January 3, 2024, 12:52am UTC](https://discourse.julialang.org/t/how-to-ensure-sum-of-state-varaibles-remain-a-constant-value-dde-with-constant-lags/108244/4 "2024-01-03T00:52:04Z")

</div>

Did that …it doesn’t ensure the non-negativity part.The sum is constant alright,I’m going with what @ChrisRackauckas said.

Thanks,
