# Questions about the values of @variables in Catalyst/ModelingToolkit

**URL:** <https://discourse.julialang.org/t/questions-about-the-values-of-variables-in-catalyst-modelingtoolkit/83976>\
**Category:** General Usage\
**Created:** [July 9, 2022, 12:59am UTC](https://discourse.julialang.org/t/questions-about-the-values-of-variables-in-catalyst-modelingtoolkit/83976 "2022-07-09T00:59:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wenzhe\_Ma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wenzhe_ma/32/13020_2.png) [@Wenzhe\_Ma](https://discourse.julialang.org/u/Wenzhe_Ma)\
**Post date:** [July 9, 2022, 12:59am UTC](https://discourse.julialang.org/t/questions-about-the-values-of-variables-in-catalyst-modelingtoolkit/83976/1 "2022-07-09T00:59:45Z")

</div>

Hello,

I have a few seemingly simple questions but just can’t figure out the answer myself. I am using Catalyst to define my model. My first question is how do I find the default values I defined for the variables? for example if I have:  
@variables a=1 b=10  
How do I find out the value of a and b in julia?  
The second question is if I have an expression  
f = 10\*a+b  
can I evaluate the expression f?  
I just can’t figure out how to do them.

Thanks in advance for you help!

Wenzhe

---

<div class="post-metadata">

**Author:** ![YingboMa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yingboma/32/2181_2.png) [@YingboMa](https://discourse.julialang.org/u/YingboMa)\
**Post date:** [July 9, 2022, 1:47am UTC](https://discourse.julialang.org/t/questions-about-the-values-of-variables-in-catalyst-modelingtoolkit/83976/2 "2022-07-09T01:47:07Z")

</div>

`@variables a=1 b=10` instantiates symbolic variables with default values or initial guesses to be `1` and `10`. It doesn’t mean that `a` is assigned to be `1` and `b` is assigned to be `10`

---

<div class="post-metadata">

**Author:** ![Wenzhe\_Ma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wenzhe_ma/32/13020_2.png) [@Wenzhe\_Ma](https://discourse.julialang.org/u/Wenzhe_Ma)\
**Post date:** [July 9, 2022, 1:58am UTC](https://discourse.julialang.org/t/questions-about-the-values-of-variables-in-catalyst-modelingtoolkit/83976/3 "2022-07-09T01:58:28Z")

</div>

Thanks. Is there a way to check the default values? And is there a way to assign these value in an expression containing a and b?

---

<div class="post-metadata">

**Author:** ![isaacsas](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@isaacsas](https://discourse.julialang.org/u/isaacsas)\
**Post date:** [July 9, 2022, 12:58pm UTC](https://discourse.julialang.org/t/questions-about-the-values-of-variables-in-catalyst-modelingtoolkit/83976/4 "2022-07-09T12:58:41Z")

</div>

Given a `ReactionSystem` you can call `ModelingToolkit.defaults(sys)` to get the current defaults. You can use [`Catalyst.setdefaults!`](https://catalyst.sciml.ai/dev/api/catalyst_api/#Catalyst.setdefaults!), to add defaults to a system.

---

<div class="post-metadata">

**Author:** ![Wenzhe\_Ma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wenzhe_ma/32/13020_2.png) [@Wenzhe\_Ma](https://discourse.julialang.org/u/Wenzhe_Ma)\
**Post date:** [July 9, 2022, 1:21pm UTC](https://discourse.julialang.org/t/questions-about-the-values-of-variables-in-catalyst-modelingtoolkit/83976/5 "2022-07-09T13:21:05Z")

</div>

That will work. But my question is just to evaluate an expression with these predefined @variables. I don’t understand how the variable definition is done on a lower level, and I didn’t find a function to evaluate a user-defined expression. The question has bothered me for a long time.

@isaacsas@YingboMa

---

<div class="post-metadata">

**Author:** ![isaacsas](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@isaacsas](https://discourse.julialang.org/u/isaacsas)\
**Post date:** [July 9, 2022, 2:23pm UTC](https://discourse.julialang.org/t/questions-about-the-values-of-variables-in-catalyst-modelingtoolkit/83976/6 "2022-07-09T14:23:44Z")

</div>

Those values are, as far as I am aware, solely used when creating an `ODEProblem` or such to specify the initial condition vector, `u0`, and the parameter value vector, `p`, – they aren’t used in the symbolic expressions at all.

If you want to substitute concrete values into a symbolic expression you can use [`Symbolics.substitute`](https://symbolics.juliasymbolics.org/stable/manual/expression_manipulation/#SymbolicUtils.substitute) like

```julia
using ModelingToolkit, Symbolics
@parameters k
@variables t A(t)
ex = A^2 * k
val = substitute(ex, Dict(A => 2.0, k => 3.0))

```

---

<div class="post-metadata">

**Author:** ![Wenzhe\_Ma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wenzhe_ma/32/13020_2.png) [@Wenzhe\_Ma](https://discourse.julialang.org/u/Wenzhe_Ma)\
**Post date:** [July 10, 2022, 2:47am UTC](https://discourse.julialang.org/t/questions-about-the-values-of-variables-in-catalyst-modelingtoolkit/83976/7 "2022-07-10T02:47:45Z")

</div>

Thanks @isaacsas, this is helpful!

---

<div class="post-metadata">

**Author:** ![isaacsas](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@isaacsas](https://discourse.julialang.org/u/isaacsas)\
**Post date:** [July 10, 2022, 12:11pm UTC](https://discourse.julialang.org/t/questions-about-the-values-of-variables-in-catalyst-modelingtoolkit/83976/8 "2022-07-10T12:11:36Z")

</div>

Glad it helped!
