# Functions of variables in @mtkmodel

**URL:** https://discourse.julialang.org/t/functions-of-variables-in-mtkmodel/117159
**Category:** Modelling & Simulations
**Created:** [July 17, 2024, 8:04pm UTC](https://discourse.julialang.org/t/functions-of-variables-in-mtkmodel/117159 "2024-07-17T20:04:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sdwfrost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdwfrost/32/2831_2.png) [@sdwfrost](https://discourse.julialang.org/u/sdwfrost)
#### Post date: [July 17, 2024, 8:04pm UTC](https://discourse.julialang.org/t/functions-of-variables-in-mtkmodel/117159/1 "2024-07-17T20:04:15Z")

</div>

I’m playing with the new (at least to me) `@mtkmodel` syntax. Here’s my standard SIR model.

```Julia
using Symbolics
using ModelingToolkit: t_nounits as t, D_nounits as D
using OrdinaryDiffEq
using Plots

@mtkmodel SIR begin
    @parameters begin
        β
        γ
    end
    @variables begin
        S(t)
        I(t)
        R(t)
    end
    @equations begin
        D(S) ~ -β * S * I
        D(I) ~ β * S * I - γ * I
        D(R) ~ γ * I
    end
end

@mtkbuild sir=SIR()
prob = ODEProblem(sir,
                 [sir.S => 990.0, sir.I => 10.0, sir.R => 0.0],
                 (0.0, 40.0),
                 [sir.β => 0.0005, sir.γ => 0.25])
sol = solve(prob, Tsit5())
plot(sol)

```

I want to define the model like this:

```Julia
@equations begin
        D(S) ~ -β * S * I/N
        D(I) ~ β * S * I/N - γ * I
        D(R) ~ γ * I
    end

```

where `N=S+I+R`. In the non-DSL version, I just write this:

```Julia
@variables S(t), I(t), R(t)
N = S + I + R

```

How do I introduce N into `@mtkmodel`?

---

<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: [July 17, 2024, 8:31pm UTC](https://discourse.julialang.org/t/functions-of-variables-in-mtkmodel/117159/2 "2024-07-17T20:31:17Z")

</div>

Make that an observed equation in the equations set
