# MTK: "Track" or print a non-state variable defined as an equation

**URL:** <https://discourse.julialang.org/t/mtk-track-or-print-a-non-state-variable-defined-as-an-equation/107170>\
**Category:** Modelling & Simulations\
**Tags:** question, modelingtoolkit\
**Created:** [December 5, 2023, 2:03pm UTC](https://discourse.julialang.org/t/mtk-track-or-print-a-non-state-variable-defined-as-an-equation/107170 "2023-12-05T14:03:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [December 5, 2023, 2:03pm UTC](https://discourse.julialang.org/t/mtk-track-or-print-a-non-state-variable-defined-as-an-equation/107170/1 "2023-12-05T14:03:24Z")

</div>

I have a rather large model which has two variables:

```julia
@variables q, x

```

that have some equations, let’s say

```julia
eqs = [
Differential(t)(x) ~ log(q),
q ~ something
]

```

After my equations are created `x` remains a state variable but `q` remains an observable.

When I run the real system as an ODE solve, it turns out that `q` becomes negative somehow, even though it shouldn’t, and my `solve` errors with domain error and the helpful message of NaN arithmetic. I know I am doing something wrong, coz there is an alternative form of equations that solves. In my real example I have lots of equations, and it doesn’t make sense for me to produce a “MWE”, as removing equations would obviously remove the problem.

My question: Using standard Julia functions, I know how I can track the value of `q` as the time evolution progresses. I could add a standard `print` statement in the function that would estimate `q`.

How do I do something similar? How do I make MTK print the value of `q` as it solves the problem, so that there are values of `q` I can see before the error is thrown?

---

<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:** [December 7, 2023, 5:01am UTC](https://discourse.julialang.org/t/mtk-track-or-print-a-non-state-variable-defined-as-an-equation/107170/2 "2023-12-07T05:01:58Z")

</div>

You can do something like:

```julia
Differential(t)(x) ~ log(show(q))

```

The derivative of show may need to be defined. But when it generates the code it should embed the show command in there.
