# Catalyst.jl: Algebraically relate two species

**URL:** <https://discourse.julialang.org/t/catalyst-jl-algebraically-relate-two-species/95762>\
**Category:** Modelling & Simulations\
**Tags:** question, package, catalyst\
**Created:** [March 8, 2023, 8:07pm UTC](https://discourse.julialang.org/t/catalyst-jl-algebraically-relate-two-species/95762 "2023-03-08T20:07:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Theodore\_Rieger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theodore_rieger/32/19390_2.png) [@Theodore\_Rieger](https://discourse.julialang.org/u/Theodore_Rieger)\
**Post date:** [March 8, 2023, 8:07pm UTC](https://discourse.julialang.org/t/catalyst-jl-algebraically-relate-two-species/95762/1 "2023-03-08T20:07:08Z")

</div>

Using Catalyst.jl (DSL) to develop a model with pharmacology. The drug concentration is tracked in milligrams, but the pharmacology requires an algebraic transformation to ng/mL-unbound (multiplication by a few parameters). Is there a simple way to just relate two quantities algebraically within the DSL? It looks messy to call a function everywhere.

---

<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:** [March 8, 2023, 8:15pm UTC](https://discourse.julialang.org/t/catalyst-jl-algebraically-relate-two-species/95762/2 "2023-03-08T20:15:26Z")

</div>

You can define an observable, or the easier thing to do is just use the observed indexing. `sol[x^2 + y^2]` just works on the solution, so you can do something like `sol[p*x]` to get the solution of `p*x` at all of the `saveat` points.

---

<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:** [March 9, 2023, 1:45am UTC](https://discourse.julialang.org/t/catalyst-jl-algebraically-relate-two-species/95762/3 "2023-03-09T01:45:40Z")

</div>

@ChrisRackauckas’s suggestions are probably the best way to handle this, especially just making an observed equation, but another option if you are planning to convert to ODEs or nonlinear equations is to add an algebraic constraint equation (which `structural_simplify` in ModelingToolkit should essentially handle moving to be an observed equation for you after conversion). See [Constraint Equations and Events · Catalyst.jl](https://docs.sciml.ai/Catalyst/stable/catalyst_functionality/constraint_equations/) and note this requires Catalyst V13.
