# Initial equations possible in MTK?

**URL:** <https://discourse.julialang.org/t/initial-equations-possible-in-mtk/128767>\
**Category:** Modelling & Simulations\
**Created:** [May 6, 2025, 7:59pm UTC](https://discourse.julialang.org/t/initial-equations-possible-in-mtk/128767 "2025-05-06T19:59:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthew1/32/215134_2.png) [@Matthew1](https://discourse.julialang.org/u/Matthew1)\
**Post date:** [May 6, 2025, 7:59pm UTC](https://discourse.julialang.org/t/initial-equations-possible-in-mtk/128767/1 "2025-05-06T19:59:35Z")

</div>

As mentioned here [[MTK -- how to set initial unknowns introduced by MTK?](https://discourse.julialang.org/t/mtk-how-to-set-initial-unknowns-introduced-by-mtk/117832)] and here [[GitHub · Where software is built](https://github.com/SciML/ModelingToolkit.jl/issues/3445)], there are many cases where it is helpful to specify initial equations, i.e. specifying initial values is insufficient (or at least inconvenient).

I see here [[Initialization of ODESystems · ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/stable/tutorials/initialization/)] that it is possible to pass initial equations to the ODEProblem. However, is it possible to specify initial equations as a macro?

As an example, this works:

```julia
    begin
        fluid_model = outlet.fluid_model
        ρ_init = calc_prop(h_init, p_init, "HmassP_INPUTS", "D", fluid_model)
        u_init = h_init - p_init/ρ_init
    end

    @variables begin
        h(t) = h_init
        p(t) = p_init
        ρ(t) = ρ_init
        m(t)
        u(t) = u_init
        Dm(t)
    end

```

But this would be more idiomatic, especially for those coming from Modelica: Is something like this possible?

```julia
    @variables begin
        h(t) = h_init
        p(t) = p_init
        ρ(t)
        m(t)
        u(t)
        Dm(t)
    end

    @initialization_eqs begin
        ρ ~ calc_prop(h_init, p_init, "HmassP_INPUTS", "D", fluid_model)
        u ~ h_init - p_init/ρ
    end

```

This is probably a trivial example, as the initial equations are linear. However any advice would be appreciated.

---

<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:** [May 7, 2025, 10:56am UTC](https://discourse.julialang.org/t/initial-equations-possible-in-mtk/128767/2 "2025-05-07T10:56:35Z")

</div>

> [@Matthew1](#):
>
> e [[Initialization of ODESystems · ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/stable/tutorials/initialization/)] that it is possible to pass initial equations to the ODEProblem. However, is it possible to specify initial equations as a ma

Not in the macro yet. I believe someone opened an issue about it last week.
